Subversion Repository Public Repository

litesoft

Diff Revisions 850 vs 851 for /trunk/Java/core/Server/tests/org/litesoft/core/simpletypes/temporal/SimpleDateTest.java

Diff revisions: vs.
  @@ -1,8 +1,6 @@
1 1 // This Source Code is in the Public Domain per: http://litesoft.org/License.txt
2 2 package org.litesoft.core.simpletypes.temporal;
3 3
4 - import java.util.*;
5 -
6 4 import junit.framework.*;
7 5
8 6 public class SimpleDateTest extends TestCase
  @@ -126,7 +124,6 @@
126 124 assertEquals( "Year", pYear, pDate.getYear() );
127 125 assertEquals( "Month", pMonth, pDate.getMonth() );
128 126 assertEquals( "Day", pDay, pDate.getDay() );
129 - Date date = pDate.getDate();
130 127 SimpleDate sd2 = pDate.copy();
131 128 assertEquals( pDate, sd2 );
132 129 assertEquals( pToString, sd2.toString() );
  @@ -134,183 +131,6 @@
134 131 assertEquals( "Year", pYear, sd2.getYear() );
135 132 assertEquals( "Month", pMonth, sd2.getMonth() );
136 133 assertEquals( "Day", pDay, sd2.getDay() );
137 - sd2.setDate( date );
138 - assertEquals( pDate, sd2 );
139 - assertEquals( pToString, sd2.toString() );
140 - assertEquals( pFieldOrder, sd2.getFieldOrder() );
141 - assertEquals( "Year", pYear, sd2.getYear() );
142 - assertEquals( "Month", pMonth, sd2.getMonth() );
143 - assertEquals( "Day", pDay, sd2.getDay() );
144 - sd2.setDate( pDate );
145 - assertEquals( pDate, sd2 );
146 - assertEquals( pToString, sd2.toString() );
147 - assertEquals( pFieldOrder, sd2.getFieldOrder() );
148 - assertEquals( "Year", pYear, sd2.getYear() );
149 - assertEquals( "Month", pMonth, sd2.getMonth() );
150 - assertEquals( "Day", pDay, sd2.getDay() );
151 - }
152 -
153 - public void test_setYearAndMonth()
154 - {
155 - chkSYM( "1957/01/04", 2000, 2, "2000/02/04" );
156 - chkSYM( "2000/04/30", 2004, 1, "2004/01/30" );
157 - chkSYM( "2000/02/29", 2004, 2, "2004/02/29" );
158 - chkSYM( "2000/01/31", 2000, 2 );
159 - chkSYM( "2000/02/29", 1900, 2 );
160 - }
161 -
162 - private void chkSYM( String pDateYMD, int pSetYear, int pSetMonth, String pExpectedYMD )
163 - {
164 - SimpleDate sd = SimpleDate.fromYMD( "yMd", pDateYMD );
165 - sd.setYearAndMonth( pSetYear, pSetMonth );
166 - assertEquals( pExpectedYMD, sd.toYMD() );
167 - }
168 -
169 - private void chkSYM( String pDateYMD, int pSetYear, int pSetMonth )
170 - {
171 - SimpleDate sd = SimpleDate.fromYMD( "yMd", pDateYMD );
172 - try
173 - {
174 - sd.setYearAndMonth( pSetYear, pSetMonth );
175 - fail( "Did Not fail on '" + pDateYMD + "': setYearAndMonth( " + pSetYear + ", " + pSetMonth + " )" );
176 - }
177 - catch ( IllegalArgumentException expected )
178 - {
179 - // expected
180 - }
181 - }
182 -
183 - public void test_setMonthAndDay()
184 - {
185 - chkSMD( "1957/01/04", 3, 2, "1957/03/02" );
186 - chkSMD( "2000/04/30", 5, 1, "2000/05/01" );
187 - chkSMD( "2000/02/29", 3, 31, "2000/03/31" );
188 - chkSMD( "2000/02/29", 4, 31 );
189 - chkSMD( "1900/01/31", 2, 29 );
190 - chkSMD( "2000/02/29", 2, 30 );
191 - }
192 -
193 - private void chkSMD( String pDateYMD, int pSetMonth, int pSetDay, String pExpectedYMD )
194 - {
195 - SimpleDate sd = SimpleDate.fromYMD( "yMd", pDateYMD );
196 - sd.setMonthAndDay( pSetMonth, pSetDay );
197 - assertEquals( pExpectedYMD, sd.toYMD() );
198 - }
199 -
200 - private void chkSMD( String pDateYMD, int pSetMonth, int pSetDay )
201 - {
202 - SimpleDate sd = SimpleDate.fromYMD( "yMd", pDateYMD );
203 - try
204 - {
205 - sd.setMonthAndDay( pSetMonth, pSetDay );
206 - fail( "Did Not fail on '" + pDateYMD + "': setMonthAndDay( " + pSetMonth + ", " + pSetDay + " )" );
207 - }
208 - catch ( IllegalArgumentException expected )
209 - {
210 - // expected
211 - }
212 - }
213 -
214 - public void test_setYear()
215 - {
216 - chk_setYear( "1957/01/04", 2007, "2007/01/04" );
217 - chk_setYear( "2000/04/30", 2004, "2004/04/30" );
218 - chk_setYear( "2000/02/29", 2004, "2004/02/29" );
219 - chk_setYear( "2000/02/29", 2007 );
220 - chk_setYear( "2000/02/29", 1900 );
221 - }
222 -
223 - private void chk_setYear( String pDateYMD, int pSetTo, String pExpectedYMD )
224 - {
225 - SimpleDate sd = SimpleDate.fromYMD( "yMd", pDateYMD );
226 - sd.setYear( pSetTo );
227 - assertEquals( pExpectedYMD, sd.toYMD() );
228 - }
229 -
230 - private void chk_setYear( String pDateYMD, int pSetTo )
231 - {
232 - SimpleDate sd = SimpleDate.fromYMD( "yMd", pDateYMD );
233 - try
234 - {
235 - sd.setYear( pSetTo );
236 - fail( "Did Not fail on '" + pDateYMD + "': setYear( " + pSetTo + " )" );
237 - }
238 - catch ( IllegalArgumentException expected )
239 - {
240 - // expected
241 - }
242 - }
243 -
244 - public void test_setMonth()
245 - {
246 - chk_setMonth( "1957/01/04", -1 );
247 - chk_setMonth( "1957/01/04", 0 );
248 - chk_setMonth( "1957/01/04", 13 );
249 - chk_setMonth( "1957/01/04", 100 );
250 - chk_setMonth( "1957/01/04", 12, "1957/12/04" );
251 - chk_setMonth( "2000/04/30", 1, "2000/01/30" );
252 - chk_setMonth( "2000/01/29", 2, "2000/02/29" );
253 - chk_setMonth( "2007/01/31", 4 );
254 - chk_setMonth( "2007/01/29", 2 );
255 - chk_setMonth( "1900/01/29", 2 );
256 - }
257 -
258 - private void chk_setMonth( String pDateYMD, int pSetTo, String pExpectedYMD )
259 - {
260 - SimpleDate sd = SimpleDate.fromYMD( "yMd", pDateYMD );
261 - sd.setMonth( pSetTo );
262 - assertEquals( pExpectedYMD, sd.toYMD() );
263 - }
264 -
265 - private void chk_setMonth( String pDateYMD, int pSetTo )
266 - {
267 - SimpleDate sd = SimpleDate.fromYMD( "yMd", pDateYMD );
268 - try
269 - {
270 - sd.setMonth( pSetTo );
271 - fail( "Did Not fail on '" + pDateYMD + "': setMonth( " + pSetTo + " )" );
272 - }
273 - catch ( IllegalArgumentException expected )
274 - {
275 - // expected
276 - }
277 - }
278 -
279 - public void test_setDay()
280 - {
281 - chk_setDay( "1957/01/04", -1 );
282 - chk_setDay( "1957/01/04", 0 );
283 - chk_setDay( "1957/04/04", 31 );
284 - chk_setDay( "1957/01/04", 32 );
285 - chk_setDay( "1957/01/04", 100 );
286 - chk_setDay( "1957/01/04", 31, "1957/01/31" );
287 - chk_setDay( "2000/01/15", 31, "2000/01/31" );
288 - chk_setDay( "2000/04/15", 1, "2000/04/01" );
289 - chk_setDay( "2000/02/28", 29, "2000/02/29" );
290 - chk_setDay( "2007/02/28", 29 );
291 - chk_setDay( "2004/02/29", 30 );
292 - chk_setDay( "1900/02/28", 29 );
293 - }
294 -
295 - private void chk_setDay( String pDateYMD, int pSetTo, String pExpectedYMD )
296 - {
297 - SimpleDate sd = SimpleDate.fromYMD( "yMd", pDateYMD );
298 - sd.setDay( pSetTo );
299 - assertEquals( pExpectedYMD, sd.toYMD() );
300 - }
301 -
302 - private void chk_setDay( String pDateYMD, int pSetTo )
303 - {
304 - SimpleDate sd = SimpleDate.fromYMD( "yMd", pDateYMD );
305 - try
306 - {
307 - sd.setDay( pSetTo );
308 - fail( "Did Not fail on '" + pDateYMD + "': setDay( " + pSetTo + " )" );
309 - }
310 - catch ( IllegalArgumentException expected )
311 - {
312 - // expected
313 - }
314 134 }
315 135
316 136 public void test_addYears()
  @@ -323,8 +143,7 @@
323 143
324 144 private void chk_addYears( String pDateYMD, int pAdjustBy, String pExpectedYMD )
325 145 {
326 - SimpleDate sd = SimpleDate.fromYMD( "yMd", pDateYMD );
327 - sd.addYears( pAdjustBy );
146 + SimpleDate sd = SimpleDate.fromYMD( "yMd", pDateYMD ).addYears( pAdjustBy );
328 147 assertEquals( pExpectedYMD, sd.toYMD() );
329 148 }
330 149
  @@ -338,8 +157,7 @@
338 157
339 158 private void chk_minusYears( String pDateYMD, int pAdjustBy, String pExpectedYMD )
340 159 {
341 - SimpleDate sd = SimpleDate.fromYMD( "yMd", pDateYMD );
342 - sd.minusYears( pAdjustBy );
160 + SimpleDate sd = SimpleDate.fromYMD( "yMd", pDateYMD ).minusYears( pAdjustBy );
343 161 assertEquals( pExpectedYMD, sd.toYMD() );
344 162 }
345 163
  @@ -348,7 +166,7 @@
348 166 SimpleDate sd = new SimpleDate( "y", 2000 );
349 167 try
350 168 {
351 - sd.addMonths( 1 );
169 + sd.addMonths( 1 ); // expected to fail
352 170 fail( "Did Not fail on '" + sd + "': addMonths( 1 )" );
353 171 }
354 172 catch ( IllegalArgumentException expected )
  @@ -364,7 +182,7 @@
364 182 private void chk_addMonths( String pDateYMD, int pAdjustBy, String pExpectedYMD )
365 183 {
366 184 SimpleDate sd = SimpleDate.fromYMD( "yMd", pDateYMD );
367 - sd.addMonths( pAdjustBy );
185 + sd = sd.addMonths( pAdjustBy );
368 186 assertEquals( pExpectedYMD, sd.toYMD() );
369 187 }
370 188
  @@ -373,7 +191,7 @@
373 191 SimpleDate sd = new SimpleDate( "y", 2000 );
374 192 try
375 193 {
376 - sd.minusMonths( 1 );
194 + sd.minusMonths( 1 ); // expected failure
377 195 fail( "Did Not fail on '" + sd + "': minusMonths( 1 )" );
378 196 }
379 197 catch ( IllegalArgumentException expected )
  @@ -388,8 +206,7 @@
388 206
389 207 private void chk_minusMonths( String pDateYMD, int pAdjustBy, String pExpectedYMD )
390 208 {
391 - SimpleDate sd = SimpleDate.fromYMD( "yMd", pDateYMD );
392 - sd.minusMonths( pAdjustBy );
209 + SimpleDate sd = SimpleDate.fromYMD( "yMd", pDateYMD ).minusMonths( pAdjustBy );
393 210 assertEquals( pExpectedYMD, sd.toYMD() );
394 211 }
395 212
  @@ -398,7 +215,7 @@
398 215 SimpleDate sd = new SimpleDate( "y", 2000 );
399 216 try
400 217 {
401 - sd.addDays( 1 );
218 + sd.addDays( 1 ); // expected failure
402 219 fail( "Did Not fail on '" + sd + "': addDays( 1 )" );
403 220 }
404 221 catch ( IllegalArgumentException expected )
  @@ -408,7 +225,7 @@
408 225 sd = new SimpleDate( "yM", 2000, 1 );
409 226 try
410 227 {
411 - sd.addDays( 1 );
228 + sd.addDays( 1 ); // expected failure
412 229 fail( "Did Not fail on '" + sd + "': addDays( 1 )" );
413 230 }
414 231 catch ( IllegalArgumentException expected )
  @@ -438,7 +255,7 @@
438 255 assertTrue( "equalsDate", osd.equals( osd.getDate() ) );
439 256 SimpleDate nsd = osd.copy();
440 257 assertEquals( osd, nsd );
441 - nsd.addDays( pAdjustBy );
258 + nsd = nsd.addDays( pAdjustBy );
442 259 assertEquals( pExpectedYMD, nsd.toYMD() );
443 260 assertEquals( pAdjustBy, osd.daysTill( nsd ) );
444 261 if ( pAdjustBy == 0 )
  @@ -466,7 +283,7 @@
466 283 SimpleDate sd = new SimpleDate( "y", 2000 );
467 284 try
468 285 {
469 - sd.minusDays( 1 );
286 + sd.minusDays( 1 ); // expected failure
470 287 fail( "Did Not fail on '" + sd + "': minusDays( 1 )" );
471 288 }
472 289 catch ( IllegalArgumentException expected )
  @@ -476,7 +293,7 @@
476 293 sd = new SimpleDate( "yM", 2000, 1 );
477 294 try
478 295 {
479 - sd.minusDays( 1 );
296 + sd.minusDays( 1 ); // expected failure
480 297 fail( "Did Not fail on '" + sd + "': minusDays( 1 )" );
481 298 }
482 299 catch ( IllegalArgumentException expected )
  @@ -498,7 +315,7 @@
498 315 assertTrue( "equalsDate", osd.equals( osd.getDate() ) );
499 316 SimpleDate nsd = osd.copy();
500 317 assertEquals( osd, nsd );
501 - nsd.minusDays( pAdjustBy );
318 + nsd = nsd.minusDays( pAdjustBy );
502 319 assertEquals( pExpectedYMD, nsd.toYMD() );
503 320 assertEquals( -pAdjustBy, osd.daysTill( nsd ) );
504 321 if ( pAdjustBy == 0 )