001 /*
002 * Copyright 2001-2010 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 import org.joda.time.format.DateTimeFormat;
029 import org.joda.time.format.DateTimeFormatter;
030
031 /**
032 * This class is a Junit unit test for DateTime.
033 *
034 * @author Stephen Colebourne
035 */
036 public class TestDateTime_Constructors extends TestCase {
037 // Test in 2002/03 as time zones are more well known
038 // (before the late 90's they were all over the place)
039
040 private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
041 private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
042
043 long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
044 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 +
045 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
046 366 + 365;
047 long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
048 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 +
049 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
050 366 + 365 + 365;
051
052 // 2002-06-09
053 private long TEST_TIME_NOW =
054 (y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY;
055
056 // 2002-04-05
057 private long TEST_TIME1 =
058 (y2002days + 31L + 28L + 31L + 5L -1L) * DateTimeConstants.MILLIS_PER_DAY
059 + 12L * DateTimeConstants.MILLIS_PER_HOUR
060 + 24L * DateTimeConstants.MILLIS_PER_MINUTE;
061
062 // 2003-05-06
063 private long TEST_TIME2 =
064 (y2003days + 31L + 28L + 31L + 30L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY
065 + 14L * DateTimeConstants.MILLIS_PER_HOUR
066 + 28L * DateTimeConstants.MILLIS_PER_MINUTE;
067
068 private DateTimeZone zone = null;
069 private Locale locale = null;
070
071 public static void main(String[] args) {
072 junit.textui.TestRunner.run(suite());
073 }
074
075 public static TestSuite suite() {
076 return new TestSuite(TestDateTime_Constructors.class);
077 }
078
079 public TestDateTime_Constructors(String name) {
080 super(name);
081 }
082
083 protected void setUp() throws Exception {
084 DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
085 zone = DateTimeZone.getDefault();
086 locale = Locale.getDefault();
087 DateTimeZone.setDefault(LONDON);
088 java.util.TimeZone.setDefault(LONDON.toTimeZone());
089 Locale.setDefault(Locale.UK);
090 }
091
092 protected void tearDown() throws Exception {
093 DateTimeUtils.setCurrentMillisSystem();
094 DateTimeZone.setDefault(zone);
095 java.util.TimeZone.setDefault(zone.toTimeZone());
096 Locale.setDefault(locale);
097 zone = null;
098 }
099
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 * Test now ()
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 * Test now (DateTimeZone)
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 * Test now (DateTimeZone=null)
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 * Test now (Chronology)
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 * Test now (Chronology=null)
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 * Test constructor ()
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 * Test constructor (DateTimeZone)
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 * Test constructor (DateTimeZone=null)
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 * Test constructor (Chronology)
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 * Test constructor (Chronology=null)
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 * Test constructor (long)
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 * Test constructor (long)
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 * Test constructor (long, DateTimeZone)
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 * Test constructor (long, DateTimeZone)
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 * Test constructor (long, DateTimeZone=null)
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 * Test constructor (long, Chronology)
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 * Test constructor (long, Chronology)
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 * Test constructor (long, Chronology=null)
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 * Test constructor (Object)
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 * Test constructor (Object)
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 * Test constructor (Object=null)
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 * Test constructor (Object=null)
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()); // timezone
347 assertEquals(11, test.getHourOfDay()); // test zone is +1, so shift back (14 - 1) hours from midnight
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()); // timezone
371 assertEquals(21, test.getHourOfDay()); // test zone is +1, so shift back (14 - 1) hours from 10am
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()); // timezone
393 assertEquals(12, test.getMonthOfYear()); // timezone
394 assertEquals(31, test.getDayOfMonth()); // timezone
395 assertEquals(21, test.getHourOfDay()); // test zone is +1, so shift back (14 - 1) hours from 10am
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 // expected
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 // expected
428 }
429 }
430
431 //-----------------------------------------------------------------------
432 /**
433 * Test constructor (Object, DateTimeZone)
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 * Test constructor (Object, DateTimeZone)
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 * Test constructor (Object=null, DateTimeZone)
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 * Test constructor (Object, DateTimeZone=null)
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 * Test constructor (Object=null, DateTimeZone=null)
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 * Test constructor (Object, DateTimeZone)
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 * Test constructor (Object, Chronology)
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 * Test constructor (Object, Chronology)
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 * Test constructor (Object=null, Chronology)
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 * Test constructor (Object, Chronology=null)
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 * Test constructor (Object=null, Chronology=null)
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 * Test constructor (Object, Chronology)
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 * Test constructor (int, int, int, int, int)
559 */
560 public void testConstructor_int_int_int_int_int() throws Throwable {
561 DateTime test = new DateTime(2002, 6, 9, 1, 0); // +01:00
562 assertEquals(ISOChronology.getInstance(), test.getChronology());
563 assertEquals(LONDON, test.getZone());
564 assertEquals(TEST_TIME_NOW, test.getMillis());
565 }
566
567 /**
568 * Test constructor (int, int, int, int, int, DateTimeZone)
569 */
570 public void testConstructor_int_int_int_int_int_DateTimeZone() throws Throwable {
571 DateTime test = new DateTime(2002, 6, 9, 2, 0, PARIS); // +02:00
572 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
573 assertEquals(TEST_TIME_NOW, test.getMillis());
574 }
575
576 /**
577 * Test constructor (int, int, int, int, int, DateTimeZone=null)
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); // +01:00
581 assertEquals(ISOChronology.getInstance(), test.getChronology());
582 assertEquals(TEST_TIME_NOW, test.getMillis());
583 }
584
585 /**
586 * Test constructor (int, int, int, int, int, Chronology)
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()); // +01:00
590 assertEquals(GregorianChronology.getInstance(), test.getChronology());
591 assertEquals(TEST_TIME_NOW, test.getMillis());
592 }
593
594 /**
595 * Test constructor (int, int, int, int, int, Chronology=null)
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); // +01:00
599 assertEquals(ISOChronology.getInstance(), test.getChronology());
600 assertEquals(TEST_TIME_NOW, test.getMillis());
601 }
602
603 //-----------------------------------------------------------------------
604 /**
605 * Test constructor (int, int, int, int, int, int)
606 */
607 public void testConstructor_int_int_int_int_int_int() throws Throwable {
608 DateTime test = new DateTime(2002, 6, 9, 1, 0, 0); // +01:00
609 assertEquals(ISOChronology.getInstance(), test.getChronology());
610 assertEquals(LONDON, test.getZone());
611 assertEquals(TEST_TIME_NOW, test.getMillis());
612 }
613
614 /**
615 * Test constructor (int, int, int, int, int, int, DateTimeZone)
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); // +02:00
619 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology());
620 assertEquals(TEST_TIME_NOW, test.getMillis());
621 }
622
623 /**
624 * Test constructor (int, int, int, int, int, int, DateTimeZone=null)
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); // +01:00
628 assertEquals(ISOChronology.getInstance(), test.getChronology());
629 assertEquals(TEST_TIME_NOW, test.getMillis());
630 }
631
632 /**
633 * Test constructor (int, int, int, int, int, int, Chronology)
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()); // +01:00
637 assertEquals(GregorianChronology.getInstance(), test.getChronology());
638 assertEquals(TEST_TIME_NOW, test.getMillis());
639 }
640
641 /**
642 * Test constructor (int, int, int, int, int, int, Chronology=null)
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); // +01:00
646 assertEquals(ISOChronology.getInstance(), test.getChronology());
647 assertEquals(TEST_TIME_NOW, test.getMillis());
648 }
649
650 //-----------------------------------------------------------------------
651 /**
652 * Test constructor (int, int, int)
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); // +01:00
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 * Test constructor (int, int, int, DateTimeZone)
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); // +02:00
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 * Test constructor (int, int, int, DateTimeZone=null)
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); // +01:00
733 assertEquals(ISOChronology.getInstance(), test.getChronology());
734 assertEquals(TEST_TIME_NOW, test.getMillis());
735 }
736
737 /**
738 * Test constructor (int, int, int, Chronology)
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()); // +01:00
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 * Test constructor (int, int, int, Chronology=null)
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); // +01:00
780 assertEquals(ISOChronology.getInstance(), test.getChronology());
781 assertEquals(TEST_TIME_NOW, test.getMillis());
782 }
783
784 }