001: /*
002: * Copyright 2001-2006 Stephen Colebourne
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.joda.time;
017:
018: import java.util.Date;
019: import java.util.Locale;
020:
021: import junit.framework.TestCase;
022: import junit.framework.TestSuite;
023:
024: import org.joda.time.chrono.GregorianChronology;
025: import org.joda.time.chrono.ISOChronology;
026: import org.joda.time.convert.ConverterManager;
027: import org.joda.time.convert.MockZeroNullIntegerConverter;
028:
029: /**
030: * This class is a Junit unit test for DateTime.
031: *
032: * @author Stephen Colebourne
033: */
034: public class TestDateTime_Constructors extends TestCase {
035: // Test in 2002/03 as time zones are more well known
036: // (before the late 90's they were all over the place)
037:
038: private static final DateTimeZone PARIS = DateTimeZone
039: .forID("Europe/Paris");
040: private static final DateTimeZone LONDON = DateTimeZone
041: .forID("Europe/London");
042:
043: long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
044: + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365
045: + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
046: + 365 + 365 + 366 + 365;
047: long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
048: + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365
049: + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
050: + 365 + 365 + 366 + 365 + 365;
051:
052: // 2002-06-09
053: private long TEST_TIME_NOW = (y2002days + 31L + 28L + 31L + 30L
054: + 31L + 9L - 1L)
055: * DateTimeConstants.MILLIS_PER_DAY;
056:
057: // 2002-04-05
058: private long TEST_TIME1 = (y2002days + 31L + 28L + 31L + 5L - 1L)
059: * DateTimeConstants.MILLIS_PER_DAY + 12L
060: * DateTimeConstants.MILLIS_PER_HOUR + 24L
061: * DateTimeConstants.MILLIS_PER_MINUTE;
062:
063: // 2003-05-06
064: private long TEST_TIME2 = (y2003days + 31L + 28L + 31L + 30L + 6L - 1L)
065: * DateTimeConstants.MILLIS_PER_DAY
066: + 14L
067: * DateTimeConstants.MILLIS_PER_HOUR
068: + 28L
069: * DateTimeConstants.MILLIS_PER_MINUTE;
070:
071: private DateTimeZone zone = null;
072: private Locale locale = null;
073:
074: public static void main(String[] args) {
075: junit.textui.TestRunner.run(suite());
076: }
077:
078: public static TestSuite suite() {
079: return new TestSuite(TestDateTime_Constructors.class);
080: }
081:
082: public TestDateTime_Constructors(String name) {
083: super (name);
084: }
085:
086: protected void setUp() throws Exception {
087: DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
088: zone = DateTimeZone.getDefault();
089: locale = Locale.getDefault();
090: DateTimeZone.setDefault(LONDON);
091: java.util.TimeZone.setDefault(LONDON.toTimeZone());
092: Locale.setDefault(Locale.UK);
093: }
094:
095: protected void tearDown() throws Exception {
096: DateTimeUtils.setCurrentMillisSystem();
097: DateTimeZone.setDefault(zone);
098: java.util.TimeZone.setDefault(zone.toTimeZone());
099: Locale.setDefault(locale);
100: zone = null;
101: }
102:
103: //-----------------------------------------------------------------------
104: public void testTest() {
105: assertEquals("2002-06-09T00:00:00.000Z", new Instant(
106: TEST_TIME_NOW).toString());
107: assertEquals("2002-04-05T12:24:00.000Z",
108: new Instant(TEST_TIME1).toString());
109: assertEquals("2003-05-06T14:28:00.000Z",
110: new Instant(TEST_TIME2).toString());
111: }
112:
113: //-----------------------------------------------------------------------
114: /**
115: * Test constructor ()
116: */
117: public void testConstructor() throws Throwable {
118: DateTime test = new DateTime();
119: assertEquals(ISOChronology.getInstance(), test.getChronology());
120: assertEquals(TEST_TIME_NOW, test.getMillis());
121: }
122:
123: /**
124: * Test constructor (DateTimeZone)
125: */
126: public void testConstructor_DateTimeZone() throws Throwable {
127: DateTime test = new DateTime(PARIS);
128: assertEquals(ISOChronology.getInstance(PARIS), test
129: .getChronology());
130: assertEquals(TEST_TIME_NOW, test.getMillis());
131: }
132:
133: /**
134: * Test constructor (DateTimeZone=null)
135: */
136: public void testConstructor_nullDateTimeZone() throws Throwable {
137: DateTime test = new DateTime((DateTimeZone) null);
138: assertEquals(ISOChronology.getInstance(), test.getChronology());
139: assertEquals(TEST_TIME_NOW, test.getMillis());
140: }
141:
142: /**
143: * Test constructor (Chronology)
144: */
145: public void testConstructor_Chronology() throws Throwable {
146: DateTime test = new DateTime(GregorianChronology.getInstance());
147: assertEquals(GregorianChronology.getInstance(), test
148: .getChronology());
149: assertEquals(TEST_TIME_NOW, test.getMillis());
150: }
151:
152: /**
153: * Test constructor (Chronology=null)
154: */
155: public void testConstructor_nullChronology() throws Throwable {
156: DateTime test = new DateTime((Chronology) null);
157: assertEquals(ISOChronology.getInstance(), test.getChronology());
158: assertEquals(TEST_TIME_NOW, test.getMillis());
159: }
160:
161: //-----------------------------------------------------------------------
162: /**
163: * Test constructor (long)
164: */
165: public void testConstructor_long1() throws Throwable {
166: DateTime test = new DateTime(TEST_TIME1);
167: assertEquals(ISOChronology.getInstance(), test.getChronology());
168: assertEquals(TEST_TIME1, test.getMillis());
169: }
170:
171: /**
172: * Test constructor (long)
173: */
174: public void testConstructor_long2() throws Throwable {
175: DateTime test = new DateTime(TEST_TIME2);
176: assertEquals(ISOChronology.getInstance(), test.getChronology());
177: assertEquals(TEST_TIME2, test.getMillis());
178: }
179:
180: /**
181: * Test constructor (long, DateTimeZone)
182: */
183: public void testConstructor_long1_DateTimeZone() throws Throwable {
184: DateTime test = new DateTime(TEST_TIME1, PARIS);
185: assertEquals(ISOChronology.getInstance(PARIS), test
186: .getChronology());
187: assertEquals(TEST_TIME1, test.getMillis());
188: }
189:
190: /**
191: * Test constructor (long, DateTimeZone)
192: */
193: public void testConstructor_long2_DateTimeZone() throws Throwable {
194: DateTime test = new DateTime(TEST_TIME2, PARIS);
195: assertEquals(ISOChronology.getInstance(PARIS), test
196: .getChronology());
197: assertEquals(TEST_TIME2, test.getMillis());
198: }
199:
200: /**
201: * Test constructor (long, DateTimeZone=null)
202: */
203: public void testConstructor_long_nullDateTimeZone()
204: throws Throwable {
205: DateTime test = new DateTime(TEST_TIME1, (DateTimeZone) null);
206: assertEquals(ISOChronology.getInstance(), test.getChronology());
207: assertEquals(TEST_TIME1, test.getMillis());
208: }
209:
210: /**
211: * Test constructor (long, Chronology)
212: */
213: public void testConstructor_long1_Chronology() throws Throwable {
214: DateTime test = new DateTime(TEST_TIME1, GregorianChronology
215: .getInstance());
216: assertEquals(GregorianChronology.getInstance(), test
217: .getChronology());
218: assertEquals(TEST_TIME1, test.getMillis());
219: }
220:
221: /**
222: * Test constructor (long, Chronology)
223: */
224: public void testConstructor_long2_Chronology() throws Throwable {
225: DateTime test = new DateTime(TEST_TIME2, GregorianChronology
226: .getInstance());
227: assertEquals(GregorianChronology.getInstance(), test
228: .getChronology());
229: assertEquals(TEST_TIME2, test.getMillis());
230: }
231:
232: /**
233: * Test constructor (long, Chronology=null)
234: */
235: public void testConstructor_long_nullChronology() throws Throwable {
236: DateTime test = new DateTime(TEST_TIME1, (Chronology) null);
237: assertEquals(ISOChronology.getInstance(), test.getChronology());
238: assertEquals(TEST_TIME1, test.getMillis());
239: }
240:
241: //-----------------------------------------------------------------------
242: /**
243: * Test constructor (Object)
244: */
245: public void testConstructor_Object() throws Throwable {
246: Date date = new Date(TEST_TIME1);
247: DateTime test = new DateTime(date);
248: assertEquals(ISOChronology.getInstance(), test.getChronology());
249: assertEquals(TEST_TIME1, test.getMillis());
250: }
251:
252: /**
253: * Test constructor (Object)
254: */
255: public void testConstructor_invalidObject() throws Throwable {
256: try {
257: new DateTime(new Object());
258: fail();
259: } catch (IllegalArgumentException ex) {
260: }
261: }
262:
263: /**
264: * Test constructor (Object=null)
265: */
266: public void testConstructor_nullObject() throws Throwable {
267: DateTime test = new DateTime((Object) null);
268: assertEquals(ISOChronology.getInstance(), test.getChronology());
269: assertEquals(TEST_TIME_NOW, test.getMillis());
270: }
271:
272: /**
273: * Test constructor (Object=null)
274: */
275: public void testConstructor_badconverterObject() throws Throwable {
276: try {
277: ConverterManager.getInstance().addInstantConverter(
278: MockZeroNullIntegerConverter.INSTANCE);
279: DateTime test = new DateTime(new Integer(0));
280: assertEquals(ISOChronology.getInstance(), test
281: .getChronology());
282: assertEquals(0L, test.getMillis());
283: } finally {
284: ConverterManager.getInstance().removeInstantConverter(
285: MockZeroNullIntegerConverter.INSTANCE);
286: }
287: }
288:
289: public void testConstructor_ObjectString1() throws Throwable {
290: DateTime test = new DateTime("1972-12-03");
291: assertEquals(ISOChronology.getInstance(), test.getChronology());
292: assertEquals(1972, test.getYear());
293: assertEquals(12, test.getMonthOfYear());
294: assertEquals(3, test.getDayOfMonth());
295: assertEquals(0, test.getHourOfDay());
296: assertEquals(0, test.getMinuteOfHour());
297: assertEquals(0, test.getSecondOfMinute());
298: assertEquals(0, test.getMillisOfSecond());
299: }
300:
301: public void testConstructor_ObjectString2() throws Throwable {
302: DateTime test = new DateTime("2006-06-03T+14:00");
303: assertEquals(ISOChronology.getInstance(), test.getChronology());
304: assertEquals(2006, test.getYear());
305: assertEquals(6, test.getMonthOfYear());
306: assertEquals(2, test.getDayOfMonth()); // timezone
307: assertEquals(11, test.getHourOfDay()); // test zone is +1, so shift back (14 - 1) hours from midnight
308: assertEquals(0, test.getMinuteOfHour());
309: assertEquals(0, test.getSecondOfMinute());
310: assertEquals(0, test.getMillisOfSecond());
311: }
312:
313: public void testConstructor_ObjectString3() throws Throwable {
314: DateTime test = new DateTime("1972-12-03T10:20:30.040");
315: assertEquals(ISOChronology.getInstance(), test.getChronology());
316: assertEquals(1972, test.getYear());
317: assertEquals(12, test.getMonthOfYear());
318: assertEquals(3, test.getDayOfMonth());
319: assertEquals(10, test.getHourOfDay());
320: assertEquals(20, test.getMinuteOfHour());
321: assertEquals(30, test.getSecondOfMinute());
322: assertEquals(40, test.getMillisOfSecond());
323: }
324:
325: public void testConstructor_ObjectString4() throws Throwable {
326: DateTime test = new DateTime("2006-06-03T10:20:30.040+14:00");
327: assertEquals(ISOChronology.getInstance(), test.getChronology());
328: assertEquals(2006, test.getYear());
329: assertEquals(6, test.getMonthOfYear());
330: assertEquals(2, test.getDayOfMonth()); // timezone
331: assertEquals(21, test.getHourOfDay()); // test zone is +1, so shift back (14 - 1) hours from 10am
332: assertEquals(20, test.getMinuteOfHour());
333: assertEquals(30, test.getSecondOfMinute());
334: assertEquals(40, test.getMillisOfSecond());
335: }
336:
337: public void testConstructor_ObjectString5() throws Throwable {
338: DateTime test = new DateTime("T10:20:30.040");
339: assertEquals(ISOChronology.getInstance(), test.getChronology());
340: assertEquals(1970, test.getYear());
341: assertEquals(1, test.getMonthOfYear());
342: assertEquals(1, test.getDayOfMonth());
343: assertEquals(10, test.getHourOfDay());
344: assertEquals(20, test.getMinuteOfHour());
345: assertEquals(30, test.getSecondOfMinute());
346: assertEquals(40, test.getMillisOfSecond());
347: }
348:
349: public void testConstructor_ObjectString6() throws Throwable {
350: DateTime test = new DateTime("T10:20:30.040+14:00");
351: assertEquals(ISOChronology.getInstance(), test.getChronology());
352: assertEquals(1969, test.getYear()); // timezone
353: assertEquals(12, test.getMonthOfYear()); // timezone
354: assertEquals(31, test.getDayOfMonth()); // timezone
355: assertEquals(21, test.getHourOfDay()); // test zone is +1, so shift back (14 - 1) hours from 10am
356: assertEquals(20, test.getMinuteOfHour());
357: assertEquals(30, test.getSecondOfMinute());
358: assertEquals(40, test.getMillisOfSecond());
359: }
360:
361: public void testConstructor_ObjectString7() throws Throwable {
362: DateTime test = new DateTime("10");
363: assertEquals(ISOChronology.getInstance(), test.getChronology());
364: assertEquals(10, test.getYear());
365: assertEquals(1, test.getMonthOfYear());
366: assertEquals(1, test.getDayOfMonth());
367: assertEquals(0, test.getHourOfDay());
368: assertEquals(0, test.getMinuteOfHour());
369: assertEquals(0, test.getSecondOfMinute());
370: assertEquals(0, test.getMillisOfSecond());
371: }
372:
373: public void testConstructor_ObjectStringEx1() throws Throwable {
374: try {
375: new DateTime("10:20:30.040");
376: fail();
377: } catch (IllegalArgumentException ex) {
378: // expected
379: }
380: }
381:
382: public void testConstructor_ObjectStringEx2() throws Throwable {
383: try {
384: new DateTime("10:20:30.040+14:00");
385: fail();
386: } catch (IllegalArgumentException ex) {
387: // expected
388: }
389: }
390:
391: //-----------------------------------------------------------------------
392: /**
393: * Test constructor (Object, DateTimeZone)
394: */
395: public void testConstructor_Object_DateTimeZone() throws Throwable {
396: Date date = new Date(TEST_TIME1);
397: DateTime test = new DateTime(date, PARIS);
398: assertEquals(ISOChronology.getInstance(PARIS), test
399: .getChronology());
400: assertEquals(TEST_TIME1, test.getMillis());
401: }
402:
403: /**
404: * Test constructor (Object, DateTimeZone)
405: */
406: public void testConstructor_invalidObject_DateTimeZone()
407: throws Throwable {
408: try {
409: new DateTime(new Object(), PARIS);
410: fail();
411: } catch (IllegalArgumentException ex) {
412: }
413: }
414:
415: /**
416: * Test constructor (Object=null, DateTimeZone)
417: */
418: public void testConstructor_nullObject_DateTimeZone()
419: throws Throwable {
420: DateTime test = new DateTime((Object) null, PARIS);
421: assertEquals(ISOChronology.getInstance(PARIS), test
422: .getChronology());
423: assertEquals(TEST_TIME_NOW, test.getMillis());
424: }
425:
426: /**
427: * Test constructor (Object, DateTimeZone=null)
428: */
429: public void testConstructor_Object_nullDateTimeZone()
430: throws Throwable {
431: Date date = new Date(TEST_TIME1);
432: DateTime test = new DateTime(date, (DateTimeZone) null);
433: assertEquals(ISOChronology.getInstance(), test.getChronology());
434: assertEquals(TEST_TIME1, test.getMillis());
435: }
436:
437: /**
438: * Test constructor (Object=null, DateTimeZone=null)
439: */
440: public void testConstructor_nullObject_nullDateTimeZone()
441: throws Throwable {
442: DateTime test = new DateTime((Object) null, (DateTimeZone) null);
443: assertEquals(ISOChronology.getInstance(), test.getChronology());
444: assertEquals(TEST_TIME_NOW, test.getMillis());
445: }
446:
447: /**
448: * Test constructor (Object, DateTimeZone)
449: */
450: public void testConstructor_badconverterObject_DateTimeZone()
451: throws Throwable {
452: try {
453: ConverterManager.getInstance().addInstantConverter(
454: MockZeroNullIntegerConverter.INSTANCE);
455: DateTime test = new DateTime(new Integer(0),
456: GregorianChronology.getInstance());
457: assertEquals(ISOChronology.getInstance(), test
458: .getChronology());
459: assertEquals(0L, test.getMillis());
460: } finally {
461: ConverterManager.getInstance().removeInstantConverter(
462: MockZeroNullIntegerConverter.INSTANCE);
463: }
464: }
465:
466: /**
467: * Test constructor (Object, Chronology)
468: */
469: public void testConstructor_Object_Chronology() throws Throwable {
470: Date date = new Date(TEST_TIME1);
471: DateTime test = new DateTime(date, GregorianChronology
472: .getInstance());
473: assertEquals(GregorianChronology.getInstance(), test
474: .getChronology());
475: assertEquals(TEST_TIME1, test.getMillis());
476: }
477:
478: /**
479: * Test constructor (Object, Chronology)
480: */
481: public void testConstructor_invalidObject_Chronology()
482: throws Throwable {
483: try {
484: new DateTime(new Object(), GregorianChronology
485: .getInstance());
486: fail();
487: } catch (IllegalArgumentException ex) {
488: }
489: }
490:
491: /**
492: * Test constructor (Object=null, Chronology)
493: */
494: public void testConstructor_nullObject_Chronology()
495: throws Throwable {
496: DateTime test = new DateTime((Object) null, GregorianChronology
497: .getInstance());
498: assertEquals(GregorianChronology.getInstance(), test
499: .getChronology());
500: assertEquals(TEST_TIME_NOW, test.getMillis());
501: }
502:
503: /**
504: * Test constructor (Object, Chronology=null)
505: */
506: public void testConstructor_Object_nullChronology()
507: throws Throwable {
508: Date date = new Date(TEST_TIME1);
509: DateTime test = new DateTime(date, (Chronology) null);
510: assertEquals(ISOChronology.getInstance(), test.getChronology());
511: assertEquals(TEST_TIME1, test.getMillis());
512: }
513:
514: /**
515: * Test constructor (Object=null, Chronology=null)
516: */
517: public void testConstructor_nullObject_nullChronology()
518: throws Throwable {
519: DateTime test = new DateTime((Object) null, (Chronology) null);
520: assertEquals(ISOChronology.getInstance(), test.getChronology());
521: assertEquals(TEST_TIME_NOW, test.getMillis());
522: }
523:
524: /**
525: * Test constructor (Object, Chronology)
526: */
527: public void testConstructor_badconverterObject_Chronology()
528: throws Throwable {
529: try {
530: ConverterManager.getInstance().addInstantConverter(
531: MockZeroNullIntegerConverter.INSTANCE);
532: DateTime test = new DateTime(new Integer(0),
533: GregorianChronology.getInstance());
534: assertEquals(ISOChronology.getInstance(), test
535: .getChronology());
536: assertEquals(0L, test.getMillis());
537: } finally {
538: ConverterManager.getInstance().removeInstantConverter(
539: MockZeroNullIntegerConverter.INSTANCE);
540: }
541: }
542:
543: //-----------------------------------------------------------------------
544: /**
545: * Test constructor (int, int, int)
546: */
547: public void testConstructor_int_int_int_int_int_int_int()
548: throws Throwable {
549: DateTime test = new DateTime(2002, 6, 9, 1, 0, 0, 0); // +01:00
550: assertEquals(ISOChronology.getInstance(), test.getChronology());
551: assertEquals(LONDON, test.getZone());
552: assertEquals(TEST_TIME_NOW, test.getMillis());
553: try {
554: new DateTime(Integer.MIN_VALUE, 6, 9, 0, 0, 0, 0);
555: fail();
556: } catch (IllegalArgumentException ex) {
557: }
558: try {
559: new DateTime(Integer.MAX_VALUE, 6, 9, 0, 0, 0, 0);
560: fail();
561: } catch (IllegalArgumentException ex) {
562: }
563: try {
564: new DateTime(2002, 0, 9, 0, 0, 0, 0);
565: fail();
566: } catch (IllegalArgumentException ex) {
567: }
568: try {
569: new DateTime(2002, 13, 9, 0, 0, 0, 0);
570: fail();
571: } catch (IllegalArgumentException ex) {
572: }
573: try {
574: new DateTime(2002, 6, 0, 0, 0, 0, 0);
575: fail();
576: } catch (IllegalArgumentException ex) {
577: }
578: try {
579: new DateTime(2002, 6, 31, 0, 0, 0, 0);
580: fail();
581: } catch (IllegalArgumentException ex) {
582: }
583: new DateTime(2002, 7, 31, 0, 0, 0, 0);
584: try {
585: new DateTime(2002, 7, 32, 0, 0, 0, 0);
586: fail();
587: } catch (IllegalArgumentException ex) {
588: }
589: }
590:
591: /**
592: * Test constructor (int, int, int, DateTimeZone)
593: */
594: public void testConstructor_int_int_int_int_int_int_int_DateTimeZone()
595: throws Throwable {
596: DateTime test = new DateTime(2002, 6, 9, 2, 0, 0, 0, PARIS); // +02:00
597: assertEquals(ISOChronology.getInstance(PARIS), test
598: .getChronology());
599: assertEquals(TEST_TIME_NOW, test.getMillis());
600: try {
601: new DateTime(Integer.MIN_VALUE, 6, 9, 0, 0, 0, 0, PARIS);
602: fail();
603: } catch (IllegalArgumentException ex) {
604: }
605: try {
606: new DateTime(Integer.MAX_VALUE, 6, 9, 0, 0, 0, 0, PARIS);
607: fail();
608: } catch (IllegalArgumentException ex) {
609: }
610: try {
611: new DateTime(2002, 0, 9, 0, 0, 0, 0, PARIS);
612: fail();
613: } catch (IllegalArgumentException ex) {
614: }
615: try {
616: new DateTime(2002, 13, 9, 0, 0, 0, 0, PARIS);
617: fail();
618: } catch (IllegalArgumentException ex) {
619: }
620: try {
621: new DateTime(2002, 6, 0, 0, 0, 0, 0, PARIS);
622: fail();
623: } catch (IllegalArgumentException ex) {
624: }
625: try {
626: new DateTime(2002, 6, 31, 0, 0, 0, 0, PARIS);
627: fail();
628: } catch (IllegalArgumentException ex) {
629: }
630: new DateTime(2002, 7, 31, 0, 0, 0, 0, PARIS);
631: try {
632: new DateTime(2002, 7, 32, 0, 0, 0, 0, PARIS);
633: fail();
634: } catch (IllegalArgumentException ex) {
635: }
636: }
637:
638: /**
639: * Test constructor (int, int, int, DateTimeZone=null)
640: */
641: public void testConstructor_int_int_int_int_int_int_int_nullDateTimeZone()
642: throws Throwable {
643: DateTime test = new DateTime(2002, 6, 9, 1, 0, 0, 0,
644: (DateTimeZone) null); // +01:00
645: assertEquals(ISOChronology.getInstance(), test.getChronology());
646: assertEquals(TEST_TIME_NOW, test.getMillis());
647: }
648:
649: /**
650: * Test constructor (int, int, int, Chronology)
651: */
652: public void testConstructor_int_int_int_int_int_int_int_Chronology()
653: throws Throwable {
654: DateTime test = new DateTime(2002, 6, 9, 1, 0, 0, 0,
655: GregorianChronology.getInstance()); // +01:00
656: assertEquals(GregorianChronology.getInstance(), test
657: .getChronology());
658: assertEquals(TEST_TIME_NOW, test.getMillis());
659: try {
660: new DateTime(Integer.MIN_VALUE, 6, 9, 0, 0, 0, 0,
661: GregorianChronology.getInstance());
662: fail();
663: } catch (IllegalArgumentException ex) {
664: }
665: try {
666: new DateTime(Integer.MAX_VALUE, 6, 9, 0, 0, 0, 0,
667: GregorianChronology.getInstance());
668: fail();
669: } catch (IllegalArgumentException ex) {
670: }
671: try {
672: new DateTime(2002, 0, 9, 0, 0, 0, 0, GregorianChronology
673: .getInstance());
674: fail();
675: } catch (IllegalArgumentException ex) {
676: }
677: try {
678: new DateTime(2002, 13, 9, 0, 0, 0, 0, GregorianChronology
679: .getInstance());
680: fail();
681: } catch (IllegalArgumentException ex) {
682: }
683: try {
684: new DateTime(2002, 6, 0, 0, 0, 0, 0, GregorianChronology
685: .getInstance());
686: fail();
687: } catch (IllegalArgumentException ex) {
688: }
689: try {
690: new DateTime(2002, 6, 31, 0, 0, 0, 0, GregorianChronology
691: .getInstance());
692: fail();
693: } catch (IllegalArgumentException ex) {
694: }
695: new DateTime(2002, 7, 31, 0, 0, 0, 0, GregorianChronology
696: .getInstance());
697: try {
698: new DateTime(2002, 7, 32, 0, 0, 0, 0, GregorianChronology
699: .getInstance());
700: fail();
701: } catch (IllegalArgumentException ex) {
702: }
703: }
704:
705: /**
706: * Test constructor (int, int, int, Chronology=null)
707: */
708: public void testConstructor_int_int_int_int_int_int_int_nullChronology()
709: throws Throwable {
710: DateTime test = new DateTime(2002, 6, 9, 1, 0, 0, 0,
711: (Chronology) null); // +01:00
712: assertEquals(ISOChronology.getInstance(), test.getChronology());
713: assertEquals(TEST_TIME_NOW, test.getMillis());
714: }
715:
716: }
|