1 /*
   2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * This file is available under and governed by the GNU General Public
  26  * License version 2 only, as published by the Free Software Foundation.
  27  * However, the following notice accompanied the original version of this
  28  * file:
  29  *
  30  * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos
  31  *
  32  * All rights reserved.
  33  *
  34  * Redistribution and use in source and binary forms, with or without
  35  * modification, are permitted provided that the following conditions are met:
  36  *
  37  *  * Redistributions of source code must retain the above copyright notice,
  38  *    this list of conditions and the following disclaimer.
  39  *
  40  *  * Redistributions in binary form must reproduce the above copyright notice,
  41  *    this list of conditions and the following disclaimer in the documentation
  42  *    and/or other materials provided with the distribution.
  43  *
  44  *  * Neither the name of JSR-310 nor the names of its contributors
  45  *    may be used to endorse or promote products derived from this software
  46  *    without specific prior written permission.
  47  *
  48  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  49  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  50  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  51  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  52  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  53  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  54  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  55  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  56  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  57  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59  */
  60 package tck.java.time;
  61 
  62 import static java.time.temporal.ChronoField.DAY_OF_MONTH;
  63 import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
  64 import static org.testng.Assert.assertEquals;
  65 import static org.testng.Assert.assertTrue;
  66 import static org.testng.Assert.fail;
  67 
  68 import java.io.ByteArrayOutputStream;
  69 import java.io.DataOutputStream;
  70 import java.io.IOException;
  71 import java.time.Clock;
  72 import java.time.DateTimeException;
  73 import java.time.Instant;
  74 import java.time.LocalDate;
  75 import java.time.LocalDateTime;
  76 import java.time.LocalTime;
  77 import java.time.Month;
  78 import java.time.MonthDay;
  79 import java.time.YearMonth;
  80 import java.time.ZoneId;
  81 import java.time.ZoneOffset;
  82 import java.time.chrono.IsoChronology;
  83 import java.time.format.DateTimeFormatter;
  84 import java.time.format.DateTimeParseException;
  85 import java.time.temporal.ChronoField;
  86 import java.time.temporal.JulianFields;
  87 import java.time.temporal.Queries;
  88 import java.time.temporal.TemporalAccessor;
  89 import java.time.temporal.TemporalField;
  90 import java.time.temporal.TemporalQuery;
  91 import java.util.ArrayList;
  92 import java.util.Arrays;
  93 import java.util.HashSet;
  94 import java.util.List;
  95 import java.util.Set;
  96 
  97 import org.testng.annotations.BeforeMethod;
  98 import org.testng.annotations.DataProvider;
  99 import org.testng.annotations.Test;
 100 
 101 /**
 102  * Test MonthDay.
 103  */
 104 @Test
 105 public class TCKMonthDay extends AbstractDateTimeTest {
 106 
 107     private MonthDay TEST_07_15;
 108 
 109     @BeforeMethod(groups={"tck","implementation"})
 110     public void setUp() {
 111         TEST_07_15 = MonthDay.of(7, 15);
 112     }
 113 
 114     //-----------------------------------------------------------------------
 115     @Override
 116     protected List<TemporalAccessor> samples() {
 117         TemporalAccessor[] array = {TEST_07_15, };
 118         return Arrays.asList(array);
 119     }
 120 
 121     @Override
 122     protected List<TemporalField> validFields() {
 123         TemporalField[] array = {
 124             DAY_OF_MONTH,
 125             MONTH_OF_YEAR,
 126         };
 127         return Arrays.asList(array);
 128     }
 129 
 130     @Override
 131     protected List<TemporalField> invalidFields() {
 132         List<TemporalField> list = new ArrayList<>(Arrays.<TemporalField>asList(ChronoField.values()));
 133         list.removeAll(validFields());
 134         list.add(JulianFields.JULIAN_DAY);
 135         list.add(JulianFields.MODIFIED_JULIAN_DAY);
 136         list.add(JulianFields.RATA_DIE);
 137         return list;
 138     }
 139 
 140     //-----------------------------------------------------------------------
 141     @Test
 142     public void test_serialization() throws ClassNotFoundException, IOException {
 143         assertSerializable(TEST_07_15);
 144     }
 145 
 146     @Test
 147     public void test_serialization_format() throws Exception {
 148         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 149         try (DataOutputStream dos = new DataOutputStream(baos) ) {
 150             dos.writeByte(13);       // java.time.temporal.Ser.MONTH_DAY_TYPE
 151             dos.writeByte(9);
 152             dos.writeByte(16);
 153         }
 154         byte[] bytes = baos.toByteArray();
 155         assertSerializedBySer(MonthDay.of(9, 16), bytes);
 156     }
 157 
 158     //-----------------------------------------------------------------------
 159     void check(MonthDay test, int m, int d) {
 160         assertEquals(test.getMonth().getValue(), m);
 161         assertEquals(test.getDayOfMonth(), d);
 162     }
 163 
 164     //-----------------------------------------------------------------------
 165     // now()
 166     //-----------------------------------------------------------------------
 167     @Test(groups={"tck"})
 168     public void now() {
 169         MonthDay expected = MonthDay.now(Clock.systemDefaultZone());
 170         MonthDay test = MonthDay.now();
 171         for (int i = 0; i < 100; i++) {
 172             if (expected.equals(test)) {
 173                 return;
 174             }
 175             expected = MonthDay.now(Clock.systemDefaultZone());
 176             test = MonthDay.now();
 177         }
 178         assertEquals(test, expected);
 179     }
 180 
 181     //-----------------------------------------------------------------------
 182     // now(ZoneId)
 183     //-----------------------------------------------------------------------
 184     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 185     public void now_ZoneId_nullZoneId() {
 186         MonthDay.now((ZoneId) null);
 187     }
 188 
 189     @Test(groups={"tck"})
 190     public void now_ZoneId() {
 191         ZoneId zone = ZoneId.of("UTC+01:02:03");
 192         MonthDay expected = MonthDay.now(Clock.system(zone));
 193         MonthDay test = MonthDay.now(zone);
 194         for (int i = 0; i < 100; i++) {
 195             if (expected.equals(test)) {
 196                 return;
 197             }
 198             expected = MonthDay.now(Clock.system(zone));
 199             test = MonthDay.now(zone);
 200         }
 201         assertEquals(test, expected);
 202     }
 203 
 204     //-----------------------------------------------------------------------
 205     // now(Clock)
 206     //-----------------------------------------------------------------------
 207     @Test(groups={"tck"})
 208     public void now_Clock() {
 209         Instant instant = LocalDateTime.of(2010, 12, 31, 0, 0).toInstant(ZoneOffset.UTC);
 210         Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 211         MonthDay test = MonthDay.now(clock);
 212         assertEquals(test.getMonth(), Month.DECEMBER);
 213         assertEquals(test.getDayOfMonth(), 31);
 214     }
 215 
 216     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 217     public void now_Clock_nullClock() {
 218         MonthDay.now((Clock) null);
 219     }
 220 
 221     //-----------------------------------------------------------------------
 222     @Test(groups={"tck"})
 223     public void factory_intMonth() {
 224         assertEquals(TEST_07_15, MonthDay.of(Month.JULY, 15));
 225     }
 226 
 227     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 228     public void test_factory_intMonth_dayTooLow() {
 229         MonthDay.of(Month.JANUARY, 0);
 230     }
 231 
 232     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 233     public void test_factory_intMonth_dayTooHigh() {
 234         MonthDay.of(Month.JANUARY, 32);
 235     }
 236 
 237     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 238     public void factory_intMonth_nullMonth() {
 239         MonthDay.of(null, 15);
 240     }
 241 
 242     //-----------------------------------------------------------------------
 243     @Test(groups={"tck"})
 244     public void factory_ints() {
 245         check(TEST_07_15, 7, 15);
 246     }
 247 
 248     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 249     public void test_factory_ints_dayTooLow() {
 250         MonthDay.of(1, 0);
 251     }
 252 
 253     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 254     public void test_factory_ints_dayTooHigh() {
 255         MonthDay.of(1, 32);
 256     }
 257 
 258 
 259     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 260     public void test_factory_ints_monthTooLow() {
 261         MonthDay.of(0, 1);
 262     }
 263 
 264     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 265     public void test_factory_ints_monthTooHigh() {
 266         MonthDay.of(13, 1);
 267     }
 268 
 269     //-----------------------------------------------------------------------
 270     @Test(groups={"tck"})
 271     public void test_factory_CalendricalObject() {
 272         assertEquals(MonthDay.from(LocalDate.of(2007, 7, 15)), TEST_07_15);
 273     }
 274 
 275     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 276     public void test_factory_CalendricalObject_invalid_noDerive() {
 277         MonthDay.from(LocalTime.of(12, 30));
 278     }
 279 
 280     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 281     public void test_factory_CalendricalObject_null() {
 282         MonthDay.from((TemporalAccessor) null);
 283     }
 284 
 285     //-----------------------------------------------------------------------
 286     // parse()
 287     //-----------------------------------------------------------------------
 288     @DataProvider(name="goodParseData")
 289     Object[][] provider_goodParseData() {
 290         return new Object[][] {
 291                 {"--01-01", MonthDay.of(1, 1)},
 292                 {"--01-31", MonthDay.of(1, 31)},
 293                 {"--02-01", MonthDay.of(2, 1)},
 294                 {"--02-29", MonthDay.of(2, 29)},
 295                 {"--03-01", MonthDay.of(3, 1)},
 296                 {"--03-31", MonthDay.of(3, 31)},
 297                 {"--04-01", MonthDay.of(4, 1)},
 298                 {"--04-30", MonthDay.of(4, 30)},
 299                 {"--05-01", MonthDay.of(5, 1)},
 300                 {"--05-31", MonthDay.of(5, 31)},
 301                 {"--06-01", MonthDay.of(6, 1)},
 302                 {"--06-30", MonthDay.of(6, 30)},
 303                 {"--07-01", MonthDay.of(7, 1)},
 304                 {"--07-31", MonthDay.of(7, 31)},
 305                 {"--08-01", MonthDay.of(8, 1)},
 306                 {"--08-31", MonthDay.of(8, 31)},
 307                 {"--09-01", MonthDay.of(9, 1)},
 308                 {"--09-30", MonthDay.of(9, 30)},
 309                 {"--10-01", MonthDay.of(10, 1)},
 310                 {"--10-31", MonthDay.of(10, 31)},
 311                 {"--11-01", MonthDay.of(11, 1)},
 312                 {"--11-30", MonthDay.of(11, 30)},
 313                 {"--12-01", MonthDay.of(12, 1)},
 314                 {"--12-31", MonthDay.of(12, 31)},
 315         };
 316     }
 317 
 318     @Test(dataProvider="goodParseData", groups={"tck"})
 319     public void factory_parse_success(String text, MonthDay expected) {
 320         MonthDay monthDay = MonthDay.parse(text);
 321         assertEquals(monthDay, expected);
 322     }
 323 
 324     //-----------------------------------------------------------------------
 325     @DataProvider(name="badParseData")
 326     Object[][] provider_badParseData() {
 327         return new Object[][] {
 328                 {"", 0},
 329                 {"-00", 0},
 330                 {"--FEB-23", 2},
 331                 {"--01-0", 5},
 332                 {"--01-3A", 5},
 333         };
 334     }
 335 
 336     @Test(dataProvider="badParseData", expectedExceptions=DateTimeParseException.class, groups={"tck"})
 337     public void factory_parse_fail(String text, int pos) {
 338         try {
 339             MonthDay.parse(text);
 340             fail(String.format("Parse should have failed for %s at position %d", text, pos));
 341         }
 342         catch (DateTimeParseException ex) {
 343             assertEquals(ex.getParsedString(), text);
 344             assertEquals(ex.getErrorIndex(), pos);
 345             throw ex;
 346         }
 347     }
 348 
 349     //-----------------------------------------------------------------------
 350     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 351     public void factory_parse_illegalValue_Day() {
 352         MonthDay.parse("--06-32");
 353     }
 354 
 355     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 356     public void factory_parse_invalidValue_Day() {
 357         MonthDay.parse("--06-31");
 358     }
 359 
 360     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 361     public void factory_parse_illegalValue_Month() {
 362         MonthDay.parse("--13-25");
 363     }
 364 
 365     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 366     public void factory_parse_nullText() {
 367         MonthDay.parse(null);
 368     }
 369 
 370     //-----------------------------------------------------------------------
 371     // parse(DateTimeFormatter)
 372     //-----------------------------------------------------------------------
 373     @Test(groups={"tck"})
 374     public void factory_parse_formatter() {
 375         DateTimeFormatter f = DateTimeFormatter.ofPattern("M d");
 376         MonthDay test = MonthDay.parse("12 3", f);
 377         assertEquals(test, MonthDay.of(12, 3));
 378     }
 379 
 380     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 381     public void factory_parse_formatter_nullText() {
 382         DateTimeFormatter f = DateTimeFormatter.ofPattern("M d");
 383         MonthDay.parse((String) null, f);
 384     }
 385 
 386     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 387     public void factory_parse_formatter_nullFormatter() {
 388         MonthDay.parse("ANY", null);
 389     }
 390 
 391     //-----------------------------------------------------------------------
 392     // get(TemporalField)
 393     //-----------------------------------------------------------------------
 394     @Test
 395     public void test_get_TemporalField() {
 396         assertEquals(TEST_07_15.get(ChronoField.DAY_OF_MONTH), 15);
 397         assertEquals(TEST_07_15.get(ChronoField.MONTH_OF_YEAR), 7);
 398     }
 399 
 400     @Test
 401     public void test_getLong_TemporalField() {
 402         assertEquals(TEST_07_15.getLong(ChronoField.DAY_OF_MONTH), 15);
 403         assertEquals(TEST_07_15.getLong(ChronoField.MONTH_OF_YEAR), 7);
 404     }
 405 
 406     //-----------------------------------------------------------------------
 407     // query(TemporalQuery)
 408     //-----------------------------------------------------------------------
 409     @DataProvider(name="query")
 410     Object[][] data_query() {
 411         return new Object[][] {
 412                 {TEST_07_15, Queries.chronology(), IsoChronology.INSTANCE},
 413                 {TEST_07_15, Queries.zoneId(), null},
 414                 {TEST_07_15, Queries.precision(), null},
 415                 {TEST_07_15, Queries.zone(), null},
 416                 {TEST_07_15, Queries.offset(), null},
 417                 {TEST_07_15, Queries.localDate(), null},
 418                 {TEST_07_15, Queries.localTime(), null},
 419         };
 420     }
 421 
 422     @Test(dataProvider="query")
 423     public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 424         assertEquals(temporal.query(query), expected);
 425     }
 426 
 427     @Test(dataProvider="query")
 428     public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 429         assertEquals(query.queryFrom(temporal), expected);
 430     }
 431 
 432     @Test(expectedExceptions=NullPointerException.class)
 433     public void test_query_null() {
 434         TEST_07_15.query(null);
 435     }
 436 
 437     //-----------------------------------------------------------------------
 438     // get*()
 439     //-----------------------------------------------------------------------
 440     @DataProvider(name="sampleDates")
 441     Object[][] provider_sampleDates() {
 442         return new Object[][] {
 443             {1, 1},
 444             {1, 31},
 445             {2, 1},
 446             {2, 28},
 447             {2, 29},
 448             {7, 4},
 449             {7, 5},
 450         };
 451     }
 452 
 453     @Test(dataProvider="sampleDates")
 454     public void test_get(int m, int d) {
 455         MonthDay a = MonthDay.of(m, d);
 456         assertEquals(a.getMonth(), Month.of(m));
 457         assertEquals(a.getMonthValue(), m);
 458         assertEquals(a.getDayOfMonth(), d);
 459     }
 460 
 461     //-----------------------------------------------------------------------
 462     // with(Month)
 463     //-----------------------------------------------------------------------
 464     @Test(groups={"tck"})
 465     public void test_with_Month() {
 466         assertEquals(MonthDay.of(6, 30).with(Month.JANUARY), MonthDay.of(1, 30));
 467     }
 468 
 469     @Test(groups={"tck"})
 470     public void test_with_Month_adjustToValid() {
 471         assertEquals(MonthDay.of(7, 31).with(Month.JUNE), MonthDay.of(6, 30));
 472     }
 473 
 474     @Test(groups={"tck"})
 475     public void test_with_Month_adjustToValidFeb() {
 476         assertEquals(MonthDay.of(7, 31).with(Month.FEBRUARY), MonthDay.of(2, 29));
 477     }
 478 
 479     @Test(groups={"tck"})
 480     public void test_with_Month_noChangeEqual() {
 481         MonthDay test = MonthDay.of(6, 30);
 482         assertEquals(test.with(Month.JUNE), test);
 483     }
 484 
 485     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 486     public void test_with_Month_null() {
 487         MonthDay.of(6, 30).with((Month) null);
 488     }
 489 
 490     //-----------------------------------------------------------------------
 491     // withMonth()
 492     //-----------------------------------------------------------------------
 493     @Test(groups={"tck"})
 494     public void test_withMonth() {
 495         assertEquals(MonthDay.of(6, 30).withMonth(1), MonthDay.of(1, 30));
 496     }
 497 
 498     @Test(groups={"tck"})
 499     public void test_withMonth_adjustToValid() {
 500         assertEquals(MonthDay.of(7, 31).withMonth(6), MonthDay.of(6, 30));
 501     }
 502 
 503     @Test(groups={"tck"})
 504     public void test_withMonth_adjustToValidFeb() {
 505         assertEquals(MonthDay.of(7, 31).withMonth(2), MonthDay.of(2, 29));
 506     }
 507 
 508     @Test(groups={"tck"})
 509     public void test_withMonth_int_noChangeEqual() {
 510         MonthDay test = MonthDay.of(6, 30);
 511         assertEquals(test.withMonth(6), test);
 512     }
 513 
 514     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 515     public void test_withMonth_tooLow() {
 516         MonthDay.of(6, 30).withMonth(0);
 517     }
 518 
 519     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 520     public void test_withMonth_tooHigh() {
 521         MonthDay.of(6, 30).withMonth(13);
 522     }
 523 
 524     //-----------------------------------------------------------------------
 525     // withDayOfMonth()
 526     //-----------------------------------------------------------------------
 527     @Test(groups={"tck"})
 528     public void test_withDayOfMonth() {
 529         assertEquals(MonthDay.of(6, 30).withDayOfMonth(1), MonthDay.of(6, 1));
 530     }
 531 
 532     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 533     public void test_withDayOfMonth_invalid() {
 534         MonthDay.of(6, 30).withDayOfMonth(31);
 535     }
 536 
 537     @Test(groups={"tck"})
 538     public void test_withDayOfMonth_adjustToValidFeb() {
 539         assertEquals(MonthDay.of(2, 1).withDayOfMonth(29), MonthDay.of(2, 29));
 540     }
 541 
 542     @Test(groups={"tck"})
 543     public void test_withDayOfMonth_noChangeEqual() {
 544         MonthDay test = MonthDay.of(6, 30);
 545         assertEquals(test.withDayOfMonth(30), test);
 546     }
 547 
 548     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 549     public void test_withDayOfMonth_tooLow() {
 550         MonthDay.of(6, 30).withDayOfMonth(0);
 551     }
 552 
 553     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 554     public void test_withDayOfMonth_tooHigh() {
 555         MonthDay.of(6, 30).withDayOfMonth(32);
 556     }
 557 
 558     //-----------------------------------------------------------------------
 559     // adjustInto()
 560     //-----------------------------------------------------------------------
 561     @Test(groups={"tck"})
 562     public void test_adjustDate() {
 563         MonthDay test = MonthDay.of(6, 30);
 564         LocalDate date = LocalDate.of(2007, 1, 1);
 565         assertEquals(test.adjustInto(date), LocalDate.of(2007, 6, 30));
 566     }
 567 
 568     @Test(groups={"tck"})
 569     public void test_adjustDate_resolve() {
 570         MonthDay test = MonthDay.of(2, 29);
 571         LocalDate date = LocalDate.of(2007, 6, 30);
 572         assertEquals(test.adjustInto(date), LocalDate.of(2007, 2, 28));
 573     }
 574 
 575     @Test(groups={"tck"})
 576     public void test_adjustDate_equal() {
 577         MonthDay test = MonthDay.of(6, 30);
 578         LocalDate date = LocalDate.of(2007, 6, 30);
 579         assertEquals(test.adjustInto(date), date);
 580     }
 581 
 582     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 583     public void test_adjustDate_null() {
 584         TEST_07_15.adjustInto((LocalDate) null);
 585     }
 586 
 587     //-----------------------------------------------------------------------
 588     // isValidYear(int)
 589     //-----------------------------------------------------------------------
 590     @Test(groups={"tck"})
 591     public void test_isValidYear_june() {
 592         MonthDay test = MonthDay.of(6, 30);
 593         assertEquals(test.isValidYear(2007), true);
 594     }
 595 
 596     @Test(groups={"tck"})
 597     public void test_isValidYear_febNonLeap() {
 598         MonthDay test = MonthDay.of(2, 29);
 599         assertEquals(test.isValidYear(2007), false);
 600     }
 601 
 602     @Test(groups={"tck"})
 603     public void test_isValidYear_febLeap() {
 604         MonthDay test = MonthDay.of(2, 29);
 605         assertEquals(test.isValidYear(2008), true);
 606     }
 607 
 608     //-----------------------------------------------------------------------
 609     // atYear(int)
 610     //-----------------------------------------------------------------------
 611     @Test(groups={"tck"})
 612     public void test_atYear_int() {
 613         MonthDay test = MonthDay.of(6, 30);
 614         assertEquals(test.atYear(2008), LocalDate.of(2008, 6, 30));
 615     }
 616 
 617     @Test(groups={"tck"})
 618     public void test_atYear_int_leapYearAdjust() {
 619         MonthDay test = MonthDay.of(2, 29);
 620         assertEquals(test.atYear(2005), LocalDate.of(2005, 2, 28));
 621     }
 622 
 623     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 624     public void test_atYear_int_invalidYear() {
 625         MonthDay test = MonthDay.of(6, 30);
 626         test.atYear(Integer.MIN_VALUE);
 627     }
 628 
 629     //-----------------------------------------------------------------------
 630     // compareTo()
 631     //-----------------------------------------------------------------------
 632     @Test(groups={"tck"})
 633     public void test_comparisons() {
 634         doTest_comparisons_MonthDay(
 635             MonthDay.of(1, 1),
 636             MonthDay.of(1, 31),
 637             MonthDay.of(2, 1),
 638             MonthDay.of(2, 29),
 639             MonthDay.of(3, 1),
 640             MonthDay.of(12, 31)
 641         );
 642     }
 643 
 644     void doTest_comparisons_MonthDay(MonthDay... localDates) {
 645         for (int i = 0; i < localDates.length; i++) {
 646             MonthDay a = localDates[i];
 647             for (int j = 0; j < localDates.length; j++) {
 648                 MonthDay b = localDates[j];
 649                 if (i < j) {
 650                     assertTrue(a.compareTo(b) < 0, a + " <=> " + b);
 651                     assertEquals(a.isBefore(b), true, a + " <=> " + b);
 652                     assertEquals(a.isAfter(b), false, a + " <=> " + b);
 653                     assertEquals(a.equals(b), false, a + " <=> " + b);
 654                 } else if (i > j) {
 655                     assertTrue(a.compareTo(b) > 0, a + " <=> " + b);
 656                     assertEquals(a.isBefore(b), false, a + " <=> " + b);
 657                     assertEquals(a.isAfter(b), true, a + " <=> " + b);
 658                     assertEquals(a.equals(b), false, a + " <=> " + b);
 659                 } else {
 660                     assertEquals(a.compareTo(b), 0, a + " <=> " + b);
 661                     assertEquals(a.isBefore(b), false, a + " <=> " + b);
 662                     assertEquals(a.isAfter(b), false, a + " <=> " + b);
 663                     assertEquals(a.equals(b), true, a + " <=> " + b);
 664                 }
 665             }
 666         }
 667     }
 668 
 669     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 670     public void test_compareTo_ObjectNull() {
 671         TEST_07_15.compareTo(null);
 672     }
 673 
 674     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 675     public void test_isBefore_ObjectNull() {
 676         TEST_07_15.isBefore(null);
 677     }
 678 
 679     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 680     public void test_isAfter_ObjectNull() {
 681         TEST_07_15.isAfter(null);
 682     }
 683 
 684     //-----------------------------------------------------------------------
 685     // equals()
 686     //-----------------------------------------------------------------------
 687     @Test(groups={"tck"})
 688     public void test_equals() {
 689         MonthDay a = MonthDay.of(1, 1);
 690         MonthDay b = MonthDay.of(1, 1);
 691         MonthDay c = MonthDay.of(2, 1);
 692         MonthDay d = MonthDay.of(1, 2);
 693 
 694         assertEquals(a.equals(a), true);
 695         assertEquals(a.equals(b), true);
 696         assertEquals(a.equals(c), false);
 697         assertEquals(a.equals(d), false);
 698 
 699         assertEquals(b.equals(a), true);
 700         assertEquals(b.equals(b), true);
 701         assertEquals(b.equals(c), false);
 702         assertEquals(b.equals(d), false);
 703 
 704         assertEquals(c.equals(a), false);
 705         assertEquals(c.equals(b), false);
 706         assertEquals(c.equals(c), true);
 707         assertEquals(c.equals(d), false);
 708 
 709         assertEquals(d.equals(a), false);
 710         assertEquals(d.equals(b), false);
 711         assertEquals(d.equals(c), false);
 712         assertEquals(d.equals(d), true);
 713     }
 714 
 715     @Test(groups={"tck"})
 716     public void test_equals_itself_true() {
 717         assertEquals(TEST_07_15.equals(TEST_07_15), true);
 718     }
 719 
 720     @Test(groups={"tck"})
 721     public void test_equals_string_false() {
 722         assertEquals(TEST_07_15.equals("2007-07-15"), false);
 723     }
 724 
 725     @Test(groups={"tck"})
 726     public void test_equals_null_false() {
 727         assertEquals(TEST_07_15.equals(null), false);
 728     }
 729 
 730     //-----------------------------------------------------------------------
 731     // hashCode()
 732     //-----------------------------------------------------------------------
 733     @Test(dataProvider="sampleDates", groups={"tck"})
 734     public void test_hashCode(int m, int d) {
 735         MonthDay a = MonthDay.of(m, d);
 736         assertEquals(a.hashCode(), a.hashCode());
 737         MonthDay b = MonthDay.of(m, d);
 738         assertEquals(a.hashCode(), b.hashCode());
 739     }
 740 
 741     @Test(groups={"tck"})
 742     public void test_hashCode_unique() {
 743         int leapYear = 2008;
 744         Set<Integer> uniques = new HashSet<Integer>(366);
 745         for (int i = 1; i <= 12; i++) {
 746             for (int j = 1; j <= 31; j++) {
 747                 if (YearMonth.of(leapYear, i).isValidDay(j)) {
 748                     assertTrue(uniques.add(MonthDay.of(i, j).hashCode()));
 749                 }
 750             }
 751         }
 752     }
 753 
 754     //-----------------------------------------------------------------------
 755     // toString()
 756     //-----------------------------------------------------------------------
 757     @DataProvider(name="sampleToString")
 758     Object[][] provider_sampleToString() {
 759         return new Object[][] {
 760             {7, 5, "--07-05"},
 761             {12, 31, "--12-31"},
 762             {1, 2, "--01-02"},
 763         };
 764     }
 765 
 766     @Test(dataProvider="sampleToString", groups={"tck"})
 767     public void test_toString(int m, int d, String expected) {
 768         MonthDay test = MonthDay.of(m, d);
 769         String str = test.toString();
 770         assertEquals(str, expected);
 771     }
 772 
 773     //-----------------------------------------------------------------------
 774     // toString(DateTimeFormatter)
 775     //-----------------------------------------------------------------------
 776     @Test(groups={"tck"})
 777     public void test_toString_formatter() {
 778         DateTimeFormatter f = DateTimeFormatter.ofPattern("M d");
 779         String t = MonthDay.of(12, 3).toString(f);
 780         assertEquals(t, "12 3");
 781     }
 782 
 783     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 784     public void test_toString_formatter_null() {
 785         MonthDay.of(12, 3).toString(null);
 786     }
 787 
 788 }