KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joda > time > TestDateTime_Constructors


1 /*
2  * Copyright 2001-2006 Stephen Colebourne
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.joda.time;
17
18 import java.util.Date JavaDoc;
19 import java.util.Locale JavaDoc;
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
29 /**
30  * This class is a Junit unit test for DateTime.
31  *
32  * @author Stephen Colebourne
33  */

34 public class TestDateTime_Constructors extends TestCase {
35     // Test in 2002/03 as time zones are more well known
36
// (before the late 90's they were all over the place)
37

38     private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
39     private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
40     
41     long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
42                      366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 +
43                      365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
44                      366 + 365;
45     long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
46                      366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 +
47                      365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
48                      366 + 365 + 365;
49     
50     // 2002-06-09
51
private long TEST_TIME_NOW =
52             (y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY;
53             
54     // 2002-04-05
55
private long TEST_TIME1 =
56             (y2002days + 31L + 28L + 31L + 5L -1L) * DateTimeConstants.MILLIS_PER_DAY
57             + 12L * DateTimeConstants.MILLIS_PER_HOUR
58             + 24L * DateTimeConstants.MILLIS_PER_MINUTE;
59         
60     // 2003-05-06
61
private long TEST_TIME2 =
62             (y2003days + 31L + 28L + 31L + 30L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY
63             + 14L * DateTimeConstants.MILLIS_PER_HOUR
64             + 28L * DateTimeConstants.MILLIS_PER_MINUTE;
65         
66     private DateTimeZone zone = null;
67     private Locale JavaDoc locale = null;
68
69     public static void main(String JavaDoc[] args) {
70         junit.textui.TestRunner.run(suite());
71     }
72
73     public static TestSuite suite() {
74         return new TestSuite(TestDateTime_Constructors.class);
75     }
76
77     public TestDateTime_Constructors(String JavaDoc name) {
78         super(name);
79     }
80
81     protected void setUp() throws Exception JavaDoc {
82         DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
83         zone = DateTimeZone.getDefault();
84         locale = Locale.getDefault();
85         DateTimeZone.setDefault(LONDON);
86         java.util.TimeZone.setDefault(LONDON.toTimeZone());
87         Locale.setDefault(Locale.UK);
88     }
89
90     protected void tearDown() throws Exception JavaDoc {
91         DateTimeUtils.setCurrentMillisSystem();
92         DateTimeZone.setDefault(zone);
93         java.util.TimeZone.setDefault(zone.toTimeZone());
94         Locale.setDefault(locale);
95         zone = null;
96     }
97
98     //-----------------------------------------------------------------------
99
public void testTest() {
100         assertEquals("2002-06-09T00:00:00.000Z", new Instant(TEST_TIME_NOW).toString());
101         assertEquals("2002-04-05T12:24:00.000Z", new Instant(TEST_TIME1).toString());
102         assertEquals("2003-05-06T14:28:00.000Z", new Instant(TEST_TIME2).toString());
103     }
104
105     //-----------------------------------------------------------------------
106
/**
107      * Test constructor ()
108      */

109     public void testConstructor() throws Throwable JavaDoc {
110         DateTime test = new DateTime();
111         assertEquals(ISOChronology.getInstance(), test.getChronology());
112         assertEquals(TEST_TIME_NOW, test.getMillis());
113     }
114
115     /**
116      * Test constructor (DateTimeZone)
117      */

118     public void testConstructor_DateTimeZone() throws Throwable JavaDoc {
119         DateTime test = new DateTime(PARIS);
120         assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
121         assertEquals(TEST_TIME_NOW, test.getMillis());
122     }
123
124     /**
125      * Test constructor (DateTimeZone=null)
126      */

127     public void testConstructor_nullDateTimeZone() throws Throwable JavaDoc {
128         DateTime test = new DateTime((DateTimeZone) null);
129         assertEquals(ISOChronology.getInstance(), test.getChronology());
130         assertEquals(TEST_TIME_NOW, test.getMillis());
131     }
132
133     /**
134      * Test constructor (Chronology)
135      */

136     public void testConstructor_Chronology() throws Throwable JavaDoc {
137         DateTime test = new DateTime(GregorianChronology.getInstance());
138         assertEquals(GregorianChronology.getInstance(), test.getChronology());
139         assertEquals(TEST_TIME_NOW, test.getMillis());
140     }
141
142     /**
143      * Test constructor (Chronology=null)
144      */

145     public void testConstructor_nullChronology() throws Throwable JavaDoc {
146         DateTime test = new DateTime((Chronology) null);
147         assertEquals(ISOChronology.getInstance(), test.getChronology());
148         assertEquals(TEST_TIME_NOW, test.getMillis());
149     }
150
151     //-----------------------------------------------------------------------
152
/**
153      * Test constructor (long)
154      */

155     public void testConstructor_long1() throws Throwable JavaDoc {
156         DateTime test = new DateTime(TEST_TIME1);
157         assertEquals(ISOChronology.getInstance(), test.getChronology());
158         assertEquals(TEST_TIME1, test.getMillis());
159     }
160
161     /**
162      * Test constructor (long)
163      */

164     public void testConstructor_long2() throws Throwable JavaDoc {
165         DateTime test = new DateTime(TEST_TIME2);
166         assertEquals(ISOChronology.getInstance(), test.getChronology());
167         assertEquals(TEST_TIME2, test.getMillis());
168     }
169
170     /**
171      * Test constructor (long, DateTimeZone)
172      */

173     public void testConstructor_long1_DateTimeZone() throws Throwable JavaDoc {
174         DateTime test = new DateTime(TEST_TIME1, PARIS);
175         assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
176         assertEquals(TEST_TIME1, test.getMillis());
177     }
178
179     /**
180      * Test constructor (long, DateTimeZone)
181      */

182     public void testConstructor_long2_DateTimeZone() throws Throwable JavaDoc {
183         DateTime test = new DateTime(TEST_TIME2, PARIS);
184         assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
185         assertEquals(TEST_TIME2, test.getMillis());
186     }
187
188     /**
189      * Test constructor (long, DateTimeZone=null)
190      */

191     public void testConstructor_long_nullDateTimeZone() throws Throwable JavaDoc {
192         DateTime test = new DateTime(TEST_TIME1, (DateTimeZone) null);
193         assertEquals(ISOChronology.getInstance(), test.getChronology());
194         assertEquals(TEST_TIME1, test.getMillis());
195     }
196
197     /**
198      * Test constructor (long, Chronology)
199      */

200     public void testConstructor_long1_Chronology() throws Throwable JavaDoc {
201         DateTime test = new DateTime(TEST_TIME1, GregorianChronology.getInstance());
202         assertEquals(GregorianChronology.getInstance(), test.getChronology());
203         assertEquals(TEST_TIME1, test.getMillis());
204     }
205
206     /**
207      * Test constructor (long, Chronology)
208      */

209     public void testConstructor_long2_Chronology() throws Throwable JavaDoc {
210         DateTime test = new DateTime(TEST_TIME2, GregorianChronology.getInstance());
211         assertEquals(GregorianChronology.getInstance(), test.getChronology());
212         assertEquals(TEST_TIME2, test.getMillis());
213     }
214
215     /**
216      * Test constructor (long, Chronology=null)
217      */

218     public void testConstructor_long_nullChronology() throws Throwable JavaDoc {
219         DateTime test = new DateTime(TEST_TIME1, (Chronology) null);
220         assertEquals(ISOChronology.getInstance(), test.getChronology());
221         assertEquals(TEST_TIME1, test.getMillis());
222     }
223
224     //-----------------------------------------------------------------------
225
/**
226      * Test constructor (Object)
227      */

228     public void testConstructor_Object() throws Throwable JavaDoc {
229         Date JavaDoc date = new Date JavaDoc(TEST_TIME1);
230         DateTime test = new DateTime(date);
231         assertEquals(ISOChronology.getInstance(), test.getChronology());
232         assertEquals(TEST_TIME1, test.getMillis());
233     }
234
235     /**
236      * Test constructor (Object)
237      */

238     public void testConstructor_invalidObject() throws Throwable JavaDoc {
239         try {
240             new DateTime(new Object JavaDoc());
241             fail();
242         } catch (IllegalArgumentException JavaDoc ex) {}
243     }
244
245     /**
246      * Test constructor (Object=null)
247      */

248     public void testConstructor_nullObject() throws Throwable JavaDoc {
249         DateTime test = new DateTime((Object JavaDoc) null);
250         assertEquals(ISOChronology.getInstance(), test.getChronology());
251         assertEquals(TEST_TIME_NOW, test.getMillis());
252     }
253
254     /**
255      * Test constructor (Object=null)
256      */

257     public void testConstructor_badconverterObject() throws Throwable JavaDoc {
258         try {
259             ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE);
260             DateTime test = new DateTime(new Integer JavaDoc(0));
261             assertEquals(ISOChronology.getInstance(), test.getChronology());
262             assertEquals(0L, test.getMillis());
263         } finally {
264             ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE);
265         }
266     }
267
268     public void testConstructor_ObjectString1() throws Throwable JavaDoc {
269         DateTime test = new DateTime("1972-12-03");
270         assertEquals(ISOChronology.getInstance(), test.getChronology());
271         assertEquals(1972, test.getYear());
272         assertEquals(12, test.getMonthOfYear());
273         assertEquals(3, test.getDayOfMonth());
274         assertEquals(0, test.getHourOfDay());
275         assertEquals(0, test.getMinuteOfHour());
276         assertEquals(0, test.getSecondOfMinute());
277         assertEquals(0, test.getMillisOfSecond());
278     }
279
280     public void testConstructor_ObjectString2() throws Throwable JavaDoc {
281         DateTime test = new DateTime("2006-06-03T+14:00");
282         assertEquals(ISOChronology.getInstance(), test.getChronology());
283         assertEquals(2006, test.getYear());
284         assertEquals(6, test.getMonthOfYear());
285         assertEquals(2, test.getDayOfMonth()); // timezone
286
assertEquals(11, test.getHourOfDay()); // test zone is +1, so shift back (14 - 1) hours from midnight
287
assertEquals(0, test.getMinuteOfHour());
288         assertEquals(0, test.getSecondOfMinute());
289         assertEquals(0, test.getMillisOfSecond());
290     }
291
292     public void testConstructor_ObjectString3() throws Throwable JavaDoc {
293         DateTime test = new DateTime("1972-12-03T10:20:30.040");
294         assertEquals(ISOChronology.getInstance(), test.getChronology());
295         assertEquals(1972, test.getYear());
296         assertEquals(12, test.getMonthOfYear());
297         assertEquals(3, test.getDayOfMonth());
298         assertEquals(10, test.getHourOfDay());
299         assertEquals(20, test.getMinuteOfHour());
300         assertEquals(30, test.getSecondOfMinute());
301         assertEquals(40, test.getMillisOfSecond());
302     }
303
304     public void testConstructor_ObjectString4() throws Throwable JavaDoc {
305         DateTime test = new DateTime("2006-06-03T10:20:30.040+14:00");
306         assertEquals(ISOChronology.getInstance(), test.getChronology());
307         assertEquals(2006, test.getYear());
308         assertEquals(6, test.getMonthOfYear());
309         assertEquals(2, test.getDayOfMonth()); // timezone
310
assertEquals(21, test.getHourOfDay()); // test zone is +1, so shift back (14 - 1) hours from 10am
311
assertEquals(20, test.getMinuteOfHour());
312         assertEquals(30, test.getSecondOfMinute());
313         assertEquals(40, test.getMillisOfSecond());
314     }
315
316     public void testConstructor_ObjectString5() throws Throwable JavaDoc {
317         DateTime test = new DateTime("T10:20:30.040");
318         assertEquals(ISOChronology.getInstance(), test.getChronology());
319         assertEquals(1970, test.getYear());
320         assertEquals(1, test.getMonthOfYear());
321         assertEquals(1, test.getDayOfMonth());
322         assertEquals(10, test.getHourOfDay());
323         assertEquals(20, test.getMinuteOfHour());
324         assertEquals(30, test.getSecondOfMinute());
325         assertEquals(40, test.getMillisOfSecond());
326     }
327
328     public void testConstructor_ObjectString6() throws Throwable JavaDoc {
329         DateTime test = new DateTime("T10:20:30.040+14:00");
330         assertEquals(ISOChronology.getInstance(), test.getChronology());
331         assertEquals(1969, test.getYear()); // timezone
332
assertEquals(12, test.getMonthOfYear()); // timezone
333
assertEquals(31, test.getDayOfMonth()); // timezone
334
assertEquals(21, test.getHourOfDay()); // test zone is +1, so shift back (14 - 1) hours from 10am
335
assertEquals(20, test.getMinuteOfHour());
336         assertEquals(30, test.getSecondOfMinute());
337         assertEquals(40, test.getMillisOfSecond());
338     }
339
340     public void testConstructor_ObjectString7() throws Throwable JavaDoc {
341         DateTime test = new DateTime("10");
342         assertEquals(ISOChronology.getInstance(), test.getChronology());
343         assertEquals(10, test.getYear());
344         assertEquals(1, test.getMonthOfYear());
345         assertEquals(1, test.getDayOfMonth());
346         assertEquals(0, test.getHourOfDay());
347         assertEquals(0, test.getMinuteOfHour());
348         assertEquals(0, test.getSecondOfMinute());
349         assertEquals(0, test.getMillisOfSecond());
350     }
351
352     public void testConstructor_ObjectStringEx1() throws Throwable JavaDoc {
353         try {
354             new DateTime("10:20:30.040");
355             fail();
356         } catch (IllegalArgumentException JavaDoc ex) {
357             // expected
358
}
359     }
360
361     public void testConstructor_ObjectStringEx2() throws Throwable JavaDoc {
362         try {
363             new DateTime("10:20:30.040+14:00");
364             fail();
365         } catch (IllegalArgumentException JavaDoc ex) {
366             // expected
367
}
368     }
369
370     //-----------------------------------------------------------------------
371
/**
372      * Test constructor (Object, DateTimeZone)
373      */

374     public void testConstructor_Object_DateTimeZone() throws Throwable JavaDoc {
375         Date JavaDoc date = new Date JavaDoc(TEST_TIME1);
376         DateTime test = new DateTime(date, PARIS);
377         assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
378         assertEquals(TEST_TIME1, test.getMillis());
379     }
380
381     /**
382      * Test constructor (Object, DateTimeZone)
383      */

384     public void testConstructor_invalidObject_DateTimeZone() throws Throwable JavaDoc {
385         try {
386             new DateTime(new Object JavaDoc(), PARIS);
387             fail();
388         } catch (IllegalArgumentException JavaDoc ex) {}
389     }
390
391     /**
392      * Test constructor (Object=null, DateTimeZone)
393      */

394     public void testConstructor_nullObject_DateTimeZone() throws Throwable JavaDoc {
395         DateTime test = new DateTime((Object JavaDoc) null, PARIS);
396         assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
397         assertEquals(TEST_TIME_NOW, test.getMillis());
398     }
399
400     /**
401      * Test constructor (Object, DateTimeZone=null)
402      */

403     public void testConstructor_Object_nullDateTimeZone() throws Throwable JavaDoc {
404         Date JavaDoc date = new Date JavaDoc(TEST_TIME1);
405         DateTime test = new DateTime(date, (DateTimeZone) null);
406         assertEquals(ISOChronology.getInstance(), test.getChronology());
407         assertEquals(TEST_TIME1, test.getMillis());
408     }
409
410     /**
411      * Test constructor (Object=null, DateTimeZone=null)
412      */

413     public void testConstructor_nullObject_nullDateTimeZone() throws Throwable JavaDoc {
414         DateTime test = new DateTime((Object JavaDoc) null, (DateTimeZone) null);
415         assertEquals(ISOChronology.getInstance(), test.getChronology());
416         assertEquals(TEST_TIME_NOW, test.getMillis());
417     }
418
419     /**
420      * Test constructor (Object, DateTimeZone)
421      */

422     public void testConstructor_badconverterObject_DateTimeZone() throws Throwable JavaDoc {
423         try {
424             ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE);
425             DateTime test = new DateTime(new Integer JavaDoc(0), GregorianChronology.getInstance());
426             assertEquals(ISOChronology.getInstance(), test.getChronology());
427             assertEquals(0L, test.getMillis());
428         } finally {
429             ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE);
430         }
431     }
432
433     /**
434      * Test constructor (Object, Chronology)
435      */

436     public void testConstructor_Object_Chronology() throws Throwable JavaDoc {
437         Date JavaDoc date = new Date JavaDoc(TEST_TIME1);
438         DateTime test = new DateTime(date, GregorianChronology.getInstance());
439         assertEquals(GregorianChronology.getInstance(), test.getChronology());
440         assertEquals(TEST_TIME1, test.getMillis());
441     }
442
443     /**
444      * Test constructor (Object, Chronology)
445      */

446     public void testConstructor_invalidObject_Chronology() throws Throwable JavaDoc {
447         try {
448             new DateTime(new Object JavaDoc(), GregorianChronology.getInstance());
449             fail();
450         } catch (IllegalArgumentException JavaDoc ex) {}
451     }
452
453     /**
454      * Test constructor (Object=null, Chronology)
455      */

456     public void testConstructor_nullObject_Chronology() throws Throwable JavaDoc {
457         DateTime test = new DateTime((Object JavaDoc) null, GregorianChronology.getInstance());
458         assertEquals(GregorianChronology.getInstance(), test.getChronology());
459         assertEquals(TEST_TIME_NOW, test.getMillis());
460     }
461
462     /**
463      * Test constructor (Object, Chronology=null)
464      */

465     public void testConstructor_Object_nullChronology() throws Throwable JavaDoc {
466         Date JavaDoc date = new Date JavaDoc(TEST_TIME1);
467         DateTime test = new DateTime(date, (Chronology) null);
468         assertEquals(ISOChronology.getInstance(), test.getChronology());
469         assertEquals(TEST_TIME1, test.getMillis());
470     }
471
472     /**
473      * Test constructor (Object=null, Chronology=null)
474      */

475     public void testConstructor_nullObject_nullChronology() throws Throwable JavaDoc {
476         DateTime test = new DateTime((Object JavaDoc) null, (Chronology) null);
477         assertEquals(ISOChronology.getInstance(), test.getChronology());
478         assertEquals(TEST_TIME_NOW, test.getMillis());
479     }
480
481     /**
482      * Test constructor (Object, Chronology)
483      */

484     public void testConstructor_badconverterObject_Chronology() throws Throwable JavaDoc {
485         try {
486             ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE);
487             DateTime test = new DateTime(new Integer JavaDoc(0), GregorianChronology.getInstance());
488             assertEquals(ISOChronology.getInstance(), test.getChronology());
489             assertEquals(0L, test.getMillis());
490         } finally {
491             ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE);
492         }
493     }
494
495     //-----------------------------------------------------------------------
496
/**
497      * Test constructor (int, int, int)
498      */

499     public void testConstructor_int_int_int_int_int_int_int() throws Throwable JavaDoc {
500         DateTime test = new DateTime(2002, 6, 9, 1, 0, 0, 0); // +01:00
501
assertEquals(ISOChronology.getInstance(), test.getChronology());
502         assertEquals(LONDON, test.getZone());
503         assertEquals(TEST_TIME_NOW, test.getMillis());
504         try {
505             new DateTime(Integer.MIN_VALUE, 6, 9, 0, 0, 0, 0);
506             fail();
507         } catch (IllegalArgumentException JavaDoc ex) {}
508         try {
509             new DateTime(Integer.MAX_VALUE, 6, 9, 0, 0, 0, 0);
510             fail();
511         } catch (IllegalArgumentException JavaDoc ex) {}
512         try {
513             new DateTime(2002, 0, 9, 0, 0, 0, 0);
514             fail();
515         } catch (IllegalArgumentException JavaDoc ex) {}
516         try {
517             new DateTime(2002, 13, 9, 0, 0, 0, 0);
518             fail();
519         } catch (IllegalArgumentException JavaDoc ex) {}
520         try {
521             new DateTime(2002, 6, 0, 0, 0, 0, 0);
522             fail();
523         } catch (IllegalArgumentException JavaDoc ex) {}
524         try {
525             new DateTime(2002, 6, 31, 0, 0, 0, 0);
526             fail();
527         } catch (IllegalArgumentException JavaDoc ex) {}
528         new DateTime(2002, 7, 31, 0, 0, 0, 0);
529         try {
530             new DateTime(2002, 7, 32, 0, 0, 0, 0);
531             fail();
532         } catch (IllegalArgumentException JavaDoc ex) {}
533     }
534
535     /**
536      * Test constructor (int, int, int, DateTimeZone)
537      */

538     public void testConstructor_int_int_int_int_int_int_int_DateTimeZone() throws Throwable JavaDoc {
539         DateTime test = new DateTime(2002, 6, 9, 2, 0, 0, 0, PARIS); // +02:00
540
assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
541         assertEquals(TEST_TIME_NOW, test.getMillis());
542         try {
543             new DateTime(Integer.MIN_VALUE, 6, 9, 0, 0, 0, 0, PARIS);
544             fail();
545         } catch (IllegalArgumentException JavaDoc ex) {}
546         try {
547             new DateTime(Integer.MAX_VALUE, 6, 9, 0, 0, 0, 0, PARIS);
548             fail();
549         } catch (IllegalArgumentException JavaDoc ex) {}
550         try {
551             new DateTime(2002, 0, 9, 0, 0, 0, 0, PARIS);
552             fail();
553         } catch (IllegalArgumentException JavaDoc ex) {}
554         try {
555             new DateTime(2002, 13, 9, 0, 0, 0, 0, PARIS);
556             fail();
557         } catch (IllegalArgumentException JavaDoc ex) {}
558         try {
559             new DateTime(2002, 6, 0, 0, 0, 0, 0, PARIS);
560             fail();
561         } catch (IllegalArgumentException JavaDoc ex) {}
562         try {
563             new DateTime(2002, 6, 31, 0, 0, 0, 0, PARIS);
564             fail();
565         } catch (IllegalArgumentException JavaDoc ex) {}
566         new DateTime(2002, 7, 31, 0, 0, 0, 0, PARIS);
567         try {
568             new DateTime(2002, 7, 32, 0, 0, 0, 0, PARIS);
569             fail();
570         } catch (IllegalArgumentException JavaDoc ex) {}
571     }
572
573     /**
574      * Test constructor (int, int, int, DateTimeZone=null)
575      */

576     public void testConstructor_int_int_int_int_int_int_int_nullDateTimeZone() throws Throwable JavaDoc {
577         DateTime test = new DateTime(2002, 6, 9, 1, 0, 0, 0, (DateTimeZone) null); // +01:00
578
assertEquals(ISOChronology.getInstance(), test.getChronology());
579         assertEquals(TEST_TIME_NOW, test.getMillis());
580     }
581
582     /**
583      * Test constructor (int, int, int, Chronology)
584      */

585     public void testConstructor_int_int_int_int_int_int_int_Chronology() throws Throwable JavaDoc {
586         DateTime test = new DateTime(2002, 6, 9, 1, 0, 0, 0, GregorianChronology.getInstance()); // +01:00
587
assertEquals(GregorianChronology.getInstance(), test.getChronology());
588         assertEquals(TEST_TIME_NOW, test.getMillis());
589         try {
590             new DateTime(Integer.MIN_VALUE, 6, 9, 0, 0, 0, 0, GregorianChronology.getInstance());
591             fail();
592         } catch (IllegalArgumentException JavaDoc ex) {}
593         try {
594             new DateTime(Integer.MAX_VALUE, 6, 9, 0, 0, 0, 0, GregorianChronology.getInstance());
595             fail();
596         } catch (IllegalArgumentException JavaDoc ex) {}
597         try {
598             new DateTime(2002, 0, 9, 0, 0, 0, 0, GregorianChronology.getInstance());
599             fail();
600         } catch (IllegalArgumentException JavaDoc ex) {}
601         try {
602             new DateTime(2002, 13, 9, 0, 0, 0, 0, GregorianChronology.getInstance());
603             fail();
604         } catch (IllegalArgumentException JavaDoc ex) {}
605         try {
606             new DateTime(2002, 6, 0, 0, 0, 0, 0, GregorianChronology.getInstance());
607             fail();
608         } catch (IllegalArgumentException JavaDoc ex) {}
609         try {
610             new DateTime(2002, 6, 31, 0, 0, 0, 0, GregorianChronology.getInstance());
611             fail();
612         } catch (IllegalArgumentException JavaDoc ex) {}
613         new DateTime(2002, 7, 31, 0, 0, 0, 0, GregorianChronology.getInstance());
614         try {
615             new DateTime(2002, 7, 32, 0, 0, 0, 0, GregorianChronology.getInstance());
616             fail();
617         } catch (IllegalArgumentException JavaDoc ex) {}
618     }
619
620     /**
621      * Test constructor (int, int, int, Chronology=null)
622      */

623     public void testConstructor_int_int_int_int_int_int_int_nullChronology() throws Throwable JavaDoc {
624         DateTime test = new DateTime(2002, 6, 9, 1, 0, 0, 0, (Chronology) null); // +01:00
625
assertEquals(ISOChronology.getInstance(), test.getChronology());
626         assertEquals(TEST_TIME_NOW, test.getMillis());
627     }
628
629 }
630
Popular Tags