001 /* 002 * Copyright 2001-2005 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 030 /** 031 * This class is a Junit unit test for DateMidnight. 032 * 033 * @author Stephen Colebourne 034 */ 035 public class TestDateMidnight_Constructors extends TestCase { 036 // Test in 2002/03 as time zones are more well known 037 // (before the late 90's they were all over the place) 038 039 private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris"); 040 private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London"); 041 042 long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 043 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 044 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 045 366 + 365; 046 long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 047 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 048 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 049 366 + 365 + 365; 050 051 // 2002-06-09 052 private long TEST_TIME_NOW_UTC = 053 (y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY; 054 private long TEST_TIME_NOW_LONDON = 055 TEST_TIME_NOW_UTC - DateTimeConstants.MILLIS_PER_HOUR; 056 private long TEST_TIME_NOW_PARIS = 057 TEST_TIME_NOW_UTC - 2*DateTimeConstants.MILLIS_PER_HOUR; 058 059 // 2002-04-05 060 private long TEST_TIME1_UTC = 061 (y2002days + 31L + 28L + 31L + 5L -1L) * DateTimeConstants.MILLIS_PER_DAY 062 + 12L * DateTimeConstants.MILLIS_PER_HOUR 063 + 24L * DateTimeConstants.MILLIS_PER_MINUTE; 064 private long TEST_TIME1_LONDON = 065 (y2002days + 31L + 28L + 31L + 5L -1L) * DateTimeConstants.MILLIS_PER_DAY 066 - DateTimeConstants.MILLIS_PER_HOUR; 067 private long TEST_TIME1_PARIS = 068 (y2002days + 31L + 28L + 31L + 5L -1L) * DateTimeConstants.MILLIS_PER_DAY 069 - 2*DateTimeConstants.MILLIS_PER_HOUR; 070 071 // 2003-05-06 072 private long TEST_TIME2_UTC = 073 (y2003days + 31L + 28L + 31L + 30L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY 074 + 14L * DateTimeConstants.MILLIS_PER_HOUR 075 + 28L * DateTimeConstants.MILLIS_PER_MINUTE; 076 private long TEST_TIME2_LONDON = 077 (y2003days + 31L + 28L + 31L + 30L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY 078 - DateTimeConstants.MILLIS_PER_HOUR; 079 private long TEST_TIME2_PARIS = 080 (y2003days + 31L + 28L + 31L + 30L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY 081 - 2*DateTimeConstants.MILLIS_PER_HOUR; 082 083 private DateTimeZone zone = null; 084 private Locale locale = null; 085 086 public static void main(String[] args) { 087 junit.textui.TestRunner.run(suite()); 088 } 089 090 public static TestSuite suite() { 091 return new TestSuite(TestDateMidnight_Constructors.class); 092 } 093 094 public TestDateMidnight_Constructors(String name) { 095 super(name); 096 } 097 098 protected void setUp() throws Exception { 099 DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW_UTC); 100 zone = DateTimeZone.getDefault(); 101 locale = Locale.getDefault(); 102 DateTimeZone.setDefault(LONDON); 103 Locale.setDefault(Locale.UK); 104 } 105 106 protected void tearDown() throws Exception { 107 DateTimeUtils.setCurrentMillisSystem(); 108 DateTimeZone.setDefault(zone); 109 Locale.setDefault(locale); 110 zone = null; 111 } 112 113 //----------------------------------------------------------------------- 114 public void testTest() { 115 assertEquals("2002-06-09T00:00:00.000Z", new Instant(TEST_TIME_NOW_UTC).toString()); 116 assertEquals("2002-04-05T12:24:00.000Z", new Instant(TEST_TIME1_UTC).toString()); 117 assertEquals("2003-05-06T14:28:00.000Z", new Instant(TEST_TIME2_UTC).toString()); 118 } 119 120 //----------------------------------------------------------------------- 121 /** 122 * Test now () 123 */ 124 public void test_now() throws Throwable { 125 DateMidnight test = DateMidnight.now(); 126 assertEquals(ISOChronology.getInstance(), test.getChronology()); 127 assertEquals(TEST_TIME_NOW_LONDON, test.getMillis()); 128 assertEquals(2002, test.getYear()); 129 assertEquals(6, test.getMonthOfYear()); 130 assertEquals(9, test.getDayOfMonth()); 131 } 132 133 /** 134 * Test now (DateTimeZone) 135 */ 136 public void test_now_DateTimeZone() throws Throwable { 137 DateMidnight test = DateMidnight.now(PARIS); 138 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology()); 139 assertEquals(TEST_TIME_NOW_PARIS, test.getMillis()); 140 } 141 142 /** 143 * Test now (DateTimeZone=null) 144 */ 145 public void test_now_nullDateTimeZone() throws Throwable { 146 try { 147 DateMidnight.now((DateTimeZone) null); 148 fail(); 149 } catch (NullPointerException ex) {} 150 } 151 152 /** 153 * Test now (Chronology) 154 */ 155 public void test_now_Chronology() throws Throwable { 156 DateMidnight test = DateMidnight.now(GregorianChronology.getInstance()); 157 assertEquals(GregorianChronology.getInstance(), test.getChronology()); 158 assertEquals(TEST_TIME_NOW_LONDON, test.getMillis()); 159 } 160 161 /** 162 * Test now (Chronology=null) 163 */ 164 public void test_now_nullChronology() throws Throwable { 165 try { 166 DateMidnight.now((Chronology) null); 167 fail(); 168 } catch (NullPointerException ex) {} 169 } 170 171 //----------------------------------------------------------------------- 172 public void testParse_noFormatter() throws Throwable { 173 assertEquals(new DateMidnight(2010, 6, 30, ISOChronology.getInstance(LONDON)), DateMidnight.parse("2010-06-30")); 174 assertEquals(new DateMidnight(2010, 1, 2, ISOChronology.getInstance(LONDON)), DateMidnight.parse("2010-002")); 175 } 176 177 public void testParse_formatter() throws Throwable { 178 assertEquals(new DateMidnight(2010, 6, 30, ISOChronology.getInstance(LONDON)), DateMidnight.parse("2010--30 06", DateTimeFormat.forPattern("yyyy--dd MM"))); 179 } 180 181 //----------------------------------------------------------------------- 182 /** 183 * Test constructor () 184 */ 185 public void testConstructor() throws Throwable { 186 DateMidnight test = new DateMidnight(); 187 assertEquals(ISOChronology.getInstance(), test.getChronology()); 188 assertEquals(TEST_TIME_NOW_LONDON, test.getMillis()); 189 assertEquals(2002, test.getYear()); 190 assertEquals(6, test.getMonthOfYear()); 191 assertEquals(9, test.getDayOfMonth()); 192 } 193 194 /** 195 * Test constructor (DateTimeZone) 196 */ 197 public void testConstructor_DateTimeZone() throws Throwable { 198 DateMidnight test = new DateMidnight(PARIS); 199 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology()); 200 assertEquals(TEST_TIME_NOW_PARIS, test.getMillis()); 201 } 202 203 /** 204 * Test constructor (DateTimeZone=null) 205 */ 206 public void testConstructor_nullDateTimeZone() throws Throwable { 207 DateMidnight test = new DateMidnight((DateTimeZone) null); 208 assertEquals(ISOChronology.getInstance(), test.getChronology()); 209 assertEquals(TEST_TIME_NOW_LONDON, test.getMillis()); 210 } 211 212 /** 213 * Test constructor (Chronology) 214 */ 215 public void testConstructor_Chronology() throws Throwable { 216 DateMidnight test = new DateMidnight(GregorianChronology.getInstance()); 217 assertEquals(GregorianChronology.getInstance(), test.getChronology()); 218 assertEquals(TEST_TIME_NOW_LONDON, test.getMillis()); 219 } 220 221 /** 222 * Test constructor (Chronology=null) 223 */ 224 public void testConstructor_nullChronology() throws Throwable { 225 DateMidnight test = new DateMidnight((Chronology) null); 226 assertEquals(ISOChronology.getInstance(), test.getChronology()); 227 assertEquals(TEST_TIME_NOW_LONDON, test.getMillis()); 228 } 229 230 //----------------------------------------------------------------------- 231 /** 232 * Test constructor (long) 233 */ 234 public void testConstructor_long1() throws Throwable { 235 DateMidnight test = new DateMidnight(TEST_TIME1_UTC); 236 assertEquals(ISOChronology.getInstance(), test.getChronology()); 237 assertEquals(TEST_TIME1_LONDON, test.getMillis()); 238 } 239 240 /** 241 * Test constructor (long) 242 */ 243 public void testConstructor_long2() throws Throwable { 244 DateMidnight test = new DateMidnight(TEST_TIME2_UTC); 245 assertEquals(ISOChronology.getInstance(), test.getChronology()); 246 assertEquals(TEST_TIME2_LONDON, test.getMillis()); 247 } 248 249 /** 250 * Test constructor (long, DateTimeZone) 251 */ 252 public void testConstructor_long1_DateTimeZone() throws Throwable { 253 DateMidnight test = new DateMidnight(TEST_TIME1_UTC, PARIS); 254 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology()); 255 assertEquals(TEST_TIME1_PARIS, test.getMillis()); 256 } 257 258 /** 259 * Test constructor (long, DateTimeZone) 260 */ 261 public void testConstructor_long2_DateTimeZone() throws Throwable { 262 DateMidnight test = new DateMidnight(TEST_TIME2_UTC, PARIS); 263 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology()); 264 assertEquals(TEST_TIME2_PARIS, test.getMillis()); 265 } 266 267 /** 268 * Test constructor (long, DateTimeZone=null) 269 */ 270 public void testConstructor_long_nullDateTimeZone() throws Throwable { 271 DateMidnight test = new DateMidnight(TEST_TIME1_UTC, (DateTimeZone) null); 272 assertEquals(ISOChronology.getInstance(), test.getChronology()); 273 assertEquals(TEST_TIME1_LONDON, test.getMillis()); 274 } 275 276 /** 277 * Test constructor (long, Chronology) 278 */ 279 public void testConstructor_long1_Chronology() throws Throwable { 280 DateMidnight test = new DateMidnight(TEST_TIME1_UTC, GregorianChronology.getInstance()); 281 assertEquals(GregorianChronology.getInstance(), test.getChronology()); 282 assertEquals(TEST_TIME1_LONDON, test.getMillis()); 283 } 284 285 /** 286 * Test constructor (long, Chronology) 287 */ 288 public void testConstructor_long2_Chronology() throws Throwable { 289 DateMidnight test = new DateMidnight(TEST_TIME2_UTC, GregorianChronology.getInstance()); 290 assertEquals(GregorianChronology.getInstance(), test.getChronology()); 291 assertEquals(TEST_TIME2_LONDON, test.getMillis()); 292 } 293 294 /** 295 * Test constructor (long, Chronology=null) 296 */ 297 public void testConstructor_long_nullChronology() throws Throwable { 298 DateMidnight test = new DateMidnight(TEST_TIME1_UTC, (Chronology) null); 299 assertEquals(ISOChronology.getInstance(), test.getChronology()); 300 assertEquals(TEST_TIME1_LONDON, test.getMillis()); 301 } 302 303 //----------------------------------------------------------------------- 304 /** 305 * Test constructor (Object) 306 */ 307 public void testConstructor_Object() throws Throwable { 308 Date date = new Date(TEST_TIME1_UTC); 309 DateMidnight test = new DateMidnight(date); 310 assertEquals(ISOChronology.getInstance(), test.getChronology()); 311 assertEquals(TEST_TIME1_LONDON, test.getMillis()); 312 } 313 314 /** 315 * Test constructor (Object) 316 */ 317 public void testConstructor_invalidObject() throws Throwable { 318 try { 319 new DateMidnight(new Object()); 320 fail(); 321 } catch (IllegalArgumentException ex) {} 322 } 323 324 /** 325 * Test constructor (Object=null) 326 */ 327 public void testConstructor_nullObject() throws Throwable { 328 DateMidnight test = new DateMidnight((Object) null); 329 assertEquals(ISOChronology.getInstance(), test.getChronology()); 330 assertEquals(TEST_TIME_NOW_LONDON, test.getMillis()); 331 } 332 333 /** 334 * Test constructor (Object=null) 335 */ 336 public void testConstructor_badconverterObject() throws Throwable { 337 try { 338 ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE); 339 DateMidnight test = new DateMidnight(new Integer(0)); 340 assertEquals(ISOChronology.getInstance(), test.getChronology()); 341 assertEquals(0L - DateTimeConstants.MILLIS_PER_HOUR, test.getMillis()); 342 } finally { 343 ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE); 344 } 345 } 346 347 /** 348 * Test constructor (Object, DateTimeZone) 349 */ 350 public void testConstructor_Object_DateTimeZone() throws Throwable { 351 Date date = new Date(TEST_TIME1_UTC); 352 DateMidnight test = new DateMidnight(date, PARIS); 353 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology()); 354 assertEquals(TEST_TIME1_PARIS, test.getMillis()); 355 } 356 357 /** 358 * Test constructor (Object, DateTimeZone) 359 */ 360 public void testConstructor_invalidObject_DateTimeZone() throws Throwable { 361 try { 362 new DateMidnight(new Object(), PARIS); 363 fail(); 364 } catch (IllegalArgumentException ex) {} 365 } 366 367 /** 368 * Test constructor (Object=null, DateTimeZone) 369 */ 370 public void testConstructor_nullObject_DateTimeZone() throws Throwable { 371 DateMidnight test = new DateMidnight((Object) null, PARIS); 372 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology()); 373 assertEquals(TEST_TIME_NOW_PARIS, test.getMillis()); 374 } 375 376 /** 377 * Test constructor (Object, DateTimeZone=null) 378 */ 379 public void testConstructor_Object_nullDateTimeZone() throws Throwable { 380 Date date = new Date(TEST_TIME1_UTC); 381 DateMidnight test = new DateMidnight(date, (DateTimeZone) null); 382 assertEquals(ISOChronology.getInstance(), test.getChronology()); 383 assertEquals(TEST_TIME1_LONDON, test.getMillis()); 384 } 385 386 /** 387 * Test constructor (Object=null, DateTimeZone=null) 388 */ 389 public void testConstructor_nullObject_nullDateTimeZone() throws Throwable { 390 DateMidnight test = new DateMidnight((Object) null, (DateTimeZone) null); 391 assertEquals(ISOChronology.getInstance(), test.getChronology()); 392 assertEquals(TEST_TIME_NOW_LONDON, test.getMillis()); 393 } 394 395 /** 396 * Test constructor (Object, DateTimeZone) 397 */ 398 public void testConstructor_badconverterObject_DateTimeZone() throws Throwable { 399 try { 400 ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE); 401 DateMidnight test = new DateMidnight(new Integer(0), GregorianChronology.getInstance()); 402 assertEquals(ISOChronology.getInstance(), test.getChronology()); 403 assertEquals(0L - DateTimeConstants.MILLIS_PER_HOUR, test.getMillis()); 404 } finally { 405 ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE); 406 } 407 } 408 409 /** 410 * Test constructor (Object, Chronology) 411 */ 412 public void testConstructor_Object_Chronology() throws Throwable { 413 Date date = new Date(TEST_TIME1_UTC); 414 DateMidnight test = new DateMidnight(date, GregorianChronology.getInstance()); 415 assertEquals(GregorianChronology.getInstance(), test.getChronology()); 416 assertEquals(TEST_TIME1_LONDON, test.getMillis()); 417 } 418 419 /** 420 * Test constructor (Object, Chronology) 421 */ 422 public void testConstructor_invalidObject_Chronology() throws Throwable { 423 try { 424 new DateMidnight(new Object(), GregorianChronology.getInstance()); 425 fail(); 426 } catch (IllegalArgumentException ex) {} 427 } 428 429 /** 430 * Test constructor (Object=null, Chronology) 431 */ 432 public void testConstructor_nullObject_Chronology() throws Throwable { 433 DateMidnight test = new DateMidnight((Object) null, GregorianChronology.getInstance()); 434 assertEquals(GregorianChronology.getInstance(), test.getChronology()); 435 assertEquals(TEST_TIME_NOW_LONDON, test.getMillis()); 436 } 437 438 /** 439 * Test constructor (Object, Chronology=null) 440 */ 441 public void testConstructor_Object_nullChronology() throws Throwable { 442 Date date = new Date(TEST_TIME1_UTC); 443 DateMidnight test = new DateMidnight(date, (Chronology) null); 444 assertEquals(ISOChronology.getInstance(), test.getChronology()); 445 assertEquals(TEST_TIME1_LONDON, test.getMillis()); 446 } 447 448 /** 449 * Test constructor (Object=null, Chronology=null) 450 */ 451 public void testConstructor_nullObject_nullChronology() throws Throwable { 452 DateMidnight test = new DateMidnight((Object) null, (Chronology) null); 453 assertEquals(ISOChronology.getInstance(), test.getChronology()); 454 assertEquals(TEST_TIME_NOW_LONDON, test.getMillis()); 455 } 456 457 /** 458 * Test constructor (Object, Chronology) 459 */ 460 public void testConstructor_badconverterObject_Chronology() throws Throwable { 461 try { 462 ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE); 463 DateMidnight test = new DateMidnight(new Integer(0), GregorianChronology.getInstance()); 464 assertEquals(ISOChronology.getInstance(), test.getChronology()); 465 assertEquals(0L - DateTimeConstants.MILLIS_PER_HOUR, test.getMillis()); 466 } finally { 467 ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE); 468 } 469 } 470 471 //----------------------------------------------------------------------- 472 /** 473 * Test constructor (int, int, int) 474 */ 475 public void testConstructor_int_int_int() throws Throwable { 476 DateMidnight test = new DateMidnight(2002, 6, 9); 477 assertEquals(ISOChronology.getInstance(), test.getChronology()); 478 assertEquals(LONDON, test.getZone()); 479 assertEquals(TEST_TIME_NOW_LONDON, test.getMillis()); 480 assertEquals(2002, test.getYear()); 481 assertEquals(6, test.getMonthOfYear()); 482 assertEquals(9, test.getDayOfMonth()); 483 try { 484 new DateMidnight(Integer.MIN_VALUE, 6, 9); 485 fail(); 486 } catch (IllegalArgumentException ex) {} 487 try { 488 new DateMidnight(Integer.MAX_VALUE, 6, 9); 489 fail(); 490 } catch (IllegalArgumentException ex) {} 491 try { 492 new DateMidnight(2002, 0, 9); 493 fail(); 494 } catch (IllegalArgumentException ex) {} 495 try { 496 new DateMidnight(2002, 13, 9); 497 fail(); 498 } catch (IllegalArgumentException ex) {} 499 try { 500 new DateMidnight(2002, 6, 0); 501 fail(); 502 } catch (IllegalArgumentException ex) {} 503 try { 504 new DateMidnight(2002, 6, 31); 505 fail(); 506 } catch (IllegalArgumentException ex) {} 507 new DateMidnight(2002, 7, 31); 508 try { 509 new DateMidnight(2002, 7, 32); 510 fail(); 511 } catch (IllegalArgumentException ex) {} 512 } 513 514 /** 515 * Test constructor (int, int, int, DateTimeZone) 516 */ 517 public void testConstructor_int_int_int_DateTimeZone() throws Throwable { 518 DateMidnight test = new DateMidnight(2002, 6, 9, PARIS); 519 assertEquals(ISOChronology.getInstance(PARIS), test.getChronology()); 520 assertEquals(TEST_TIME_NOW_PARIS, test.getMillis()); 521 assertEquals(2002, test.getYear()); 522 assertEquals(6, test.getMonthOfYear()); 523 assertEquals(9, test.getDayOfMonth()); 524 try { 525 new DateMidnight(Integer.MIN_VALUE, 6, 9, PARIS); 526 fail(); 527 } catch (IllegalArgumentException ex) {} 528 try { 529 new DateMidnight(Integer.MAX_VALUE, 6, 9, PARIS); 530 fail(); 531 } catch (IllegalArgumentException ex) {} 532 try { 533 new DateMidnight(2002, 0, 9, PARIS); 534 fail(); 535 } catch (IllegalArgumentException ex) {} 536 try { 537 new DateMidnight(2002, 13, 9, PARIS); 538 fail(); 539 } catch (IllegalArgumentException ex) {} 540 try { 541 new DateMidnight(2002, 6, 0, PARIS); 542 fail(); 543 } catch (IllegalArgumentException ex) {} 544 try { 545 new DateMidnight(2002, 6, 31, PARIS); 546 fail(); 547 } catch (IllegalArgumentException ex) {} 548 new DateMidnight(2002, 7, 31, PARIS); 549 try { 550 new DateMidnight(2002, 7, 32, PARIS); 551 fail(); 552 } catch (IllegalArgumentException ex) {} 553 } 554 555 /** 556 * Test constructor (int, int, int, DateTimeZone=null) 557 */ 558 public void testConstructor_int_int_int_nullDateTimeZone() throws Throwable { 559 DateMidnight test = new DateMidnight(2002, 6, 9, (DateTimeZone) null); 560 assertEquals(ISOChronology.getInstance(), test.getChronology()); 561 assertEquals(TEST_TIME_NOW_LONDON, test.getMillis()); 562 assertEquals(2002, test.getYear()); 563 assertEquals(6, test.getMonthOfYear()); 564 assertEquals(9, test.getDayOfMonth()); 565 } 566 567 /** 568 * Test constructor (int, int, int, Chronology) 569 */ 570 public void testConstructor_int_int_int_Chronology() throws Throwable { 571 DateMidnight test = new DateMidnight(2002, 6, 9, GregorianChronology.getInstance()); 572 assertEquals(GregorianChronology.getInstance(), test.getChronology()); 573 assertEquals(TEST_TIME_NOW_LONDON, test.getMillis()); 574 assertEquals(2002, test.getYear()); 575 assertEquals(6, test.getMonthOfYear()); 576 assertEquals(9, test.getDayOfMonth()); 577 try { 578 new DateMidnight(Integer.MIN_VALUE, 6, 9, GregorianChronology.getInstance()); 579 fail(); 580 } catch (IllegalArgumentException ex) {} 581 try { 582 new DateMidnight(Integer.MAX_VALUE, 6, 9, GregorianChronology.getInstance()); 583 fail(); 584 } catch (IllegalArgumentException ex) {} 585 try { 586 new DateMidnight(2002, 0, 9, GregorianChronology.getInstance()); 587 fail(); 588 } catch (IllegalArgumentException ex) {} 589 try { 590 new DateMidnight(2002, 13, 9, GregorianChronology.getInstance()); 591 fail(); 592 } catch (IllegalArgumentException ex) {} 593 try { 594 new DateMidnight(2002, 6, 0, GregorianChronology.getInstance()); 595 fail(); 596 } catch (IllegalArgumentException ex) {} 597 try { 598 new DateMidnight(2002, 6, 31, GregorianChronology.getInstance()); 599 fail(); 600 } catch (IllegalArgumentException ex) {} 601 new DateMidnight(2002, 7, 31, GregorianChronology.getInstance()); 602 try { 603 new DateMidnight(2002, 7, 32, GregorianChronology.getInstance()); 604 fail(); 605 } catch (IllegalArgumentException ex) {} 606 } 607 608 /** 609 * Test constructor (int, int, int, Chronology=null) 610 */ 611 public void testConstructor_int_int_int_nullChronology() throws Throwable { 612 DateMidnight test = new DateMidnight(2002, 6, 9, (Chronology) null); 613 assertEquals(ISOChronology.getInstance(), test.getChronology()); 614 assertEquals(TEST_TIME_NOW_LONDON, test.getMillis()); 615 assertEquals(2002, test.getYear()); 616 assertEquals(6, test.getMonthOfYear()); 617 assertEquals(9, test.getDayOfMonth()); 618 } 619 620 }