test/java/time/tck/java/time/TCKYear.java

Print this page




  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.temporal;
  61 
  62 import static java.time.temporal.ChronoField.ERA;
  63 import static java.time.temporal.ChronoField.YEAR;
  64 import static java.time.temporal.ChronoField.YEAR_OF_ERA;
  65 import static org.testng.Assert.assertEquals;
  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.util.ArrayList;
  72 import java.util.Arrays;
  73 import java.util.List;
  74 
  75 import java.time.Clock;
  76 import java.time.DateTimeException;
  77 import java.time.Instant;
  78 import java.time.LocalDate;
  79 import java.time.LocalTime;
  80 import java.time.Month;




  81 import java.time.ZoneId;
  82 import java.time.ZoneOffset;

  83 import java.time.format.DateTimeFormatter;
  84 import java.time.format.DateTimeFormatters;
  85 import java.time.format.DateTimeParseException;
  86 import java.time.temporal.ChronoField;

  87 import java.time.temporal.JulianFields;
  88 import java.time.temporal.MonthDay;
  89 import java.time.temporal.OffsetDateTime;
  90 import java.time.temporal.Temporal;
  91 import java.time.temporal.TemporalAccessor;
  92 import java.time.temporal.TemporalField;
  93 import java.time.temporal.Year;
  94 import java.time.temporal.YearMonth;


  95 
  96 import org.testng.annotations.BeforeMethod;
  97 import org.testng.annotations.DataProvider;
  98 import org.testng.annotations.Test;
  99 import tck.java.time.AbstractDateTimeTest;
 100 
 101 /**
 102  * Test Year.
 103  */
 104 @Test
 105 public class TCKYear extends AbstractDateTimeTest {
 106 
 107     private static final Year TEST_2008 = Year.of(2008);
 108 
 109     @BeforeMethod
 110     public void setUp() {
 111     }
 112 
 113     //-----------------------------------------------------------------------
 114     @Override
 115     protected List<TemporalAccessor> samples() {
 116         TemporalAccessor[] array = {TEST_2008, };
 117         return Arrays.asList(array);
 118     }
 119 


 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 Exception {
 143         assertSerializable(Year.of(2));
 144         assertSerializable(Year.of(0));
 145         assertSerializable(Year.of(-2));
 146     }
 147 
 148     @Test
 149     public void test_serialization_format() throws Exception {
 150         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 151         try (DataOutputStream dos = new DataOutputStream(baos) ) {
 152             dos.writeByte(4);
 153             dos.writeInt(2012);
 154         }
 155         byte[] bytes = baos.toByteArray();
 156         assertSerializedBySer(Year.of(2012), bytes);
 157     }
 158 
 159     //-----------------------------------------------------------------------
 160     // now()
 161     //-----------------------------------------------------------------------
 162     @Test(groups={"tck"})
 163     public void now() {
 164         Year expected = Year.now(Clock.systemDefaultZone());
 165         Year test = Year.now();
 166         for (int i = 0; i < 100; i++) {
 167             if (expected.equals(test)) {
 168                 return;
 169             }
 170             expected = Year.now(Clock.systemDefaultZone());
 171             test = Year.now();
 172         }


 300         try {
 301             Year.parse(text);
 302             fail(String.format("Parse should have failed for %s at position %d", text, pos));
 303         } catch (DateTimeParseException ex) {
 304             assertEquals(ex.getParsedString(), text);
 305             assertEquals(ex.getErrorIndex(), pos);
 306             throw ex;
 307         }
 308     }
 309 
 310     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 311     public void factory_parse_nullText() {
 312         Year.parse(null);
 313     }
 314 
 315     //-----------------------------------------------------------------------
 316     // parse(DateTimeFormatter)
 317     //-----------------------------------------------------------------------
 318     @Test(groups={"tck"})
 319     public void factory_parse_formatter() {
 320         DateTimeFormatter f = DateTimeFormatters.pattern("y");
 321         Year test = Year.parse("2010", f);
 322         assertEquals(test, Year.of(2010));
 323     }
 324 
 325     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 326     public void factory_parse_formatter_nullText() {
 327         DateTimeFormatter f = DateTimeFormatters.pattern("y");
 328         Year.parse((String) null, f);
 329     }
 330 
 331     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 332     public void factory_parse_formatter_nullFormatter() {
 333         Year.parse("ANY", null);
 334     }
 335 
 336     //-----------------------------------------------------------------------
 337     // get(TemporalField)
 338     //-----------------------------------------------------------------------
 339     @Test
 340     public void test_get_TemporalField() {
 341         assertEquals(TEST_2008.get(ChronoField.YEAR), 2008);
 342         assertEquals(TEST_2008.get(ChronoField.YEAR_OF_ERA), 2008);
 343         assertEquals(TEST_2008.get(ChronoField.ERA), 1);
 344     }
 345 
 346     @Test
 347     public void test_getLong_TemporalField() {
 348         assertEquals(TEST_2008.getLong(ChronoField.YEAR), 2008);
 349         assertEquals(TEST_2008.getLong(ChronoField.YEAR_OF_ERA), 2008);
 350         assertEquals(TEST_2008.getLong(ChronoField.ERA), 1);
 351     }
 352 
 353     //-----------------------------------------------------------------------































 354     // isLeap()
 355     //-----------------------------------------------------------------------
 356     @Test(groups={"tck"})
 357     public void test_isLeap() {
 358         assertEquals(Year.of(1999).isLeap(), false);
 359         assertEquals(Year.of(2000).isLeap(), true);
 360         assertEquals(Year.of(2001).isLeap(), false);
 361 
 362         assertEquals(Year.of(2007).isLeap(), false);
 363         assertEquals(Year.of(2008).isLeap(), true);
 364         assertEquals(Year.of(2009).isLeap(), false);
 365         assertEquals(Year.of(2010).isLeap(), false);
 366         assertEquals(Year.of(2011).isLeap(), false);
 367         assertEquals(Year.of(2012).isLeap(), true);
 368 
 369         assertEquals(Year.of(2095).isLeap(), false);
 370         assertEquals(Year.of(2096).isLeap(), true);
 371         assertEquals(Year.of(2097).isLeap(), false);
 372         assertEquals(Year.of(2098).isLeap(), false);
 373         assertEquals(Year.of(2099).isLeap(), false);


 538         assertEquals(Year.of(2101).length(), 365);
 539         assertEquals(Year.of(2102).length(), 365);
 540         assertEquals(Year.of(2103).length(), 365);
 541         assertEquals(Year.of(2104).length(), 366);
 542         assertEquals(Year.of(2105).length(), 365);
 543 
 544         assertEquals(Year.of(-500).length(), 365);
 545         assertEquals(Year.of(-400).length(), 366);
 546         assertEquals(Year.of(-300).length(), 365);
 547         assertEquals(Year.of(-200).length(), 365);
 548         assertEquals(Year.of(-100).length(), 365);
 549         assertEquals(Year.of(0).length(), 366);
 550         assertEquals(Year.of(100).length(), 365);
 551         assertEquals(Year.of(200).length(), 365);
 552         assertEquals(Year.of(300).length(), 365);
 553         assertEquals(Year.of(400).length(), 366);
 554         assertEquals(Year.of(500).length(), 365);
 555     }
 556 
 557     //-----------------------------------------------------------------------
 558     // isValidMonthDay(Month)
 559     //-----------------------------------------------------------------------
 560     @Test(groups={"tck"})
 561     public void test_isValidMonthDay_june() {
 562         Year test = Year.of(2007);
 563         MonthDay monthDay = MonthDay.of(6, 30);
 564         assertEquals(test.isValidMonthDay(monthDay), true);
 565     }
 566 
 567     @Test(groups={"tck"})
 568     public void test_isValidMonthDay_febNonLeap() {
 569         Year test = Year.of(2007);
 570         MonthDay monthDay = MonthDay.of(2, 29);
 571         assertEquals(test.isValidMonthDay(monthDay), false);
 572     }
 573 
 574     @Test(groups={"tck"})
 575     public void test_isValidMonthDay_febLeap() {
 576         Year test = Year.of(2008);
 577         MonthDay monthDay = MonthDay.of(2, 29);
 578         assertEquals(test.isValidMonthDay(monthDay), true);
 579     }
 580 
 581     @Test(groups={"tck"})
 582     public void test_isValidMonthDay_null() {
 583         Year test = Year.of(2008);
 584         assertEquals(test.isValidMonthDay(null), false);
 585     }
 586 
 587     //-----------------------------------------------------------------------
 588     // atMonth(Month)
 589     //-----------------------------------------------------------------------
 590     @Test(groups={"tck"})
 591     public void test_atMonth() {
 592         Year test = Year.of(2008);
 593         assertEquals(test.atMonth(Month.JUNE), YearMonth.of(2008, 6));
 594     }
 595 
 596     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 597     public void test_atMonth_nullMonth() {
 598         Year test = Year.of(2008);
 599         test.atMonth((Month) null);
 600     }
 601 
 602     //-----------------------------------------------------------------------
 603     // atMonth(int)
 604     //-----------------------------------------------------------------------
 605     @Test(groups={"tck"})
 606     public void test_atMonth_int() {
 607         Year test = Year.of(2008);
 608         assertEquals(test.atMonth(6), YearMonth.of(2008, 6));
 609     }
 610 
 611     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 612     public void test_atMonth_int_invalidMonth() {
 613         Year test = Year.of(2008);
 614         test.atMonth(13);
 615     }
 616 
 617     //-----------------------------------------------------------------------
 618     // atMonthDay(Month)
 619     //-----------------------------------------------------------------------
 620     @Test(groups={"tck"})
 621     public void test_atMonthDay() {
 622         Year test = Year.of(2008);
 623         assertEquals(test.atMonthDay(MonthDay.of(6, 30)), LocalDate.of(2008, 6, 30));



 624     }
 625 
 626     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 627     public void test_atMonthDay_nullMonthDay() {
 628         Year test = Year.of(2008);
 629         test.atMonthDay((MonthDay) null);
 630     }
 631 
 632     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 633     public void test_atMonthDay_invalidMonthDay() {
 634         Year test = Year.of(2008);
 635         test.atMonthDay(MonthDay.of(6, 31));
 636     }
 637 
 638     //-----------------------------------------------------------------------
 639     // atDay(int)
 640     //-----------------------------------------------------------------------
 641     @Test(groups={"tck"})
 642     public void test_atDay_notLeapYear() {
 643         Year test = Year.of(2007);
 644         LocalDate expected = LocalDate.of(2007, 1, 1);
 645         for (int i = 1; i <= 365; i++) {
 646             assertEquals(test.atDay(i), expected);
 647             expected = expected.plusDays(1);
 648         }
 649     }
 650 
 651     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 652     public void test_atDay_notLeapYear_day366() {
 653         Year test = Year.of(2007);
 654         test.atDay(366);
 655     }


 751         Year test = Year.of(1);
 752         assertEquals(test.equals("Incorrect type"), false);
 753     }
 754 
 755     //-----------------------------------------------------------------------
 756     // toString()
 757     //-----------------------------------------------------------------------
 758     @Test(groups={"tck"})
 759     public void test_toString() {
 760         for (int i = -4; i <= 2104; i++) {
 761             Year a = Year.of(i);
 762             assertEquals(a.toString(), "" + i);
 763         }
 764     }
 765 
 766     //-----------------------------------------------------------------------
 767     // toString(DateTimeFormatter)
 768     //-----------------------------------------------------------------------
 769     @Test(groups={"tck"})
 770     public void test_toString_formatter() {
 771         DateTimeFormatter f = DateTimeFormatters.pattern("y");
 772         String t = Year.of(2010).toString(f);
 773         assertEquals(t, "2010");
 774     }
 775 
 776     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 777     public void test_toString_formatter_null() {
 778         Year.of(2010).toString(null);
 779     }
 780 
 781 }


  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.ERA;
  63 import static java.time.temporal.ChronoField.YEAR;
  64 import static java.time.temporal.ChronoField.YEAR_OF_ERA;
  65 import static org.testng.Assert.assertEquals;
  66 import static org.testng.Assert.fail;
  67 
  68 import java.io.ByteArrayOutputStream;
  69 import java.io.DataOutputStream;





  70 import java.time.Clock;
  71 import java.time.DateTimeException;
  72 import java.time.Instant;
  73 import java.time.LocalDate;
  74 import java.time.LocalTime;
  75 import java.time.Month;
  76 import java.time.MonthDay;
  77 import java.time.OffsetDateTime;
  78 import java.time.Year;
  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.ChronoUnit;
  87 import java.time.temporal.JulianFields;
  88 import java.time.temporal.Queries;

  89 import java.time.temporal.Temporal;
  90 import java.time.temporal.TemporalAccessor;
  91 import java.time.temporal.TemporalField;
  92 import java.time.temporal.TemporalQuery;
  93 import java.util.ArrayList;
  94 import java.util.Arrays;
  95 import java.util.List;
  96 
  97 import org.testng.annotations.BeforeMethod;
  98 import org.testng.annotations.DataProvider;
  99 import org.testng.annotations.Test;

 100 
 101 /**
 102  * Test Year.
 103  */
 104 @Test
 105 public class TCKYear extends AbstractDateTimeTest {
 106 
 107     private static final Year TEST_2008 = Year.of(2008);
 108 
 109     @BeforeMethod
 110     public void setUp() {
 111     }
 112 
 113     //-----------------------------------------------------------------------
 114     @Override
 115     protected List<TemporalAccessor> samples() {
 116         TemporalAccessor[] array = {TEST_2008, };
 117         return Arrays.asList(array);
 118     }
 119 


 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 Exception {
 143         assertSerializable(Year.of(2));
 144         assertSerializable(Year.of(0));
 145         assertSerializable(Year.of(-2));
 146     }
 147 
 148     @Test
 149     public void test_serialization_format() throws Exception {
 150         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 151         try (DataOutputStream dos = new DataOutputStream(baos) ) {
 152             dos.writeByte(11);       // java.time.temporal.Ser.YEAR_TYPE
 153             dos.writeInt(2012);
 154         }
 155         byte[] bytes = baos.toByteArray();
 156         assertSerializedBySer(Year.of(2012), bytes);
 157     }
 158 
 159     //-----------------------------------------------------------------------
 160     // now()
 161     //-----------------------------------------------------------------------
 162     @Test(groups={"tck"})
 163     public void now() {
 164         Year expected = Year.now(Clock.systemDefaultZone());
 165         Year test = Year.now();
 166         for (int i = 0; i < 100; i++) {
 167             if (expected.equals(test)) {
 168                 return;
 169             }
 170             expected = Year.now(Clock.systemDefaultZone());
 171             test = Year.now();
 172         }


 300         try {
 301             Year.parse(text);
 302             fail(String.format("Parse should have failed for %s at position %d", text, pos));
 303         } catch (DateTimeParseException ex) {
 304             assertEquals(ex.getParsedString(), text);
 305             assertEquals(ex.getErrorIndex(), pos);
 306             throw ex;
 307         }
 308     }
 309 
 310     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 311     public void factory_parse_nullText() {
 312         Year.parse(null);
 313     }
 314 
 315     //-----------------------------------------------------------------------
 316     // parse(DateTimeFormatter)
 317     //-----------------------------------------------------------------------
 318     @Test(groups={"tck"})
 319     public void factory_parse_formatter() {
 320         DateTimeFormatter f = DateTimeFormatter.ofPattern("y");
 321         Year test = Year.parse("2010", f);
 322         assertEquals(test, Year.of(2010));
 323     }
 324 
 325     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 326     public void factory_parse_formatter_nullText() {
 327         DateTimeFormatter f = DateTimeFormatter.ofPattern("y");
 328         Year.parse((String) null, f);
 329     }
 330 
 331     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 332     public void factory_parse_formatter_nullFormatter() {
 333         Year.parse("ANY", null);
 334     }
 335 
 336     //-----------------------------------------------------------------------
 337     // get(TemporalField)
 338     //-----------------------------------------------------------------------
 339     @Test
 340     public void test_get_TemporalField() {
 341         assertEquals(TEST_2008.get(ChronoField.YEAR), 2008);
 342         assertEquals(TEST_2008.get(ChronoField.YEAR_OF_ERA), 2008);
 343         assertEquals(TEST_2008.get(ChronoField.ERA), 1);
 344     }
 345 
 346     @Test
 347     public void test_getLong_TemporalField() {
 348         assertEquals(TEST_2008.getLong(ChronoField.YEAR), 2008);
 349         assertEquals(TEST_2008.getLong(ChronoField.YEAR_OF_ERA), 2008);
 350         assertEquals(TEST_2008.getLong(ChronoField.ERA), 1);
 351     }
 352 
 353     //-----------------------------------------------------------------------
 354     // query(TemporalQuery)
 355     //-----------------------------------------------------------------------
 356     @DataProvider(name="query")
 357     Object[][] data_query() {
 358         return new Object[][] {
 359                 {TEST_2008, Queries.chronology(), IsoChronology.INSTANCE},
 360                 {TEST_2008, Queries.zoneId(), null},
 361                 {TEST_2008, Queries.precision(), ChronoUnit.YEARS},
 362                 {TEST_2008, Queries.zone(), null},
 363                 {TEST_2008, Queries.offset(), null},
 364                 {TEST_2008, Queries.localDate(), null},
 365                 {TEST_2008, Queries.localTime(), null},
 366         };
 367     }
 368 
 369     @Test(dataProvider="query")
 370     public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 371         assertEquals(temporal.query(query), expected);
 372     }
 373 
 374     @Test(dataProvider="query")
 375     public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 376         assertEquals(query.queryFrom(temporal), expected);
 377     }
 378 
 379     @Test(expectedExceptions=NullPointerException.class)
 380     public void test_query_null() {
 381         TEST_2008.query(null);
 382     }
 383 
 384     //-----------------------------------------------------------------------
 385     // isLeap()
 386     //-----------------------------------------------------------------------
 387     @Test(groups={"tck"})
 388     public void test_isLeap() {
 389         assertEquals(Year.of(1999).isLeap(), false);
 390         assertEquals(Year.of(2000).isLeap(), true);
 391         assertEquals(Year.of(2001).isLeap(), false);
 392 
 393         assertEquals(Year.of(2007).isLeap(), false);
 394         assertEquals(Year.of(2008).isLeap(), true);
 395         assertEquals(Year.of(2009).isLeap(), false);
 396         assertEquals(Year.of(2010).isLeap(), false);
 397         assertEquals(Year.of(2011).isLeap(), false);
 398         assertEquals(Year.of(2012).isLeap(), true);
 399 
 400         assertEquals(Year.of(2095).isLeap(), false);
 401         assertEquals(Year.of(2096).isLeap(), true);
 402         assertEquals(Year.of(2097).isLeap(), false);
 403         assertEquals(Year.of(2098).isLeap(), false);
 404         assertEquals(Year.of(2099).isLeap(), false);


 569         assertEquals(Year.of(2101).length(), 365);
 570         assertEquals(Year.of(2102).length(), 365);
 571         assertEquals(Year.of(2103).length(), 365);
 572         assertEquals(Year.of(2104).length(), 366);
 573         assertEquals(Year.of(2105).length(), 365);
 574 
 575         assertEquals(Year.of(-500).length(), 365);
 576         assertEquals(Year.of(-400).length(), 366);
 577         assertEquals(Year.of(-300).length(), 365);
 578         assertEquals(Year.of(-200).length(), 365);
 579         assertEquals(Year.of(-100).length(), 365);
 580         assertEquals(Year.of(0).length(), 366);
 581         assertEquals(Year.of(100).length(), 365);
 582         assertEquals(Year.of(200).length(), 365);
 583         assertEquals(Year.of(300).length(), 365);
 584         assertEquals(Year.of(400).length(), 366);
 585         assertEquals(Year.of(500).length(), 365);
 586     }
 587 
 588     //-----------------------------------------------------------------------
 589     // isValidMonthDay(MonthDay)
 590     //-----------------------------------------------------------------------
 591     @DataProvider(name="isValidMonthDay")
 592     Object[][] data_isValidMonthDay() {
 593         return new Object[][] {
 594                 {Year.of(2007), MonthDay.of(6, 30), true},
 595                 {Year.of(2008), MonthDay.of(2, 28), true},
 596                 {Year.of(2008), MonthDay.of(2, 29), true},
 597                 {Year.of(2009), MonthDay.of(2, 28), true},
 598                 {Year.of(2009), MonthDay.of(2, 29), false},
 599                 {Year.of(2009), null, false},
 600         };


 601     }
 602 
 603     @Test(dataProvider="isValidMonthDay")
 604     public void test_isValidMonthDay(Year year, MonthDay monthDay, boolean expected) {
 605         assertEquals(year.isValidMonthDay(monthDay), expected);








 606     }
 607 
 608     //-----------------------------------------------------------------------
 609     // atMonth(Month)
 610     //-----------------------------------------------------------------------
 611     @Test
 612     public void test_atMonth() {
 613         Year test = Year.of(2008);
 614         assertEquals(test.atMonth(Month.JUNE), YearMonth.of(2008, 6));
 615     }
 616 
 617     @Test(expectedExceptions=NullPointerException.class)
 618     public void test_atMonth_nullMonth() {
 619         Year test = Year.of(2008);
 620         test.atMonth((Month) null);
 621     }
 622 
 623     //-----------------------------------------------------------------------
 624     // atMonth(int)
 625     //-----------------------------------------------------------------------
 626     @Test
 627     public void test_atMonth_int() {
 628         Year test = Year.of(2008);
 629         assertEquals(test.atMonth(6), YearMonth.of(2008, 6));
 630     }
 631 
 632     @Test(expectedExceptions=DateTimeException.class)
 633     public void test_atMonth_int_invalidMonth() {
 634         Year test = Year.of(2008);
 635         test.atMonth(13);
 636     }
 637 
 638     //-----------------------------------------------------------------------
 639     // atMonthDay(Month)
 640     //-----------------------------------------------------------------------
 641     @DataProvider(name="atMonthDay")
 642     Object[][] data_atMonthDay() {
 643         return new Object[][] {
 644                 {Year.of(2008), MonthDay.of(6, 30), LocalDate.of(2008, 6, 30)},
 645                 {Year.of(2008), MonthDay.of(2, 29), LocalDate.of(2008, 2, 29)},
 646                 {Year.of(2009), MonthDay.of(2, 29), LocalDate.of(2009, 2, 28)},
 647         };
 648     }
 649 
 650     @Test(dataProvider="atMonthDay")
 651     public void test_atMonthDay(Year year, MonthDay monthDay, LocalDate expected) {
 652         assertEquals(year.atMonthDay(monthDay), expected);

 653     }
 654 
 655     @Test(expectedExceptions=NullPointerException.class)
 656     public void test_atMonthDay_nullMonthDay() {
 657         Year test = Year.of(2008);
 658         test.atMonthDay((MonthDay) null);
 659     }
 660 
 661     //-----------------------------------------------------------------------
 662     // atDay(int)
 663     //-----------------------------------------------------------------------
 664     @Test(groups={"tck"})
 665     public void test_atDay_notLeapYear() {
 666         Year test = Year.of(2007);
 667         LocalDate expected = LocalDate.of(2007, 1, 1);
 668         for (int i = 1; i <= 365; i++) {
 669             assertEquals(test.atDay(i), expected);
 670             expected = expected.plusDays(1);
 671         }
 672     }
 673 
 674     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 675     public void test_atDay_notLeapYear_day366() {
 676         Year test = Year.of(2007);
 677         test.atDay(366);
 678     }


 774         Year test = Year.of(1);
 775         assertEquals(test.equals("Incorrect type"), false);
 776     }
 777 
 778     //-----------------------------------------------------------------------
 779     // toString()
 780     //-----------------------------------------------------------------------
 781     @Test(groups={"tck"})
 782     public void test_toString() {
 783         for (int i = -4; i <= 2104; i++) {
 784             Year a = Year.of(i);
 785             assertEquals(a.toString(), "" + i);
 786         }
 787     }
 788 
 789     //-----------------------------------------------------------------------
 790     // toString(DateTimeFormatter)
 791     //-----------------------------------------------------------------------
 792     @Test(groups={"tck"})
 793     public void test_toString_formatter() {
 794         DateTimeFormatter f = DateTimeFormatter.ofPattern("y");
 795         String t = Year.of(2010).toString(f);
 796         assertEquals(t, "2010");
 797     }
 798 
 799     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 800     public void test_toString_formatter_null() {
 801         Year.of(2010).toString(null);
 802     }
 803 
 804 }