1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.joda.time;
17
18 import java.util.Date;
19 import java.util.Locale;
20
21 import junit.framework.TestCase;
22 import junit.framework.TestSuite;
23
24 import org.joda.time.chrono.GregorianChronology;
25 import org.joda.time.chrono.ISOChronology;
26 import org.joda.time.convert.ConverterManager;
27 import org.joda.time.convert.MockZeroNullIntegerConverter;
28 import org.joda.time.format.DateTimeFormat;
29 import org.joda.time.format.DateTimeFormatter;
30
31
32
33
34
35
36 public class TestDateTime_Constructors extends TestCase {
37
38
39
40 private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
41 private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
42
43 long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
44 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 +
45 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
46 366 + 365;
47 long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
48 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 +
49 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
50 366 + 365 + 365;
51
52
53 private long TEST_TIME_NOW =
54 (y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY;
55
56
57 private long TEST_TIME1 =
58 (y2002days + 31L + 28L + 31L + 5L -1L) * DateTimeConstants.MILLIS_PER_DAY
59 + 12L * DateTimeConstants.MILLIS_PER_HOUR
60 + 24L * DateTimeConstants.MILLIS_PER_MINUTE;
61
62
63 private long TEST_TIME2 =
64 (y2003days + 31L + 28L + 31L + 30L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY
65 + 14L * DateTimeConstants.MILLIS_PER_HOUR
66 + 28L * DateTimeConstants.MILLIS_PER_MINUTE;
67
68 private DateTimeZone zone = null;
69 private Locale locale = null;
70
71 public static void main(String[] args) {
72 junit.textui.TestRunner.run(suite());
73 }
74
75 public static TestSuite suite() {
76 return new TestSuite(TestDateTime_Constructors.class);
77 }
78
79 public TestDateTime_Constructors(String name) {
80 super(name);
81 }
82
83 protected void setUp() throws Exception {
84 DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
85 zone = DateTimeZone.getDefault();
86 locale = Locale.getDefault();
87 DateTimeZone.setDefault(LONDON);
88 java.util.TimeZone.setDefault(LONDON.toTimeZone());
89 Locale.setDefault(Locale.UK);
90 }
91
92 protected void tearDown() throws Exception {
93 DateTimeUtils.setCurrentMillisSystem();
94 DateTimeZone.setDefault(zone);
95 java.util.TimeZone.setDefault(zone.toTimeZone());
96 Locale.setDefault(locale);
97 zone = null;
98 }
99
100
101 public void testTest() {
102 assertEquals("2002-06-09T00:00:00.000Z", new Instant(TEST_TIME_NOW).toString());
103 assertEquals("2002-04-05T12:24:00.000Z", new Instant(TEST_TIME1).toString());
104 assertEquals("2003-05-06T14:28:00.000Z", new Instant(TEST_TIME2).toString());
105 }
106
107
108
109
110
111 public void test_now() throws Throwable {
112 DateTime test = DateTime.now();
113 assertEquals(ISOChronology.getInstance(), test.getChronology());
114 assertEquals(TEST_TIME_NOW, test.getMillis());
115 }
116
117
118
119
120 public void test_now_DateTimeZone() throws Throwable {
121 DateTime test = DateTime.now(PARIS);
122 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
123 assertEquals(TEST_TIME_NOW, test.getMillis());
124 }
125
126
127
128
129 public void test_now_nullDateTimeZone() throws Throwable {
130 try {
131 DateTime.now((DateTimeZone) null);
132 fail();
133 } catch (NullPointerException ex) {}
134 }
135
136
137
138
139 public void test_now_Chronology() throws Throwable {
140 DateTime test = DateTime.now(GregorianChronology.getInstance());
141 assertEquals(GregorianChronology.getInstance(), test.getChronology());
142 assertEquals(TEST_TIME_NOW, test.getMillis());
143 }
144
145
146
147
148 public void test_now_nullChronology() throws Throwable {
149 try {
150 DateTime.now((Chronology) null);
151 fail();
152 } catch (NullPointerException ex) {}
153 }
154
155
156 public void testParse_noFormatter() throws Throwable {
157 assertEquals(new DateTime(2010, 6, 30, 1, 20, ISOChronology.getInstance(DateTimeZone.forOffsetHours(2))), DateTime.parse("2010-06-30T01:20+02:00"));
158 assertEquals(new DateTime(2010, 1, 2, 14, 50, ISOChronology.getInstance(LONDON)), DateTime.parse("2010-002T14:50"));
159 }
160
161 public void testParse_formatter() throws Throwable {
162 DateTimeFormatter f = DateTimeFormat.forPattern("yyyy--dd MM HH").withChronology(ISOChronology.getInstance(PARIS));
163 assertEquals(new DateTime(2010, 6, 30, 13, 0, ISOChronology.getInstance(PARIS)), DateTime.parse("2010--30 06 13", f));
164 }
165
166
167
168
169
170 public void testConstructor() throws Throwable {
171 DateTime test = new DateTime();
172 assertEquals(ISOChronology.getInstance(), test.getChronology());
173 assertEquals(TEST_TIME_NOW, test.getMillis());
174 }
175
176
177
178
179 public void testConstructor_DateTimeZone() throws Throwable {
180 DateTime test = new DateTime(PARIS);
181 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
182 assertEquals(TEST_TIME_NOW, test.getMillis());
183 }
184
185
186
187
188 public void testConstructor_nullDateTimeZone() throws Throwable {
189 DateTime test = new DateTime((DateTimeZone) null);
190 assertEquals(ISOChronology.getInstance(), test.getChronology());
191 assertEquals(TEST_TIME_NOW, test.getMillis());
192 }
193
194
195
196
197 public void testConstructor_Chronology() throws Throwable {
198 DateTime test = new DateTime(GregorianChronology.getInstance());
199 assertEquals(GregorianChronology.getInstance(), test.getChronology());
200 assertEquals(TEST_TIME_NOW, test.getMillis());
201 }
202
203
204
205
206 public void testConstructor_nullChronology() throws Throwable {
207 DateTime test = new DateTime((Chronology) null);
208 assertEquals(ISOChronology.getInstance(), test.getChronology());
209 assertEquals(TEST_TIME_NOW, test.getMillis());
210 }
211
212
213
214
215
216 public void testConstructor_long1() throws Throwable {
217 DateTime test = new DateTime(TEST_TIME1);
218 assertEquals(ISOChronology.getInstance(), test.getChronology());
219 assertEquals(TEST_TIME1, test.getMillis());
220 }
221
222
223
224
225 public void testConstructor_long2() throws Throwable {
226 DateTime test = new DateTime(TEST_TIME2);
227 assertEquals(ISOChronology.getInstance(), test.getChronology());
228 assertEquals(TEST_TIME2, test.getMillis());
229 }
230
231
232
233
234 public void testConstructor_long1_DateTimeZone() throws Throwable {
235 DateTime test = new DateTime(TEST_TIME1, PARIS);
236 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
237 assertEquals(TEST_TIME1, test.getMillis());
238 }
239
240
241
242
243 public void testConstructor_long2_DateTimeZone() throws Throwable {
244 DateTime test = new DateTime(TEST_TIME2, PARIS);
245 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
246 assertEquals(TEST_TIME2, test.getMillis());
247 }
248
249
250
251
252 public void testConstructor_long_nullDateTimeZone() throws Throwable {
253 DateTime test = new DateTime(TEST_TIME1, (DateTimeZone) null);
254 assertEquals(ISOChronology.getInstance(), test.getChronology());
255 assertEquals(TEST_TIME1, test.getMillis());
256 }
257
258
259
260
261 public void testConstructor_long1_Chronology() throws Throwable {
262 DateTime test = new DateTime(TEST_TIME1, GregorianChronology.getInstance());
263 assertEquals(GregorianChronology.getInstance(), test.getChronology());
264 assertEquals(TEST_TIME1, test.getMillis());
265 }
266
267
268
269
270 public void testConstructor_long2_Chronology() throws Throwable {
271 DateTime test = new DateTime(TEST_TIME2, GregorianChronology.getInstance());
272 assertEquals(GregorianChronology.getInstance(), test.getChronology());
273 assertEquals(TEST_TIME2, test.getMillis());
274 }
275
276
277
278
279 public void testConstructor_long_nullChronology() throws Throwable {
280 DateTime test = new DateTime(TEST_TIME1, (Chronology) null);
281 assertEquals(ISOChronology.getInstance(), test.getChronology());
282 assertEquals(TEST_TIME1, test.getMillis());
283 }
284
285
286
287
288
289 public void testConstructor_Object() throws Throwable {
290 Date date = new Date(TEST_TIME1);
291 DateTime test = new DateTime(date);
292 assertEquals(ISOChronology.getInstance(), test.getChronology());
293 assertEquals(TEST_TIME1, test.getMillis());
294 }
295
296
297
298
299 public void testConstructor_invalidObject() throws Throwable {
300 try {
301 new DateTime(new Object());
302 fail();
303 } catch (IllegalArgumentException ex) {}
304 }
305
306
307
308
309 public void testConstructor_nullObject() throws Throwable {
310 DateTime test = new DateTime((Object) null);
311 assertEquals(ISOChronology.getInstance(), test.getChronology());
312 assertEquals(TEST_TIME_NOW, test.getMillis());
313 }
314
315
316
317
318 public void testConstructor_badconverterObject() throws Throwable {
319 try {
320 ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE);
321 DateTime test = new DateTime(new Integer(0));
322 assertEquals(ISOChronology.getInstance(), test.getChronology());
323 assertEquals(0L, test.getMillis());
324 } finally {
325 ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE);
326 }
327 }
328
329 public void testConstructor_ObjectString1() throws Throwable {
330 DateTime test = new DateTime("1972-12-03");
331 assertEquals(ISOChronology.getInstance(), test.getChronology());
332 assertEquals(1972, test.getYear());
333 assertEquals(12, test.getMonthOfYear());
334 assertEquals(3, test.getDayOfMonth());
335 assertEquals(0, test.getHourOfDay());
336 assertEquals(0, test.getMinuteOfHour());
337 assertEquals(0, test.getSecondOfMinute());
338 assertEquals(0, test.getMillisOfSecond());
339 }
340
341 public void testConstructor_ObjectString2() throws Throwable {
342 DateTime test = new DateTime("2006-06-03T+14:00");
343 assertEquals(ISOChronology.getInstance(), test.getChronology());
344 assertEquals(2006, test.getYear());
345 assertEquals(6, test.getMonthOfYear());
346 assertEquals(2, test.getDayOfMonth());
347 assertEquals(11, test.getHourOfDay());
348 assertEquals(0, test.getMinuteOfHour());
349 assertEquals(0, test.getSecondOfMinute());
350 assertEquals(0, test.getMillisOfSecond());
351 }
352
353 public void testConstructor_ObjectString3() throws Throwable {
354 DateTime test = new DateTime("1972-12-03T10:20:30.040");
355 assertEquals(ISOChronology.getInstance(), test.getChronology());
356 assertEquals(1972, test.getYear());
357 assertEquals(12, test.getMonthOfYear());
358 assertEquals(3, test.getDayOfMonth());
359 assertEquals(10, test.getHourOfDay());
360 assertEquals(20, test.getMinuteOfHour());
361 assertEquals(30, test.getSecondOfMinute());
362 assertEquals(40, test.getMillisOfSecond());
363 }
364
365 public void testConstructor_ObjectString4() throws Throwable {
366 DateTime test = new DateTime("2006-06-03T10:20:30.040+14:00");
367 assertEquals(ISOChronology.getInstance(), test.getChronology());
368 assertEquals(2006, test.getYear());
369 assertEquals(6, test.getMonthOfYear());
370 assertEquals(2, test.getDayOfMonth());
371 assertEquals(21, test.getHourOfDay());
372 assertEquals(20, test.getMinuteOfHour());
373 assertEquals(30, test.getSecondOfMinute());
374 assertEquals(40, test.getMillisOfSecond());
375 }
376
377 public void testConstructor_ObjectString5() throws Throwable {
378 DateTime test = new DateTime("T10:20:30.040");
379 assertEquals(ISOChronology.getInstance(), test.getChronology());
380 assertEquals(1970, test.getYear());
381 assertEquals(1, test.getMonthOfYear());
382 assertEquals(1, test.getDayOfMonth());
383 assertEquals(10, test.getHourOfDay());
384 assertEquals(20, test.getMinuteOfHour());
385 assertEquals(30, test.getSecondOfMinute());
386 assertEquals(40, test.getMillisOfSecond());
387 }
388
389 public void testConstructor_ObjectString6() throws Throwable {
390 DateTime test = new DateTime("T10:20:30.040+14:00");
391 assertEquals(ISOChronology.getInstance(), test.getChronology());
392 assertEquals(1969, test.getYear());
393 assertEquals(12, test.getMonthOfYear());
394 assertEquals(31, test.getDayOfMonth());
395 assertEquals(21, test.getHourOfDay());
396 assertEquals(20, test.getMinuteOfHour());
397 assertEquals(30, test.getSecondOfMinute());
398 assertEquals(40, test.getMillisOfSecond());
399 }
400
401 public void testConstructor_ObjectString7() throws Throwable {
402 DateTime test = new DateTime("10");
403 assertEquals(ISOChronology.getInstance(), test.getChronology());
404 assertEquals(10, test.getYear());
405 assertEquals(1, test.getMonthOfYear());
406 assertEquals(1, test.getDayOfMonth());
407 assertEquals(0, test.getHourOfDay());
408 assertEquals(0, test.getMinuteOfHour());
409 assertEquals(0, test.getSecondOfMinute());
410 assertEquals(0, test.getMillisOfSecond());
411 }
412
413 public void testConstructor_ObjectStringEx1() throws Throwable {
414 try {
415 new DateTime("10:20:30.040");
416 fail();
417 } catch (IllegalArgumentException ex) {
418
419 }
420 }
421
422 public void testConstructor_ObjectStringEx2() throws Throwable {
423 try {
424 new DateTime("10:20:30.040+14:00");
425 fail();
426 } catch (IllegalArgumentException ex) {
427
428 }
429 }
430
431
432
433
434
435 public void testConstructor_Object_DateTimeZone() throws Throwable {
436 Date date = new Date(TEST_TIME1);
437 DateTime test = new DateTime(date, PARIS);
438 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
439 assertEquals(TEST_TIME1, test.getMillis());
440 }
441
442
443
444
445 public void testConstructor_invalidObject_DateTimeZone() throws Throwable {
446 try {
447 new DateTime(new Object(), PARIS);
448 fail();
449 } catch (IllegalArgumentException ex) {}
450 }
451
452
453
454
455 public void testConstructor_nullObject_DateTimeZone() throws Throwable {
456 DateTime test = new DateTime((Object) null, PARIS);
457 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
458 assertEquals(TEST_TIME_NOW, test.getMillis());
459 }
460
461
462
463
464 public void testConstructor_Object_nullDateTimeZone() throws Throwable {
465 Date date = new Date(TEST_TIME1);
466 DateTime test = new DateTime(date, (DateTimeZone) null);
467 assertEquals(ISOChronology.getInstance(), test.getChronology());
468 assertEquals(TEST_TIME1, test.getMillis());
469 }
470
471
472
473
474 public void testConstructor_nullObject_nullDateTimeZone() throws Throwable {
475 DateTime test = new DateTime((Object) null, (DateTimeZone) null);
476 assertEquals(ISOChronology.getInstance(), test.getChronology());
477 assertEquals(TEST_TIME_NOW, test.getMillis());
478 }
479
480
481
482
483 public void testConstructor_badconverterObject_DateTimeZone() throws Throwable {
484 try {
485 ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE);
486 DateTime test = new DateTime(new Integer(0), GregorianChronology.getInstance());
487 assertEquals(ISOChronology.getInstance(), test.getChronology());
488 assertEquals(0L, test.getMillis());
489 } finally {
490 ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE);
491 }
492 }
493
494
495
496
497 public void testConstructor_Object_Chronology() throws Throwable {
498 Date date = new Date(TEST_TIME1);
499 DateTime test = new DateTime(date, GregorianChronology.getInstance());
500 assertEquals(GregorianChronology.getInstance(), test.getChronology());
501 assertEquals(TEST_TIME1, test.getMillis());
502 }
503
504
505
506
507 public void testConstructor_invalidObject_Chronology() throws Throwable {
508 try {
509 new DateTime(new Object(), GregorianChronology.getInstance());
510 fail();
511 } catch (IllegalArgumentException ex) {}
512 }
513
514
515
516
517 public void testConstructor_nullObject_Chronology() throws Throwable {
518 DateTime test = new DateTime((Object) null, GregorianChronology.getInstance());
519 assertEquals(GregorianChronology.getInstance(), test.getChronology());
520 assertEquals(TEST_TIME_NOW, test.getMillis());
521 }
522
523
524
525
526 public void testConstructor_Object_nullChronology() throws Throwable {
527 Date date = new Date(TEST_TIME1);
528 DateTime test = new DateTime(date, (Chronology) null);
529 assertEquals(ISOChronology.getInstance(), test.getChronology());
530 assertEquals(TEST_TIME1, test.getMillis());
531 }
532
533
534
535
536 public void testConstructor_nullObject_nullChronology() throws Throwable {
537 DateTime test = new DateTime((Object) null, (Chronology) null);
538 assertEquals(ISOChronology.getInstance(), test.getChronology());
539 assertEquals(TEST_TIME_NOW, test.getMillis());
540 }
541
542
543
544
545 public void testConstructor_badconverterObject_Chronology() throws Throwable {
546 try {
547 ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE);
548 DateTime test = new DateTime(new Integer(0), GregorianChronology.getInstance());
549 assertEquals(ISOChronology.getInstance(), test.getChronology());
550 assertEquals(0L, test.getMillis());
551 } finally {
552 ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE);
553 }
554 }
555
556
557
558
559
560 public void testConstructor_int_int_int_int_int() throws Throwable {
561 DateTime test = new DateTime(2002, 6, 9, 1, 0);
562 assertEquals(ISOChronology.getInstance(), test.getChronology());
563 assertEquals(LONDON, test.getZone());
564 assertEquals(TEST_TIME_NOW, test.getMillis());
565 }
566
567
568
569
570 public void testConstructor_int_int_int_int_int_DateTimeZone() throws Throwable {
571 DateTime test = new DateTime(2002, 6, 9, 2, 0, PARIS);
572 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
573 assertEquals(TEST_TIME_NOW, test.getMillis());
574 }
575
576
577
578
579 public void testConstructor_int_int_int_int_int_nullDateTimeZone() throws Throwable {
580 DateTime test = new DateTime(2002, 6, 9, 1, 0, (DateTimeZone) null);
581 assertEquals(ISOChronology.getInstance(), test.getChronology());
582 assertEquals(TEST_TIME_NOW, test.getMillis());
583 }
584
585
586
587
588 public void testConstructor_int_int_int_int_int_Chronology() throws Throwable {
589 DateTime test = new DateTime(2002, 6, 9, 1, 0, GregorianChronology.getInstance());
590 assertEquals(GregorianChronology.getInstance(), test.getChronology());
591 assertEquals(TEST_TIME_NOW, test.getMillis());
592 }
593
594
595
596
597 public void testConstructor_int_int_int_int_int_nullChronology() throws Throwable {
598 DateTime test = new DateTime(2002, 6, 9, 1, 0, (Chronology) null);
599 assertEquals(ISOChronology.getInstance(), test.getChronology());
600 assertEquals(TEST_TIME_NOW, test.getMillis());
601 }
602
603
604
605
606
607 public void testConstructor_int_int_int_int_int_int() throws Throwable {
608 DateTime test = new DateTime(2002, 6, 9, 1, 0, 0);
609 assertEquals(ISOChronology.getInstance(), test.getChronology());
610 assertEquals(LONDON, test.getZone());
611 assertEquals(TEST_TIME_NOW, test.getMillis());
612 }
613
614
615
616
617 public void testConstructor_int_int_int_int_int_int_DateTimeZone() throws Throwable {
618 DateTime test = new DateTime(2002, 6, 9, 2, 0, 0, PARIS);
619 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
620 assertEquals(TEST_TIME_NOW, test.getMillis());
621 }
622
623
624
625
626 public void testConstructor_int_int_int_int_int_int_nullDateTimeZone() throws Throwable {
627 DateTime test = new DateTime(2002, 6, 9, 1, 0, 0, (DateTimeZone) null);
628 assertEquals(ISOChronology.getInstance(), test.getChronology());
629 assertEquals(TEST_TIME_NOW, test.getMillis());
630 }
631
632
633
634
635 public void testConstructor_int_int_int_int_int_int_Chronology() throws Throwable {
636 DateTime test = new DateTime(2002, 6, 9, 1, 0, 0, GregorianChronology.getInstance());
637 assertEquals(GregorianChronology.getInstance(), test.getChronology());
638 assertEquals(TEST_TIME_NOW, test.getMillis());
639 }
640
641
642
643
644 public void testConstructor_int_int_int_int_int_int_nullChronology() throws Throwable {
645 DateTime test = new DateTime(2002, 6, 9, 1, 0, 0, (Chronology) null);
646 assertEquals(ISOChronology.getInstance(), test.getChronology());
647 assertEquals(TEST_TIME_NOW, test.getMillis());
648 }
649
650
651
652
653
654 public void testConstructor_int_int_int_int_int_int_int() throws Throwable {
655 DateTime test = new DateTime(2002, 6, 9, 1, 0, 0, 0);
656 assertEquals(ISOChronology.getInstance(), test.getChronology());
657 assertEquals(LONDON, test.getZone());
658 assertEquals(TEST_TIME_NOW, test.getMillis());
659 try {
660 new DateTime(Integer.MIN_VALUE, 6, 9, 0, 0, 0, 0);
661 fail();
662 } catch (IllegalArgumentException ex) {}
663 try {
664 new DateTime(Integer.MAX_VALUE, 6, 9, 0, 0, 0, 0);
665 fail();
666 } catch (IllegalArgumentException ex) {}
667 try {
668 new DateTime(2002, 0, 9, 0, 0, 0, 0);
669 fail();
670 } catch (IllegalArgumentException ex) {}
671 try {
672 new DateTime(2002, 13, 9, 0, 0, 0, 0);
673 fail();
674 } catch (IllegalArgumentException ex) {}
675 try {
676 new DateTime(2002, 6, 0, 0, 0, 0, 0);
677 fail();
678 } catch (IllegalArgumentException ex) {}
679 try {
680 new DateTime(2002, 6, 31, 0, 0, 0, 0);
681 fail();
682 } catch (IllegalArgumentException ex) {}
683 new DateTime(2002, 7, 31, 0, 0, 0, 0);
684 try {
685 new DateTime(2002, 7, 32, 0, 0, 0, 0);
686 fail();
687 } catch (IllegalArgumentException ex) {}
688 }
689
690
691
692
693 public void testConstructor_int_int_int_int_int_int_int_DateTimeZone() throws Throwable {
694 DateTime test = new DateTime(2002, 6, 9, 2, 0, 0, 0, PARIS);
695 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
696 assertEquals(TEST_TIME_NOW, test.getMillis());
697 try {
698 new DateTime(Integer.MIN_VALUE, 6, 9, 0, 0, 0, 0, PARIS);
699 fail();
700 } catch (IllegalArgumentException ex) {}
701 try {
702 new DateTime(Integer.MAX_VALUE, 6, 9, 0, 0, 0, 0, PARIS);
703 fail();
704 } catch (IllegalArgumentException ex) {}
705 try {
706 new DateTime(2002, 0, 9, 0, 0, 0, 0, PARIS);
707 fail();
708 } catch (IllegalArgumentException ex) {}
709 try {
710 new DateTime(2002, 13, 9, 0, 0, 0, 0, PARIS);
711 fail();
712 } catch (IllegalArgumentException ex) {}
713 try {
714 new DateTime(2002, 6, 0, 0, 0, 0, 0, PARIS);
715 fail();
716 } catch (IllegalArgumentException ex) {}
717 try {
718 new DateTime(2002, 6, 31, 0, 0, 0, 0, PARIS);
719 fail();
720 } catch (IllegalArgumentException ex) {}
721 new DateTime(2002, 7, 31, 0, 0, 0, 0, PARIS);
722 try {
723 new DateTime(2002, 7, 32, 0, 0, 0, 0, PARIS);
724 fail();
725 } catch (IllegalArgumentException ex) {}
726 }
727
728
729
730
731 public void testConstructor_int_int_int_int_int_int_int_nullDateTimeZone() throws Throwable {
732 DateTime test = new DateTime(2002, 6, 9, 1, 0, 0, 0, (DateTimeZone) null);
733 assertEquals(ISOChronology.getInstance(), test.getChronology());
734 assertEquals(TEST_TIME_NOW, test.getMillis());
735 }
736
737
738
739
740 public void testConstructor_int_int_int_int_int_int_int_Chronology() throws Throwable {
741 DateTime test = new DateTime(2002, 6, 9, 1, 0, 0, 0, GregorianChronology.getInstance());
742 assertEquals(GregorianChronology.getInstance(), test.getChronology());
743 assertEquals(TEST_TIME_NOW, test.getMillis());
744 try {
745 new DateTime(Integer.MIN_VALUE, 6, 9, 0, 0, 0, 0, GregorianChronology.getInstance());
746 fail();
747 } catch (IllegalArgumentException ex) {}
748 try {
749 new DateTime(Integer.MAX_VALUE, 6, 9, 0, 0, 0, 0, GregorianChronology.getInstance());
750 fail();
751 } catch (IllegalArgumentException ex) {}
752 try {
753 new DateTime(2002, 0, 9, 0, 0, 0, 0, GregorianChronology.getInstance());
754 fail();
755 } catch (IllegalArgumentException ex) {}
756 try {
757 new DateTime(2002, 13, 9, 0, 0, 0, 0, GregorianChronology.getInstance());
758 fail();
759 } catch (IllegalArgumentException ex) {}
760 try {
761 new DateTime(2002, 6, 0, 0, 0, 0, 0, GregorianChronology.getInstance());
762 fail();
763 } catch (IllegalArgumentException ex) {}
764 try {
765 new DateTime(2002, 6, 31, 0, 0, 0, 0, GregorianChronology.getInstance());
766 fail();
767 } catch (IllegalArgumentException ex) {}
768 new DateTime(2002, 7, 31, 0, 0, 0, 0, GregorianChronology.getInstance());
769 try {
770 new DateTime(2002, 7, 32, 0, 0, 0, 0, GregorianChronology.getInstance());
771 fail();
772 } catch (IllegalArgumentException ex) {}
773 }
774
775
776
777
778 public void testConstructor_int_int_int_int_int_int_int_nullChronology() throws Throwable {
779 DateTime test = new DateTime(2002, 6, 9, 1, 0, 0, 0, (Chronology) null);
780 assertEquals(ISOChronology.getInstance(), test.getChronology());
781 assertEquals(TEST_TIME_NOW, test.getMillis());
782 }
783
784 }