Debian Codegraph @

maven-scm-api/src/test/java/org/apache/maven/scm/ChangeSetTest.java

raw
1 package org.apache.maven.scm;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import junit.framework.TestCase;
23
24 import java.util.Calendar;
25 import java.util.Date;
26
27 import static org.junit.Assert.assertNotEquals;
28
29 /**
30 * Tests for the {@link ChangeSet}class
31 *
32 * @author dion
33 *
34 */
35 public class ChangeSetTest
36 extends TestCase
37 {
38 /**
39 * the {@link ChangeSet} used for testing
40 */
41 private ChangeSet instance;
42
43 /**
44 * Initialize per test data
45 */
46 public void setUp()
47 {
48 instance = createInstance();
49 }
50
51 private static ChangeSet createInstance()
52 {
53 ChangeSet instance = new ChangeSet();
54 instance.setAuthor( "dion" );
55 instance.setComment( "comment" );
56 instance.setDate( "2002/04/01 00:00:00" );
57 return instance;
58 }
59
60 /**
61 * Test of addFile methods: using ChangeFile
62 */
63 public void testAddFileWithFile()
64 {
65 ChangeFile file = new ChangeFile( "maven:dummy" );
66 instance.addFile( file );
67 assertTrue( "File name not found in list", instance.toString().indexOf( "maven:dummy" ) != -1 );
68
69 assertTrue( instance.containsFilename("maven:") );
70 assertTrue( instance.containsFilename(":dummy") );
71 assertTrue( instance.containsFilename(":") );
72 assertTrue( instance.containsFilename("maven:dummy") );
73 assertFalse( instance.containsFilename("dammy") );
74 }
75
76 /**
77 * Test of toString method
78 */
79 public void testToString()
80 {
81 //dion, Mon Apr 01 00:00:00 EST 2002, comment
82 String value = instance.toString();
83 assertTrue( "author not found in string", value.indexOf( "dion" ) != -1 );
84 assertTrue( "comment not found in string", value.indexOf( "comment" ) != -1 );
85 assertTrue( "date not found in string", value.indexOf( "Mon Apr 01" ) != -1 );
86 }
87
88 /**
89 * Test of getAuthor method
90 */
91 public void testGetAuthor()
92 {
93 assertEquals( "Author value not retrieved correctly", "dion", instance.getAuthor() );
94 }
95
96 /**
97 * Test of setAuthor method
98 */
99 public void testSetAuthor()
100 {
101 instance.setAuthor( "maven:dion" );
102 assertEquals( "Author not set correctly", "maven:dion", instance.getAuthor() );
103 }
104
105 /**
106 * Test of getComment method
107 */
108 public void testGetComment()
109 {
110 assertEquals( "Comment value not retrieved correctly", "comment", instance.getComment() );
111 }
112
113 /**
114 * Test of setComment method
115 */
116 public void testSetComment()
117 {
118 instance.setComment( "maven:comment" );
119 assertEquals( "Comment not set correctly", "maven:comment", instance.getComment() );
120 }
121
122 /**
123 * Test of getDate method
124 */
125 public void testGetDate()
126 {
127 assertEquals( "Date value not retrieved correctly", getDate( 2002, 3, 1 ), instance.getDate() );
128 }
129
130 /**
131 * Test of setDate method with Date object
132 */
133 public void testSetDate()
134 {
135 Calendar cal = Calendar.getInstance();
136 Date date = cal.getTime();
137 instance.setDate( date );
138 assertEquals( "Date value not set correctly", date, instance.getDate() );
139 }
140
141
142 /**
143 * Test of setDate method with String
144 */
145 public void testSetDateFromString()
146 {
147 instance.setDate( "2002/03/04 00:00:00" );
148 assertEquals( "Date value not set correctly from a string", getDate( 2002, 2, 4 ), instance.getDate() );
149 }
150
151 /**
152 * Test of getDateFormatted method
153 */
154 public void testGetDateFormatted()
155 {
156 assertEquals( "Date not formatted correctly", "2002-04-01", instance.getDateFormatted() );
157 }
158
159 /**
160 * Test of getDateFormatted method
161 */
162 public void testGetTimeFormatted()
163 {
164 assertEquals( "Time not formatted correctly", "00:00:00", instance.getTimeFormatted() );
165 }
166
167 public static Date getDate( int year, int month, int day )
168 {
169 Calendar cal = Calendar.getInstance();
170
171 cal.set( year, month, day, 0, 0, 0 );
172 cal.set( Calendar.MILLISECOND, 0 );
173
174 return cal.getTime();
175 }
176
177 public void testEscapeValue()
178 {
179 assertEquals( "", ChangeSet.escapeValue("") );
180 assertEquals( "'", ChangeSet.escapeValue("'") );
181 assertEquals( "a", ChangeSet.escapeValue("a") );
182 assertEquals( "a'", ChangeSet.escapeValue("a'") );
183 assertEquals( "'a'", ChangeSet.escapeValue("'a'") );
184
185 assertEquals( "a&lt;b&gt;c", ChangeSet.escapeValue("a<b>c") );
186 assertEquals( "&apos;&amp;;&lt;&gt;&quot;", ChangeSet.escapeValue("'&;<>\"") );
187 }
188
189 public void testEquals()
190 {
191 ChangeSet instance2 = createInstance();
192 assertEquals(instance, instance2);
193
194 instance2.setComment("another comment");
195 assertNotEquals( instance2, instance );
196
197 instance2.setComment("comment");
198 assertEquals(instance, instance2);
199 }
200
201 public void testHashCode()
202 {
203 int hashCode1 = instance.hashCode();
204 instance.setAuthor("anotherAuthor");
205
206 assertFalse( hashCode1 == instance.hashCode() );
207 instance.setAuthor( "dion" );
208 assertEquals( hashCode1, instance.hashCode() );
209 }
210
211 public void testToXml()
212 {
213 String sXml = instance.toXML();
214 assertNotNull(sXml);
215
216 assertTrue(sXml.indexOf("<changelog-entry>") > -1);
217 assertTrue(sXml.indexOf("</changelog-entry>") > -1);
218 }
219
220 public void testToXmlWithFiles()
221 {
222 instance.addFile( new ChangeFile( "maven1:dummy" ) );
223 instance.addFile( new ChangeFile( "maven2:dummy2" ) );
224
225 String sXml = instance.toXML();
226 assertNotNull(sXml);
227
228 assertTrue(sXml.indexOf("<changelog-entry>") > -1);
229 assertTrue(sXml.indexOf("</changelog-entry>") > -1);
230
231 assertTrue(sXml.indexOf("<file>") > -1);
232 assertTrue(sXml.indexOf("<name>maven1:dummy</name>") > -1);
233 assertTrue(sXml.indexOf("<name>maven2:dummy2</name>") > -1);
234
235
236 }
237
238 }