|
@@ -5,7 +5,7 @@ |
5 |
5 |
|
|
6 |
6 |
|
import org.litesoft.core.typeutils.*; |
7 |
7 |
|
|
8 |
|
- |
public class CalendarYMTest extends AbstractTemporalTestSupport<CalendarYM> |
|
8 |
+ |
public class CalendarYMTest extends TestCase |
9 |
9 |
|
{ |
10 |
10 |
|
public static TestSuite suite() |
11 |
11 |
|
{ |
|
@@ -28,16 +28,15 @@ |
28 |
28 |
|
chkCB( "1996a" ); |
29 |
29 |
|
chkCB( "1996/a" ); |
30 |
30 |
|
chkCB( "1996/1/a" ); |
|
31 |
+ |
// Bad Dates |
|
32 |
+ |
chkCB( "2000/0" ); |
|
33 |
+ |
chkCB( "2000/13" ); |
31 |
34 |
|
|
32 |
35 |
|
// Missing Parts |
33 |
36 |
|
chkCB( "1996" ); |
34 |
37 |
|
|
35 |
38 |
|
// Too Many Parts |
36 |
39 |
|
chkCB( "1996/2/1" ); |
37 |
|
- |
|
38 |
|
- |
// Bad Dates |
39 |
|
- |
chkCB( "2000/0" ); |
40 |
|
- |
chkCB( "2000/13" ); |
41 |
40 |
|
} |
42 |
41 |
|
|
43 |
42 |
|
private void chkCB( String pToYM ) |
|
@@ -110,13 +109,15 @@ |
110 |
109 |
|
|
111 |
110 |
|
private void chk( DateFormat pFormat, String pFieldOrder, CalendarYM pDate, String pDateFormatToString, int pYear, int pMonth ) |
112 |
111 |
|
{ |
|
112 |
+ |
String zExpectedStringFormY = Integers.zeroPadIt( 4, pYear ); |
|
113 |
+ |
String zExpectedStringFormM = Integers.zeroPadIt( 2, pMonth ); |
113 |
114 |
|
assertEquals( pFieldOrder, pFormat.getFieldOrder() ); |
114 |
115 |
|
assertEquals( "Year", pYear, pDate.getYear() ); |
115 |
116 |
|
assertEquals( "Month", pMonth, pDate.getMonth() ); |
116 |
117 |
|
assertEquals( pDateFormatToString, pFormat.format( pDate ) ); |
117 |
|
- |
assertEquals( "toYM", toYM(pYear, pMonth), pDate.toYM() ); |
|
118 |
+ |
assertEquals( "toYM", zExpectedStringFormY + "/" + zExpectedStringFormM, pDate.toYM() ); |
118 |
119 |
|
assertEquals( "fromYM", pDate, CalendarYM.fromYM( pDate.toYM() ) ); |
119 |
|
- |
assertEquals( "toSQLvalue", toSQLvalueYM( pYear, pMonth ), pDate.toSQLvalue() ); |
|
120 |
+ |
assertEquals( "toSQLvalue", zExpectedStringFormY + "-" + zExpectedStringFormM, pDate.toSQLvalue() ); |
120 |
121 |
|
assertEquals( "fromSQLvalue", pDate, CalendarYM.fromSQLvalue( pDate.toSQLvalue() ) ); |
121 |
122 |
|
} |
122 |
123 |
|
|
|
@@ -134,7 +135,25 @@ |
134 |
135 |
|
CalendarYM od = CalendarYM.fromYM( pDateYM ); |
135 |
136 |
|
CalendarYM nd = od.addYears( pAdjustBy ); |
136 |
137 |
|
assertEquals( pExpectedYM, nd.toYM() ); |
137 |
|
- |
compareCheck( add( pAdjustBy ), od, nd ); |
|
138 |
+ |
if ( pAdjustBy == 0 ) |
|
139 |
+ |
{ |
|
140 |
+ |
assertTrue( od == nd ); |
|
141 |
+ |
assertTrue( 0 == od.compareTo( nd ) ); |
|
142 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
143 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
|
144 |
+ |
} |
|
145 |
+ |
else if ( pAdjustBy > 0 ) |
|
146 |
+ |
{ |
|
147 |
+ |
assertTrue( 0 > od.compareTo( nd ) ); |
|
148 |
+ |
assertFalse( od.afterOrEqual( nd ) ); |
|
149 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
|
150 |
+ |
} |
|
151 |
+ |
else // pAdjustBy < 0 |
|
152 |
+ |
{ |
|
153 |
+ |
assertTrue( 0 < od.compareTo( nd ) ); |
|
154 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
155 |
+ |
assertFalse( od.beforeOrEqual( nd ) ); |
|
156 |
+ |
} |
138 |
157 |
|
} |
139 |
158 |
|
|
140 |
159 |
|
public void test_minusYears() |
|
@@ -151,7 +170,25 @@ |
151 |
170 |
|
CalendarYM od = CalendarYM.fromYM( pDateYM ); |
152 |
171 |
|
CalendarYM nd = od.minusYears( pAdjustBy ); |
153 |
172 |
|
assertEquals( pExpectedYM, nd.toYM() ); |
154 |
|
- |
compareCheck( minus( pAdjustBy ), od, nd ); |
|
173 |
+ |
if ( pAdjustBy == 0 ) |
|
174 |
+ |
{ |
|
175 |
+ |
assertTrue( od == nd ); |
|
176 |
+ |
assertTrue( 0 == od.compareTo( nd ) ); |
|
177 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
178 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
|
179 |
+ |
} |
|
180 |
+ |
else if ( pAdjustBy < 0 ) |
|
181 |
+ |
{ |
|
182 |
+ |
assertTrue( 0 > od.compareTo( nd ) ); |
|
183 |
+ |
assertFalse( od.afterOrEqual( nd ) ); |
|
184 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
|
185 |
+ |
} |
|
186 |
+ |
else // pAdjustBy > 0 |
|
187 |
+ |
{ |
|
188 |
+ |
assertTrue( 0 < od.compareTo( nd ) ); |
|
189 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
190 |
+ |
assertFalse( od.beforeOrEqual( nd ) ); |
|
191 |
+ |
} |
155 |
192 |
|
} |
156 |
193 |
|
|
157 |
194 |
|
public void test_addMonths() |
|
@@ -168,7 +205,25 @@ |
168 |
205 |
|
CalendarYM od = CalendarYM.fromYM( pDateYM ); |
169 |
206 |
|
CalendarYM nd = od.addMonths( pAdjustBy ); |
170 |
207 |
|
assertEquals( pExpectedYM, nd.toYM() ); |
171 |
|
- |
compareCheck( add( pAdjustBy ), od, nd ); |
|
208 |
+ |
if ( pAdjustBy == 0 ) |
|
209 |
+ |
{ |
|
210 |
+ |
assertTrue( od == nd ); |
|
211 |
+ |
assertTrue( 0 == od.compareTo( nd ) ); |
|
212 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
213 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
|
214 |
+ |
} |
|
215 |
+ |
else if ( pAdjustBy > 0 ) |
|
216 |
+ |
{ |
|
217 |
+ |
assertTrue( 0 > od.compareTo( nd ) ); |
|
218 |
+ |
assertFalse( od.afterOrEqual( nd ) ); |
|
219 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
|
220 |
+ |
} |
|
221 |
+ |
else // pAdjustBy < 0 |
|
222 |
+ |
{ |
|
223 |
+ |
assertTrue( 0 < od.compareTo( nd ) ); |
|
224 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
225 |
+ |
assertFalse( od.beforeOrEqual( nd ) ); |
|
226 |
+ |
} |
172 |
227 |
|
} |
173 |
228 |
|
|
174 |
229 |
|
public void test_minusMonths() |
|
@@ -185,11 +240,47 @@ |
185 |
240 |
|
CalendarYM od = CalendarYM.fromYM( pDateYM ); |
186 |
241 |
|
CalendarYM nd = od.minusMonths( pAdjustBy ); |
187 |
242 |
|
assertEquals( pExpectedYM, nd.toYM() ); |
188 |
|
- |
compareCheck( minus( pAdjustBy ), od, nd ); |
|
243 |
+ |
if ( pAdjustBy == 0 ) |
|
244 |
+ |
{ |
|
245 |
+ |
assertTrue( od == nd ); |
|
246 |
+ |
assertTrue( 0 == od.compareTo( nd ) ); |
|
247 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
248 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
|
249 |
+ |
} |
|
250 |
+ |
else if ( pAdjustBy < 0 ) |
|
251 |
+ |
{ |
|
252 |
+ |
assertTrue( 0 > od.compareTo( nd ) ); |
|
253 |
+ |
assertFalse( od.afterOrEqual( nd ) ); |
|
254 |
+ |
assertTrue( od.beforeOrEqual( nd ) ); |
|
255 |
+ |
} |
|
256 |
+ |
else // pAdjustBy > 0 |
|
257 |
+ |
{ |
|
258 |
+ |
assertTrue( 0 < od.compareTo( nd ) ); |
|
259 |
+ |
assertTrue( od.afterOrEqual( nd ) ); |
|
260 |
+ |
assertFalse( od.beforeOrEqual( nd ) ); |
|
261 |
+ |
} |
189 |
262 |
|
} |
190 |
263 |
|
|
191 |
264 |
|
public void test_after_before_null() |
192 |
265 |
|
{ |
193 |
|
- |
chkAfterBeforeNull( new CalendarYM( 2000, 1 ) ); |
|
266 |
+ |
CalendarYM sd = new CalendarYM( 2000, 1 ); |
|
267 |
+ |
try |
|
268 |
+ |
{ |
|
269 |
+ |
sd.afterOrEqual( null ); |
|
270 |
+ |
fail( "Did Not fail on '" + sd + "': after( null )" ); |
|
271 |
+ |
} |
|
272 |
+ |
catch ( IllegalArgumentException expected ) |
|
273 |
+ |
{ |
|
274 |
+ |
// expected |
|
275 |
+ |
} |
|
276 |
+ |
try |
|
277 |
+ |
{ |
|
278 |
+ |
sd.beforeOrEqual( null ); |
|
279 |
+ |
fail( "Did Not fail on '" + sd + "': before( null )" ); |
|
280 |
+ |
} |
|
281 |
+ |
catch ( IllegalArgumentException expected ) |
|
282 |
+ |
{ |
|
283 |
+ |
// expected |
|
284 |
+ |
} |
194 |
285 |
|
} |
195 |
286 |
|
} |