test/java/time/tck/java/time/TCKLocalDateTime.java

Print this page

        

*** 68,78 **** import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_DAY; import static java.time.temporal.ChronoField.DAY_OF_MONTH; import static java.time.temporal.ChronoField.DAY_OF_WEEK; import static java.time.temporal.ChronoField.DAY_OF_YEAR; import static java.time.temporal.ChronoField.EPOCH_DAY; - import static java.time.temporal.ChronoField.EPOCH_MONTH; import static java.time.temporal.ChronoField.ERA; import static java.time.temporal.ChronoField.HOUR_OF_AMPM; import static java.time.temporal.ChronoField.HOUR_OF_DAY; import static java.time.temporal.ChronoField.MICRO_OF_DAY; import static java.time.temporal.ChronoField.MICRO_OF_SECOND; --- 68,77 ----
*** 81,103 **** --- 80,113 ---- import static java.time.temporal.ChronoField.MINUTE_OF_DAY; import static java.time.temporal.ChronoField.MINUTE_OF_HOUR; import static java.time.temporal.ChronoField.MONTH_OF_YEAR; import static java.time.temporal.ChronoField.NANO_OF_DAY; import static java.time.temporal.ChronoField.NANO_OF_SECOND; + import static java.time.temporal.ChronoField.PROLEPTIC_MONTH; import static java.time.temporal.ChronoField.SECOND_OF_DAY; import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; import static java.time.temporal.ChronoField.YEAR; import static java.time.temporal.ChronoField.YEAR_OF_ERA; + import static java.time.temporal.ChronoUnit.CENTURIES; import static java.time.temporal.ChronoUnit.DAYS; + import static java.time.temporal.ChronoUnit.DECADES; + import static java.time.temporal.ChronoUnit.HALF_DAYS; + import static java.time.temporal.ChronoUnit.HOURS; + import static java.time.temporal.ChronoUnit.MICROS; + import static java.time.temporal.ChronoUnit.MILLENNIA; + import static java.time.temporal.ChronoUnit.MILLIS; + import static java.time.temporal.ChronoUnit.MINUTES; import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.NANOS; import static java.time.temporal.ChronoUnit.SECONDS; + import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertSame; import static org.testng.Assert.assertTrue; + import static org.testng.Assert.fail; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.time.Clock; import java.time.DateTimeException;
*** 106,126 **** import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.Month; import java.time.OffsetDateTime; import java.time.Year; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.chrono.IsoChronology; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.time.temporal.ChronoField; import java.time.temporal.ChronoUnit; import java.time.temporal.JulianFields; - import java.time.temporal.Queries; import java.time.temporal.Temporal; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; import java.time.temporal.TemporalAmount; import java.time.temporal.TemporalField; --- 116,136 ---- import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.Month; import java.time.OffsetDateTime; + import java.time.OffsetTime; import java.time.Year; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.chrono.IsoChronology; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.time.temporal.ChronoField; import java.time.temporal.ChronoUnit; import java.time.temporal.JulianFields; import java.time.temporal.Temporal; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; import java.time.temporal.TemporalAmount; import java.time.temporal.TemporalField;
*** 151,161 **** private LocalDateTime MAX_DATE_TIME; private LocalDateTime MIN_DATE_TIME; private Instant MAX_INSTANT; private Instant MIN_INSTANT; ! @BeforeMethod(groups={"implementation","tck"}) public void setUp() { MAX_DATE_TIME = LocalDateTime.MAX; MIN_DATE_TIME = LocalDateTime.MIN; MAX_INSTANT = MAX_DATE_TIME.atZone(ZoneOffset.UTC).toInstant(); MIN_INSTANT = MIN_DATE_TIME.atZone(ZoneOffset.UTC).toInstant(); --- 161,171 ---- private LocalDateTime MAX_DATE_TIME; private LocalDateTime MIN_DATE_TIME; private Instant MAX_INSTANT; private Instant MIN_INSTANT; ! @BeforeMethod public void setUp() { MAX_DATE_TIME = LocalDateTime.MAX; MIN_DATE_TIME = LocalDateTime.MIN; MAX_INSTANT = MAX_DATE_TIME.atZone(ZoneOffset.UTC).toInstant(); MIN_INSTANT = MIN_DATE_TIME.atZone(ZoneOffset.UTC).toInstant();
*** 193,203 **** DAY_OF_YEAR, EPOCH_DAY, ALIGNED_WEEK_OF_MONTH, ALIGNED_WEEK_OF_YEAR, MONTH_OF_YEAR, ! EPOCH_MONTH, YEAR_OF_ERA, YEAR, ERA, JulianFields.JULIAN_DAY, JulianFields.MODIFIED_JULIAN_DAY, --- 203,213 ---- DAY_OF_YEAR, EPOCH_DAY, ALIGNED_WEEK_OF_MONTH, ALIGNED_WEEK_OF_YEAR, MONTH_OF_YEAR, ! PROLEPTIC_MONTH, YEAR_OF_ERA, YEAR, ERA, JulianFields.JULIAN_DAY, JulianFields.MODIFIED_JULIAN_DAY,
*** 270,280 **** } //----------------------------------------------------------------------- // now() //----------------------------------------------------------------------- ! @Test(timeOut=30000, groups={"tck"}) // TODO: remove when time zone loading is faster public void now() { LocalDateTime expected = LocalDateTime.now(Clock.systemDefaultZone()); LocalDateTime test = LocalDateTime.now(); long diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay()); if (diff >= 100000000) { --- 280,290 ---- } //----------------------------------------------------------------------- // now() //----------------------------------------------------------------------- ! @Test(timeOut=30000) // TODO: remove when time zone loading is faster public void now() { LocalDateTime expected = LocalDateTime.now(Clock.systemDefaultZone()); LocalDateTime test = LocalDateTime.now(); long diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay()); if (diff >= 100000000) {
*** 287,302 **** } //----------------------------------------------------------------------- // now(ZoneId) //----------------------------------------------------------------------- ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void now_ZoneId_nullZoneId() { LocalDateTime.now((ZoneId) null); } ! @Test(groups={"tck"}) public void now_ZoneId() { ZoneId zone = ZoneId.of("UTC+01:02:03"); LocalDateTime expected = LocalDateTime.now(Clock.system(zone)); LocalDateTime test = LocalDateTime.now(zone); for (int i = 0; i < 100; i++) { --- 297,312 ---- } //----------------------------------------------------------------------- // now(ZoneId) //----------------------------------------------------------------------- ! @Test(expectedExceptions=NullPointerException.class) public void now_ZoneId_nullZoneId() { LocalDateTime.now((ZoneId) null); } ! @Test public void now_ZoneId() { ZoneId zone = ZoneId.of("UTC+01:02:03"); LocalDateTime expected = LocalDateTime.now(Clock.system(zone)); LocalDateTime test = LocalDateTime.now(zone); for (int i = 0; i < 100; i++) {
*** 310,325 **** } //----------------------------------------------------------------------- // now(Clock) //----------------------------------------------------------------------- ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void now_Clock_nullClock() { LocalDateTime.now((Clock) null); } ! @Test(groups={"tck"}) public void now_Clock_allSecsInDay_utc() { for (int i = 0; i < (2 * 24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L); Clock clock = Clock.fixed(instant, ZoneOffset.UTC); LocalDateTime test = LocalDateTime.now(clock); --- 320,335 ---- } //----------------------------------------------------------------------- // now(Clock) //----------------------------------------------------------------------- ! @Test(expectedExceptions=NullPointerException.class) public void now_Clock_nullClock() { LocalDateTime.now((Clock) null); } ! @Test public void now_Clock_allSecsInDay_utc() { for (int i = 0; i < (2 * 24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L); Clock clock = Clock.fixed(instant, ZoneOffset.UTC); LocalDateTime test = LocalDateTime.now(clock);
*** 331,341 **** assertEquals(test.getSecond(), i % 60); assertEquals(test.getNano(), 123456789); } } ! @Test(groups={"tck"}) public void now_Clock_allSecsInDay_offset() { for (int i = 0; i < (2 * 24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L); Clock clock = Clock.fixed(instant.minusSeconds(OFFSET_PONE.getTotalSeconds()), OFFSET_PONE); LocalDateTime test = LocalDateTime.now(clock); --- 341,351 ---- assertEquals(test.getSecond(), i % 60); assertEquals(test.getNano(), 123456789); } } ! @Test public void now_Clock_allSecsInDay_offset() { for (int i = 0; i < (2 * 24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L); Clock clock = Clock.fixed(instant.minusSeconds(OFFSET_PONE.getTotalSeconds()), OFFSET_PONE); LocalDateTime test = LocalDateTime.now(clock);
*** 347,357 **** assertEquals(test.getSecond(), i % 60); assertEquals(test.getNano(), 123456789); } } ! @Test(groups={"tck"}) public void now_Clock_allSecsInDay_beforeEpoch() { LocalTime expected = LocalTime.MIDNIGHT.plusNanos(123456789L); for (int i =-1; i >= -(24 * 60 * 60); i--) { Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L); Clock clock = Clock.fixed(instant, ZoneOffset.UTC); --- 357,367 ---- assertEquals(test.getSecond(), i % 60); assertEquals(test.getNano(), 123456789); } } ! @Test public void now_Clock_allSecsInDay_beforeEpoch() { LocalTime expected = LocalTime.MIDNIGHT.plusNanos(123456789L); for (int i =-1; i >= -(24 * 60 * 60); i--) { Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L); Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
*** 363,771 **** assertEquals(test.toLocalTime(), expected); } } //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void now_Clock_maxYear() { Clock clock = Clock.fixed(MAX_INSTANT, ZoneOffset.UTC); LocalDateTime test = LocalDateTime.now(clock); assertEquals(test, MAX_DATE_TIME); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void now_Clock_tooBig() { Clock clock = Clock.fixed(MAX_INSTANT.plusSeconds(24 * 60 * 60), ZoneOffset.UTC); LocalDateTime.now(clock); } ! @Test(groups={"tck"}) public void now_Clock_minYear() { Clock clock = Clock.fixed(MIN_INSTANT, ZoneOffset.UTC); LocalDateTime test = LocalDateTime.now(clock); assertEquals(test, MIN_DATE_TIME); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void now_Clock_tooLow() { Clock clock = Clock.fixed(MIN_INSTANT.minusNanos(1), ZoneOffset.UTC); LocalDateTime.now(clock); } //----------------------------------------------------------------------- // of() factories //----------------------------------------------------------------------- //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void factory_of_4intsMonth() { LocalDateTime dateTime = LocalDateTime.of(2007, Month.JULY, 15, 12, 30); check(dateTime, 2007, 7, 15, 12, 30, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_4intsMonth_yearTooLow() { LocalDateTime.of(Integer.MIN_VALUE, Month.JULY, 15, 12, 30); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void factory_of_4intsMonth_nullMonth() { LocalDateTime.of(2007, null, 15, 12, 30); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_4intsMonth_dayTooLow() { LocalDateTime.of(2007, Month.JULY, -1, 12, 30); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_4intsMonth_dayTooHigh() { LocalDateTime.of(2007, Month.JULY, 32, 12, 30); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_4intsMonth_hourTooLow() { LocalDateTime.of(2007, Month.JULY, 15, -1, 30); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_4intsMonth_hourTooHigh() { LocalDateTime.of(2007, Month.JULY, 15, 24, 30); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_4intsMonth_minuteTooLow() { LocalDateTime.of(2007, Month.JULY, 15, 12, -1); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_4intsMonth_minuteTooHigh() { LocalDateTime.of(2007, Month.JULY, 15, 12, 60); } //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void factory_of_5intsMonth() { LocalDateTime dateTime = LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40); check(dateTime, 2007, 7, 15, 12, 30, 40, 0); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_5intsMonth_yearTooLow() { LocalDateTime.of(Integer.MIN_VALUE, Month.JULY, 15, 12, 30, 40); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void factory_of_5intsMonth_nullMonth() { LocalDateTime.of(2007, null, 15, 12, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_5intsMonth_dayTooLow() { LocalDateTime.of(2007, Month.JULY, -1, 12, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_5intsMonth_dayTooHigh() { LocalDateTime.of(2007, Month.JULY, 32, 12, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_5intsMonth_hourTooLow() { LocalDateTime.of(2007, Month.JULY, 15, -1, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_5intsMonth_hourTooHigh() { LocalDateTime.of(2007, Month.JULY, 15, 24, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_5intsMonth_minuteTooLow() { LocalDateTime.of(2007, Month.JULY, 15, 12, -1, 40); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_5intsMonth_minuteTooHigh() { LocalDateTime.of(2007, Month.JULY, 15, 12, 60, 40); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_5intsMonth_secondTooLow() { LocalDateTime.of(2007, Month.JULY, 15, 12, 30, -1); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_5intsMonth_secondTooHigh() { LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 60); } //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void factory_of_6intsMonth() { LocalDateTime dateTime = LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40, 987654321); check(dateTime, 2007, 7, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6intsMonth_yearTooLow() { LocalDateTime.of(Integer.MIN_VALUE, Month.JULY, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void factory_of_6intsMonth_nullMonth() { LocalDateTime.of(2007, null, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6intsMonth_dayTooLow() { LocalDateTime.of(2007, Month.JULY, -1, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6intsMonth_dayTooHigh() { LocalDateTime.of(2007, Month.JULY, 32, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6intsMonth_hourTooLow() { LocalDateTime.of(2007, Month.JULY, 15, -1, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6intsMonth_hourTooHigh() { LocalDateTime.of(2007, Month.JULY, 15, 24, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6intsMonth_minuteTooLow() { LocalDateTime.of(2007, Month.JULY, 15, 12, -1, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6intsMonth_minuteTooHigh() { LocalDateTime.of(2007, Month.JULY, 15, 12, 60, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6intsMonth_secondTooLow() { LocalDateTime.of(2007, Month.JULY, 15, 12, 30, -1, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6intsMonth_secondTooHigh() { LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 60, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6intsMonth_nanoTooLow() { LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40, -1); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6intsMonth_nanoTooHigh() { LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40, 1000000000); } //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void factory_of_5ints() { LocalDateTime dateTime = LocalDateTime.of(2007, 7, 15, 12, 30); check(dateTime, 2007, 7, 15, 12, 30, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_5ints_yearTooLow() { LocalDateTime.of(Integer.MIN_VALUE, 7, 15, 12, 30); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_5ints_monthTooLow() { LocalDateTime.of(2007, 0, 15, 12, 30); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_5ints_monthTooHigh() { LocalDateTime.of(2007, 13, 15, 12, 30); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_5ints_dayTooLow() { LocalDateTime.of(2007, 7, -1, 12, 30); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_5ints_dayTooHigh() { LocalDateTime.of(2007, 7, 32, 12, 30); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_5ints_hourTooLow() { LocalDateTime.of(2007, 7, 15, -1, 30); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_5ints_hourTooHigh() { LocalDateTime.of(2007, 7, 15, 24, 30); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_5ints_minuteTooLow() { LocalDateTime.of(2007, 7, 15, 12, -1); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_5ints_minuteTooHigh() { LocalDateTime.of(2007, 7, 15, 12, 60); } //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void factory_of_6ints() { LocalDateTime dateTime = LocalDateTime.of(2007, 7, 15, 12, 30, 40); check(dateTime, 2007, 7, 15, 12, 30, 40, 0); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6ints_yearTooLow() { LocalDateTime.of(Integer.MIN_VALUE, 7, 15, 12, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6ints_monthTooLow() { LocalDateTime.of(2007, 0, 15, 12, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6ints_monthTooHigh() { LocalDateTime.of(2007, 13, 15, 12, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6ints_dayTooLow() { LocalDateTime.of(2007, 7, -1, 12, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6ints_dayTooHigh() { LocalDateTime.of(2007, 7, 32, 12, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6ints_hourTooLow() { LocalDateTime.of(2007, 7, 15, -1, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6ints_hourTooHigh() { LocalDateTime.of(2007, 7, 15, 24, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6ints_minuteTooLow() { LocalDateTime.of(2007, 7, 15, 12, -1, 40); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6ints_minuteTooHigh() { LocalDateTime.of(2007, 7, 15, 12, 60, 40); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6ints_secondTooLow() { LocalDateTime.of(2007, 7, 15, 12, 30, -1); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_6ints_secondTooHigh() { LocalDateTime.of(2007, 7, 15, 12, 30, 60); } //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void factory_of_7ints() { LocalDateTime dateTime = LocalDateTime.of(2007, 7, 15, 12, 30, 40, 987654321); check(dateTime, 2007, 7, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_7ints_yearTooLow() { LocalDateTime.of(Integer.MIN_VALUE, 7, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_7ints_monthTooLow() { LocalDateTime.of(2007, 0, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_7ints_monthTooHigh() { LocalDateTime.of(2007, 13, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_7ints_dayTooLow() { LocalDateTime.of(2007, 7, -1, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_7ints_dayTooHigh() { LocalDateTime.of(2007, 7, 32, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_7ints_hourTooLow() { LocalDateTime.of(2007, 7, 15, -1, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_7ints_hourTooHigh() { LocalDateTime.of(2007, 7, 15, 24, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_7ints_minuteTooLow() { LocalDateTime.of(2007, 7, 15, 12, -1, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_7ints_minuteTooHigh() { LocalDateTime.of(2007, 7, 15, 12, 60, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_7ints_secondTooLow() { LocalDateTime.of(2007, 7, 15, 12, 30, -1, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_7ints_secondTooHigh() { LocalDateTime.of(2007, 7, 15, 12, 30, 60, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_7ints_nanoTooLow() { LocalDateTime.of(2007, 7, 15, 12, 30, 40, -1); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_of_7ints_nanoTooHigh() { LocalDateTime.of(2007, 7, 15, 12, 30, 40, 1000000000); } //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void factory_of_LocalDate_LocalTime() { LocalDateTime dateTime = LocalDateTime.of(LocalDate.of(2007, 7, 15), LocalTime.of(12, 30, 40, 987654321)); check(dateTime, 2007, 7, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void factory_of_LocalDate_LocalTime_nullLocalDate() { LocalDateTime.of(null, LocalTime.of(12, 30, 40, 987654321)); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void factory_of_LocalDate_LocalTime_nullLocalTime() { LocalDateTime.of(LocalDate.of(2007, 7, 15), null); } //----------------------------------------------------------------------- --- 373,781 ---- assertEquals(test.toLocalTime(), expected); } } //----------------------------------------------------------------------- ! @Test public void now_Clock_maxYear() { Clock clock = Clock.fixed(MAX_INSTANT, ZoneOffset.UTC); LocalDateTime test = LocalDateTime.now(clock); assertEquals(test, MAX_DATE_TIME); } ! @Test(expectedExceptions=DateTimeException.class) public void now_Clock_tooBig() { Clock clock = Clock.fixed(MAX_INSTANT.plusSeconds(24 * 60 * 60), ZoneOffset.UTC); LocalDateTime.now(clock); } ! @Test public void now_Clock_minYear() { Clock clock = Clock.fixed(MIN_INSTANT, ZoneOffset.UTC); LocalDateTime test = LocalDateTime.now(clock); assertEquals(test, MIN_DATE_TIME); } ! @Test(expectedExceptions=DateTimeException.class) public void now_Clock_tooLow() { Clock clock = Clock.fixed(MIN_INSTANT.minusNanos(1), ZoneOffset.UTC); LocalDateTime.now(clock); } //----------------------------------------------------------------------- // of() factories //----------------------------------------------------------------------- //----------------------------------------------------------------------- ! @Test public void factory_of_4intsMonth() { LocalDateTime dateTime = LocalDateTime.of(2007, Month.JULY, 15, 12, 30); check(dateTime, 2007, 7, 15, 12, 30, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_4intsMonth_yearTooLow() { LocalDateTime.of(Integer.MIN_VALUE, Month.JULY, 15, 12, 30); } ! @Test(expectedExceptions=NullPointerException.class) public void factory_of_4intsMonth_nullMonth() { LocalDateTime.of(2007, null, 15, 12, 30); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_4intsMonth_dayTooLow() { LocalDateTime.of(2007, Month.JULY, -1, 12, 30); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_4intsMonth_dayTooHigh() { LocalDateTime.of(2007, Month.JULY, 32, 12, 30); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_4intsMonth_hourTooLow() { LocalDateTime.of(2007, Month.JULY, 15, -1, 30); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_4intsMonth_hourTooHigh() { LocalDateTime.of(2007, Month.JULY, 15, 24, 30); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_4intsMonth_minuteTooLow() { LocalDateTime.of(2007, Month.JULY, 15, 12, -1); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_4intsMonth_minuteTooHigh() { LocalDateTime.of(2007, Month.JULY, 15, 12, 60); } //----------------------------------------------------------------------- ! @Test public void factory_of_5intsMonth() { LocalDateTime dateTime = LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40); check(dateTime, 2007, 7, 15, 12, 30, 40, 0); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_5intsMonth_yearTooLow() { LocalDateTime.of(Integer.MIN_VALUE, Month.JULY, 15, 12, 30, 40); } ! @Test(expectedExceptions=NullPointerException.class) public void factory_of_5intsMonth_nullMonth() { LocalDateTime.of(2007, null, 15, 12, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_5intsMonth_dayTooLow() { LocalDateTime.of(2007, Month.JULY, -1, 12, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_5intsMonth_dayTooHigh() { LocalDateTime.of(2007, Month.JULY, 32, 12, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_5intsMonth_hourTooLow() { LocalDateTime.of(2007, Month.JULY, 15, -1, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_5intsMonth_hourTooHigh() { LocalDateTime.of(2007, Month.JULY, 15, 24, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_5intsMonth_minuteTooLow() { LocalDateTime.of(2007, Month.JULY, 15, 12, -1, 40); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_5intsMonth_minuteTooHigh() { LocalDateTime.of(2007, Month.JULY, 15, 12, 60, 40); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_5intsMonth_secondTooLow() { LocalDateTime.of(2007, Month.JULY, 15, 12, 30, -1); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_5intsMonth_secondTooHigh() { LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 60); } //----------------------------------------------------------------------- ! @Test public void factory_of_6intsMonth() { LocalDateTime dateTime = LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40, 987654321); check(dateTime, 2007, 7, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6intsMonth_yearTooLow() { LocalDateTime.of(Integer.MIN_VALUE, Month.JULY, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=NullPointerException.class) public void factory_of_6intsMonth_nullMonth() { LocalDateTime.of(2007, null, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6intsMonth_dayTooLow() { LocalDateTime.of(2007, Month.JULY, -1, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6intsMonth_dayTooHigh() { LocalDateTime.of(2007, Month.JULY, 32, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6intsMonth_hourTooLow() { LocalDateTime.of(2007, Month.JULY, 15, -1, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6intsMonth_hourTooHigh() { LocalDateTime.of(2007, Month.JULY, 15, 24, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6intsMonth_minuteTooLow() { LocalDateTime.of(2007, Month.JULY, 15, 12, -1, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6intsMonth_minuteTooHigh() { LocalDateTime.of(2007, Month.JULY, 15, 12, 60, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6intsMonth_secondTooLow() { LocalDateTime.of(2007, Month.JULY, 15, 12, 30, -1, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6intsMonth_secondTooHigh() { LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 60, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6intsMonth_nanoTooLow() { LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40, -1); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6intsMonth_nanoTooHigh() { LocalDateTime.of(2007, Month.JULY, 15, 12, 30, 40, 1000000000); } //----------------------------------------------------------------------- ! @Test public void factory_of_5ints() { LocalDateTime dateTime = LocalDateTime.of(2007, 7, 15, 12, 30); check(dateTime, 2007, 7, 15, 12, 30, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_5ints_yearTooLow() { LocalDateTime.of(Integer.MIN_VALUE, 7, 15, 12, 30); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_5ints_monthTooLow() { LocalDateTime.of(2007, 0, 15, 12, 30); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_5ints_monthTooHigh() { LocalDateTime.of(2007, 13, 15, 12, 30); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_5ints_dayTooLow() { LocalDateTime.of(2007, 7, -1, 12, 30); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_5ints_dayTooHigh() { LocalDateTime.of(2007, 7, 32, 12, 30); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_5ints_hourTooLow() { LocalDateTime.of(2007, 7, 15, -1, 30); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_5ints_hourTooHigh() { LocalDateTime.of(2007, 7, 15, 24, 30); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_5ints_minuteTooLow() { LocalDateTime.of(2007, 7, 15, 12, -1); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_5ints_minuteTooHigh() { LocalDateTime.of(2007, 7, 15, 12, 60); } //----------------------------------------------------------------------- ! @Test public void factory_of_6ints() { LocalDateTime dateTime = LocalDateTime.of(2007, 7, 15, 12, 30, 40); check(dateTime, 2007, 7, 15, 12, 30, 40, 0); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6ints_yearTooLow() { LocalDateTime.of(Integer.MIN_VALUE, 7, 15, 12, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6ints_monthTooLow() { LocalDateTime.of(2007, 0, 15, 12, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6ints_monthTooHigh() { LocalDateTime.of(2007, 13, 15, 12, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6ints_dayTooLow() { LocalDateTime.of(2007, 7, -1, 12, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6ints_dayTooHigh() { LocalDateTime.of(2007, 7, 32, 12, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6ints_hourTooLow() { LocalDateTime.of(2007, 7, 15, -1, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6ints_hourTooHigh() { LocalDateTime.of(2007, 7, 15, 24, 30, 40); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6ints_minuteTooLow() { LocalDateTime.of(2007, 7, 15, 12, -1, 40); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6ints_minuteTooHigh() { LocalDateTime.of(2007, 7, 15, 12, 60, 40); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6ints_secondTooLow() { LocalDateTime.of(2007, 7, 15, 12, 30, -1); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_6ints_secondTooHigh() { LocalDateTime.of(2007, 7, 15, 12, 30, 60); } //----------------------------------------------------------------------- ! @Test public void factory_of_7ints() { LocalDateTime dateTime = LocalDateTime.of(2007, 7, 15, 12, 30, 40, 987654321); check(dateTime, 2007, 7, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_7ints_yearTooLow() { LocalDateTime.of(Integer.MIN_VALUE, 7, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_7ints_monthTooLow() { LocalDateTime.of(2007, 0, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_7ints_monthTooHigh() { LocalDateTime.of(2007, 13, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_7ints_dayTooLow() { LocalDateTime.of(2007, 7, -1, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_7ints_dayTooHigh() { LocalDateTime.of(2007, 7, 32, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_7ints_hourTooLow() { LocalDateTime.of(2007, 7, 15, -1, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_7ints_hourTooHigh() { LocalDateTime.of(2007, 7, 15, 24, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_7ints_minuteTooLow() { LocalDateTime.of(2007, 7, 15, 12, -1, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_7ints_minuteTooHigh() { LocalDateTime.of(2007, 7, 15, 12, 60, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_7ints_secondTooLow() { LocalDateTime.of(2007, 7, 15, 12, 30, -1, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_7ints_secondTooHigh() { LocalDateTime.of(2007, 7, 15, 12, 30, 60, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_7ints_nanoTooLow() { LocalDateTime.of(2007, 7, 15, 12, 30, 40, -1); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_of_7ints_nanoTooHigh() { LocalDateTime.of(2007, 7, 15, 12, 30, 40, 1000000000); } //----------------------------------------------------------------------- ! @Test public void factory_of_LocalDate_LocalTime() { LocalDateTime dateTime = LocalDateTime.of(LocalDate.of(2007, 7, 15), LocalTime.of(12, 30, 40, 987654321)); check(dateTime, 2007, 7, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=NullPointerException.class) public void factory_of_LocalDate_LocalTime_nullLocalDate() { LocalDateTime.of(null, LocalTime.of(12, 30, 40, 987654321)); } ! @Test(expectedExceptions=NullPointerException.class) public void factory_of_LocalDate_LocalTime_nullLocalTime() { LocalDateTime.of(LocalDate.of(2007, 7, 15), null); } //-----------------------------------------------------------------------
*** 788,887 **** public void factory_ofInstant(Instant instant, ZoneId zone, LocalDateTime expected) { LocalDateTime test = LocalDateTime.ofInstant(instant, zone); assertEquals(test, expected); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_ofInstant_instantTooBig() { LocalDateTime.ofInstant(Instant.MAX, OFFSET_PONE) ; } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_ofInstant_instantTooSmall() { LocalDateTime.ofInstant(Instant.MIN, OFFSET_PONE) ; } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void factory_ofInstant_nullInstant() { LocalDateTime.ofInstant((Instant) null, ZONE_GAZA); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void factory_ofInstant_nullZone() { LocalDateTime.ofInstant(Instant.EPOCH, (ZoneId) null); } //----------------------------------------------------------------------- // ofEpochSecond() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void factory_ofEpochSecond_longOffset_afterEpoch() { LocalDateTime base = LocalDateTime.of(1970, 1, 1, 2, 0, 0, 500); for (int i = 0; i < 100000; i++) { LocalDateTime test = LocalDateTime.ofEpochSecond(i, 500, OFFSET_PTWO); assertEquals(test, base.plusSeconds(i)); } } ! @Test(groups={"tck"}) public void factory_ofEpochSecond_longOffset_beforeEpoch() { LocalDateTime base = LocalDateTime.of(1970, 1, 1, 2, 0, 0, 500); for (int i = 0; i < 100000; i++) { LocalDateTime test = LocalDateTime.ofEpochSecond(-i, 500, OFFSET_PTWO); assertEquals(test, base.minusSeconds(i)); } } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_ofEpochSecond_longOffset_tooBig() { LocalDateTime.ofEpochSecond(Long.MAX_VALUE, 500, OFFSET_PONE); // TODO: better test } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_ofEpochSecond_longOffset_tooSmall() { LocalDateTime.ofEpochSecond(Long.MIN_VALUE, 500, OFFSET_PONE); // TODO: better test } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_ofEpochSecond_badNanos_toBig() { LocalDateTime.ofEpochSecond(0, 1_000_000_000, OFFSET_PONE); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void factory_ofEpochSecond_badNanos_toSmall() { LocalDateTime.ofEpochSecond(0, -1, OFFSET_PONE); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void factory_ofEpochSecond_longOffset_nullOffset() { LocalDateTime.ofEpochSecond(0L, 500, null); } //----------------------------------------------------------------------- // from() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_from_TemporalAccessor() { LocalDateTime base = LocalDateTime.of(2007, 7, 15, 17, 30); assertEquals(LocalDateTime.from(base), base); assertEquals(LocalDateTime.from(ZonedDateTime.of(base, ZoneOffset.ofHours(2))), base); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_from_TemporalAccessor_invalid_noDerive() { LocalDateTime.from(LocalTime.of(12, 30)); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_from_TemporalAccessor_null() { LocalDateTime.from((TemporalAccessor) null); } //----------------------------------------------------------------------- // parse() //----------------------------------------------------------------------- ! @Test(dataProvider="sampleToString", groups={"tck"}) public void test_parse(int y, int month, int d, int h, int m, int s, int n, String text) { LocalDateTime t = LocalDateTime.parse(text); assertEquals(t.getYear(), y); assertEquals(t.getMonth().getValue(), month); assertEquals(t.getDayOfMonth(), d); --- 798,897 ---- public void factory_ofInstant(Instant instant, ZoneId zone, LocalDateTime expected) { LocalDateTime test = LocalDateTime.ofInstant(instant, zone); assertEquals(test, expected); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_ofInstant_instantTooBig() { LocalDateTime.ofInstant(Instant.MAX, OFFSET_PONE) ; } ! @Test(expectedExceptions=DateTimeException.class) public void factory_ofInstant_instantTooSmall() { LocalDateTime.ofInstant(Instant.MIN, OFFSET_PONE) ; } ! @Test(expectedExceptions=NullPointerException.class) public void factory_ofInstant_nullInstant() { LocalDateTime.ofInstant((Instant) null, ZONE_GAZA); } ! @Test(expectedExceptions=NullPointerException.class) public void factory_ofInstant_nullZone() { LocalDateTime.ofInstant(Instant.EPOCH, (ZoneId) null); } //----------------------------------------------------------------------- // ofEpochSecond() //----------------------------------------------------------------------- ! @Test public void factory_ofEpochSecond_longOffset_afterEpoch() { LocalDateTime base = LocalDateTime.of(1970, 1, 1, 2, 0, 0, 500); for (int i = 0; i < 100000; i++) { LocalDateTime test = LocalDateTime.ofEpochSecond(i, 500, OFFSET_PTWO); assertEquals(test, base.plusSeconds(i)); } } ! @Test public void factory_ofEpochSecond_longOffset_beforeEpoch() { LocalDateTime base = LocalDateTime.of(1970, 1, 1, 2, 0, 0, 500); for (int i = 0; i < 100000; i++) { LocalDateTime test = LocalDateTime.ofEpochSecond(-i, 500, OFFSET_PTWO); assertEquals(test, base.minusSeconds(i)); } } ! @Test(expectedExceptions=DateTimeException.class) public void factory_ofEpochSecond_longOffset_tooBig() { LocalDateTime.ofEpochSecond(Long.MAX_VALUE, 500, OFFSET_PONE); // TODO: better test } ! @Test(expectedExceptions=DateTimeException.class) public void factory_ofEpochSecond_longOffset_tooSmall() { LocalDateTime.ofEpochSecond(Long.MIN_VALUE, 500, OFFSET_PONE); // TODO: better test } ! @Test(expectedExceptions=DateTimeException.class) public void factory_ofEpochSecond_badNanos_toBig() { LocalDateTime.ofEpochSecond(0, 1_000_000_000, OFFSET_PONE); } ! @Test(expectedExceptions=DateTimeException.class) public void factory_ofEpochSecond_badNanos_toSmall() { LocalDateTime.ofEpochSecond(0, -1, OFFSET_PONE); } ! @Test(expectedExceptions=NullPointerException.class) public void factory_ofEpochSecond_longOffset_nullOffset() { LocalDateTime.ofEpochSecond(0L, 500, null); } //----------------------------------------------------------------------- // from() //----------------------------------------------------------------------- ! @Test public void test_from_TemporalAccessor() { LocalDateTime base = LocalDateTime.of(2007, 7, 15, 17, 30); assertEquals(LocalDateTime.from(base), base); assertEquals(LocalDateTime.from(ZonedDateTime.of(base, ZoneOffset.ofHours(2))), base); } ! @Test(expectedExceptions=DateTimeException.class) public void test_from_TemporalAccessor_invalid_noDerive() { LocalDateTime.from(LocalTime.of(12, 30)); } ! @Test(expectedExceptions=NullPointerException.class) public void test_from_TemporalAccessor_null() { LocalDateTime.from((TemporalAccessor) null); } //----------------------------------------------------------------------- // parse() //----------------------------------------------------------------------- ! @Test(dataProvider="sampleToString") public void test_parse(int y, int month, int d, int h, int m, int s, int n, String text) { LocalDateTime t = LocalDateTime.parse(text); assertEquals(t.getYear(), y); assertEquals(t.getMonth().getValue(), month); assertEquals(t.getDayOfMonth(), d);
*** 889,930 **** assertEquals(t.getMinute(), m); assertEquals(t.getSecond(), s); assertEquals(t.getNano(), n); } ! @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"}) public void factory_parse_illegalValue() { LocalDateTime.parse("2008-06-32T11:15"); } ! @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"}) public void factory_parse_invalidValue() { LocalDateTime.parse("2008-06-31T11:15"); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void factory_parse_nullText() { LocalDateTime.parse((String) null); } //----------------------------------------------------------------------- // parse(DateTimeFormatter) //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void factory_parse_formatter() { DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s"); LocalDateTime test = LocalDateTime.parse("2010 12 3 11 30 45", f); assertEquals(test, LocalDateTime.of(2010, 12, 3, 11, 30, 45)); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void factory_parse_formatter_nullText() { DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s"); LocalDateTime.parse((String) null, f); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void factory_parse_formatter_nullFormatter() { LocalDateTime.parse("ANY", null); } //----------------------------------------------------------------------- --- 899,940 ---- assertEquals(t.getMinute(), m); assertEquals(t.getSecond(), s); assertEquals(t.getNano(), n); } ! @Test(expectedExceptions=DateTimeParseException.class) public void factory_parse_illegalValue() { LocalDateTime.parse("2008-06-32T11:15"); } ! @Test(expectedExceptions=DateTimeParseException.class) public void factory_parse_invalidValue() { LocalDateTime.parse("2008-06-31T11:15"); } ! @Test(expectedExceptions=NullPointerException.class) public void factory_parse_nullText() { LocalDateTime.parse((String) null); } //----------------------------------------------------------------------- // parse(DateTimeFormatter) //----------------------------------------------------------------------- ! @Test public void factory_parse_formatter() { DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s"); LocalDateTime test = LocalDateTime.parse("2010 12 3 11 30 45", f); assertEquals(test, LocalDateTime.of(2010, 12, 3, 11, 30, 45)); } ! @Test(expectedExceptions=NullPointerException.class) public void factory_parse_formatter_nullText() { DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s"); LocalDateTime.parse((String) null, f); } ! @Test(expectedExceptions=NullPointerException.class) public void factory_parse_formatter_nullFormatter() { LocalDateTime.parse("ANY", null); } //-----------------------------------------------------------------------
*** 968,984 **** // query(TemporalQuery) //----------------------------------------------------------------------- @DataProvider(name="query") Object[][] data_query() { return new Object[][] { ! {TEST_2007_07_15_12_30_40_987654321, Queries.chronology(), IsoChronology.INSTANCE}, ! {TEST_2007_07_15_12_30_40_987654321, Queries.zoneId(), null}, ! {TEST_2007_07_15_12_30_40_987654321, Queries.precision(), ChronoUnit.NANOS}, ! {TEST_2007_07_15_12_30_40_987654321, Queries.zone(), null}, ! {TEST_2007_07_15_12_30_40_987654321, Queries.offset(), null}, ! {TEST_2007_07_15_12_30_40_987654321, Queries.localDate(), LocalDate.of(2007, 7, 15)}, ! {TEST_2007_07_15_12_30_40_987654321, Queries.localTime(), LocalTime.of(12, 30, 40, 987654321)}, }; } @Test(dataProvider="query") public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) { --- 978,994 ---- // query(TemporalQuery) //----------------------------------------------------------------------- @DataProvider(name="query") Object[][] data_query() { return new Object[][] { ! {TEST_2007_07_15_12_30_40_987654321, TemporalQuery.chronology(), IsoChronology.INSTANCE}, ! {TEST_2007_07_15_12_30_40_987654321, TemporalQuery.zoneId(), null}, ! {TEST_2007_07_15_12_30_40_987654321, TemporalQuery.precision(), ChronoUnit.NANOS}, ! {TEST_2007_07_15_12_30_40_987654321, TemporalQuery.zone(), null}, ! {TEST_2007_07_15_12_30_40_987654321, TemporalQuery.offset(), null}, ! {TEST_2007_07_15_12_30_40_987654321, TemporalQuery.localDate(), LocalDate.of(2007, 7, 15)}, ! {TEST_2007_07_15_12_30_40_987654321, TemporalQuery.localTime(), LocalTime.of(12, 30, 40, 987654321)}, }; } @Test(dataProvider="query") public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
*** 1031,1060 **** } //----------------------------------------------------------------------- // get*() //----------------------------------------------------------------------- ! @Test(dataProvider="sampleDates", groups={"tck"}) public void test_get_dates(int y, int m, int d) { LocalDateTime a = LocalDateTime.of(y, m, d, 12, 30); assertEquals(a.getYear(), y); assertEquals(a.getMonth(), Month.of(m)); assertEquals(a.getDayOfMonth(), d); } ! @Test(dataProvider="sampleDates", groups={"tck"}) public void test_getDOY(int y, int m, int d) { LocalDateTime a = LocalDateTime.of(y, m, d, 12 ,30); int total = 0; for (int i = 1; i < m; i++) { total += Month.of(i).length(isIsoLeap(y)); } int doy = total + d; assertEquals(a.getDayOfYear(), doy); } ! @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_get_times(int h, int m, int s, int ns) { LocalDateTime a = LocalDateTime.of(TEST_2007_07_15_12_30_40_987654321.toLocalDate(), LocalTime.of(h, m, s, ns)); assertEquals(a.getHour(), h); assertEquals(a.getMinute(), m); assertEquals(a.getSecond(), s); --- 1041,1070 ---- } //----------------------------------------------------------------------- // get*() //----------------------------------------------------------------------- ! @Test(dataProvider="sampleDates") public void test_get_dates(int y, int m, int d) { LocalDateTime a = LocalDateTime.of(y, m, d, 12, 30); assertEquals(a.getYear(), y); assertEquals(a.getMonth(), Month.of(m)); assertEquals(a.getDayOfMonth(), d); } ! @Test(dataProvider="sampleDates") public void test_getDOY(int y, int m, int d) { LocalDateTime a = LocalDateTime.of(y, m, d, 12 ,30); int total = 0; for (int i = 1; i < m; i++) { total += Month.of(i).length(isIsoLeap(y)); } int doy = total + d; assertEquals(a.getDayOfYear(), doy); } ! @Test(dataProvider="sampleTimes") public void test_get_times(int h, int m, int s, int ns) { LocalDateTime a = LocalDateTime.of(TEST_2007_07_15_12_30_40_987654321.toLocalDate(), LocalTime.of(h, m, s, ns)); assertEquals(a.getHour(), h); assertEquals(a.getMinute(), m); assertEquals(a.getSecond(), s);
*** 1062,1072 **** } //----------------------------------------------------------------------- // getDayOfWeek() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_getDayOfWeek() { DayOfWeek dow = DayOfWeek.MONDAY; for (Month month : Month.values()) { int length = month.length(false); for (int i = 1; i <= length; i++) { --- 1072,1082 ---- } //----------------------------------------------------------------------- // getDayOfWeek() //----------------------------------------------------------------------- ! @Test public void test_getDayOfWeek() { DayOfWeek dow = DayOfWeek.MONDAY; for (Month month : Month.values()) { int length = month.length(false); for (int i = 1; i <= length; i++) {
*** 1077,1089 **** } } } //----------------------------------------------------------------------- // with() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_with_adjustment() { final LocalDateTime sample = LocalDateTime.of(2012, 3, 4, 23, 5); TemporalAdjuster adjuster = new TemporalAdjuster() { @Override public Temporal adjustInto(Temporal dateTime) { --- 1087,1139 ---- } } } //----------------------------------------------------------------------- + // adjustInto(Temporal) + //----------------------------------------------------------------------- + @DataProvider(name="adjustInto") + Object[][] data_adjustInto() { + return new Object[][]{ + {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), LocalDateTime.of(2012, 3, 4, 23, 5, 0, 0), null}, + {LocalDateTime.of(2012, Month.MARCH, 4, 0, 0), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), LocalDateTime.of(2012, 3, 4, 0, 0), null}, + {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MAX, LocalDateTime.of(2012, 3, 4, 23, 5), null}, + {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MIN, LocalDateTime.of(2012, 3, 4, 23, 5), null}, + {LocalDateTime.MAX, LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MAX, null}, + {LocalDateTime.MIN, LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MIN, null}, + + {LocalDateTime.of(2012, 3, 4, 23, 5), OffsetDateTime.of(2210, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC), OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, ZoneOffset.UTC), null}, + {LocalDateTime.of(2012, 3, 4, 23, 5), OffsetDateTime.of(2210, 2, 2, 0, 0, 0, 0, OFFSET_PONE), OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null}, + {LocalDateTime.of(2012, 3, 4, 23, 5), ZonedDateTime.of(2210, 2, 2, 0, 0, 0, 0, ZONE_PARIS), ZonedDateTime.of(2012, 3, 4, 23, 5, 0, 0, ZONE_PARIS), null}, + + {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDate.of(2210, 2, 2), null, DateTimeException.class}, + {LocalDateTime.of(2012, 3, 4, 23, 5), LocalTime.of(22, 3, 0), null, DateTimeException.class}, + {LocalDateTime.of(2012, 3, 4, 23, 5), OffsetTime.of(22, 3, 0, 0, ZoneOffset.UTC), null, DateTimeException.class}, + {LocalDateTime.of(2012, 3, 4, 23, 5), null, null, NullPointerException.class}, + + }; + } + + @Test(dataProvider="adjustInto") + public void test_adjustInto(LocalDateTime test, Temporal temporal, Temporal expected, Class<?> expectedEx) { + if (expectedEx == null) { + Temporal result = test.adjustInto(temporal); + assertEquals(result, expected); + } else { + try { + Temporal result = test.adjustInto(temporal); + fail(); + } catch (Exception ex) { + assertTrue(expectedEx.isInstance(ex)); + } + } + } + + //----------------------------------------------------------------------- // with() //----------------------------------------------------------------------- ! @Test public void test_with_adjustment() { final LocalDateTime sample = LocalDateTime.of(2012, 3, 4, 23, 5); TemporalAdjuster adjuster = new TemporalAdjuster() { @Override public Temporal adjustInto(Temporal dateTime) {
*** 1091,1255 **** } }; assertEquals(TEST_2007_07_15_12_30_40_987654321.with(adjuster), sample); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_with_adjustment_null() { TEST_2007_07_15_12_30_40_987654321.with((TemporalAdjuster) null); } //----------------------------------------------------------------------- // withYear() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_withYear_int_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withYear(2008); check(t, 2008, 7, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_withYear_int_invalid() { TEST_2007_07_15_12_30_40_987654321.withYear(Year.MIN_VALUE - 1); } ! @Test(groups={"tck"}) public void test_withYear_int_adjustDay() { LocalDateTime t = LocalDateTime.of(2008, 2, 29, 12, 30).withYear(2007); LocalDateTime expected = LocalDateTime.of(2007, 2, 28, 12, 30); assertEquals(t, expected); } //----------------------------------------------------------------------- // withMonth() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_withMonth_int_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withMonth(1); check(t, 2007, 1, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_withMonth_int_invalid() { TEST_2007_07_15_12_30_40_987654321.withMonth(13); } ! @Test(groups={"tck"}) public void test_withMonth_int_adjustDay() { LocalDateTime t = LocalDateTime.of(2007, 12, 31, 12, 30).withMonth(11); LocalDateTime expected = LocalDateTime.of(2007, 11, 30, 12, 30); assertEquals(t, expected); } //----------------------------------------------------------------------- // withDayOfMonth() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_withDayOfMonth_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withDayOfMonth(1); check(t, 2007, 7, 1, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_withDayOfMonth_invalid() { LocalDateTime.of(2007, 11, 30, 12, 30).withDayOfMonth(32); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_withDayOfMonth_invalidCombination() { LocalDateTime.of(2007, 11, 30, 12, 30).withDayOfMonth(31); } //----------------------------------------------------------------------- // withDayOfYear(int) //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_withDayOfYear_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withDayOfYear(33); assertEquals(t, LocalDateTime.of(2007, 2, 2, 12, 30, 40, 987654321)); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_withDayOfYear_illegal() { TEST_2007_07_15_12_30_40_987654321.withDayOfYear(367); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_withDayOfYear_invalid() { TEST_2007_07_15_12_30_40_987654321.withDayOfYear(366); } //----------------------------------------------------------------------- // withHour() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_withHour_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321; for (int i = 0; i < 24; i++) { t = t.withHour(i); assertEquals(t.getHour(), i); } } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_withHour_hourTooLow() { TEST_2007_07_15_12_30_40_987654321.withHour(-1); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_withHour_hourTooHigh() { TEST_2007_07_15_12_30_40_987654321.withHour(24); } //----------------------------------------------------------------------- // withMinute() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_withMinute_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321; for (int i = 0; i < 60; i++) { t = t.withMinute(i); assertEquals(t.getMinute(), i); } } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_withMinute_minuteTooLow() { TEST_2007_07_15_12_30_40_987654321.withMinute(-1); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_withMinute_minuteTooHigh() { TEST_2007_07_15_12_30_40_987654321.withMinute(60); } //----------------------------------------------------------------------- // withSecond() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_withSecond_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321; for (int i = 0; i < 60; i++) { t = t.withSecond(i); assertEquals(t.getSecond(), i); } } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_withSecond_secondTooLow() { TEST_2007_07_15_12_30_40_987654321.withSecond(-1); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_withSecond_secondTooHigh() { TEST_2007_07_15_12_30_40_987654321.withSecond(60); } //----------------------------------------------------------------------- // withNano() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_withNanoOfSecond_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321; t = t.withNano(1); assertEquals(t.getNano(), 1); t = t.withNano(10); --- 1141,1305 ---- } }; assertEquals(TEST_2007_07_15_12_30_40_987654321.with(adjuster), sample); } ! @Test(expectedExceptions=NullPointerException.class) public void test_with_adjustment_null() { TEST_2007_07_15_12_30_40_987654321.with((TemporalAdjuster) null); } //----------------------------------------------------------------------- // withYear() //----------------------------------------------------------------------- ! @Test public void test_withYear_int_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withYear(2008); check(t, 2008, 7, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void test_withYear_int_invalid() { TEST_2007_07_15_12_30_40_987654321.withYear(Year.MIN_VALUE - 1); } ! @Test public void test_withYear_int_adjustDay() { LocalDateTime t = LocalDateTime.of(2008, 2, 29, 12, 30).withYear(2007); LocalDateTime expected = LocalDateTime.of(2007, 2, 28, 12, 30); assertEquals(t, expected); } //----------------------------------------------------------------------- // withMonth() //----------------------------------------------------------------------- ! @Test public void test_withMonth_int_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withMonth(1); check(t, 2007, 1, 15, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void test_withMonth_int_invalid() { TEST_2007_07_15_12_30_40_987654321.withMonth(13); } ! @Test public void test_withMonth_int_adjustDay() { LocalDateTime t = LocalDateTime.of(2007, 12, 31, 12, 30).withMonth(11); LocalDateTime expected = LocalDateTime.of(2007, 11, 30, 12, 30); assertEquals(t, expected); } //----------------------------------------------------------------------- // withDayOfMonth() //----------------------------------------------------------------------- ! @Test public void test_withDayOfMonth_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withDayOfMonth(1); check(t, 2007, 7, 1, 12, 30, 40, 987654321); } ! @Test(expectedExceptions=DateTimeException.class) public void test_withDayOfMonth_invalid() { LocalDateTime.of(2007, 11, 30, 12, 30).withDayOfMonth(32); } ! @Test(expectedExceptions=DateTimeException.class) public void test_withDayOfMonth_invalidCombination() { LocalDateTime.of(2007, 11, 30, 12, 30).withDayOfMonth(31); } //----------------------------------------------------------------------- // withDayOfYear(int) //----------------------------------------------------------------------- ! @Test public void test_withDayOfYear_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.withDayOfYear(33); assertEquals(t, LocalDateTime.of(2007, 2, 2, 12, 30, 40, 987654321)); } ! @Test(expectedExceptions=DateTimeException.class) public void test_withDayOfYear_illegal() { TEST_2007_07_15_12_30_40_987654321.withDayOfYear(367); } ! @Test(expectedExceptions=DateTimeException.class) public void test_withDayOfYear_invalid() { TEST_2007_07_15_12_30_40_987654321.withDayOfYear(366); } //----------------------------------------------------------------------- // withHour() //----------------------------------------------------------------------- ! @Test public void test_withHour_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321; for (int i = 0; i < 24; i++) { t = t.withHour(i); assertEquals(t.getHour(), i); } } ! @Test(expectedExceptions=DateTimeException.class) public void test_withHour_hourTooLow() { TEST_2007_07_15_12_30_40_987654321.withHour(-1); } ! @Test(expectedExceptions=DateTimeException.class) public void test_withHour_hourTooHigh() { TEST_2007_07_15_12_30_40_987654321.withHour(24); } //----------------------------------------------------------------------- // withMinute() //----------------------------------------------------------------------- ! @Test public void test_withMinute_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321; for (int i = 0; i < 60; i++) { t = t.withMinute(i); assertEquals(t.getMinute(), i); } } ! @Test(expectedExceptions=DateTimeException.class) public void test_withMinute_minuteTooLow() { TEST_2007_07_15_12_30_40_987654321.withMinute(-1); } ! @Test(expectedExceptions=DateTimeException.class) public void test_withMinute_minuteTooHigh() { TEST_2007_07_15_12_30_40_987654321.withMinute(60); } //----------------------------------------------------------------------- // withSecond() //----------------------------------------------------------------------- ! @Test public void test_withSecond_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321; for (int i = 0; i < 60; i++) { t = t.withSecond(i); assertEquals(t.getSecond(), i); } } ! @Test(expectedExceptions=DateTimeException.class) public void test_withSecond_secondTooLow() { TEST_2007_07_15_12_30_40_987654321.withSecond(-1); } ! @Test(expectedExceptions=DateTimeException.class) public void test_withSecond_secondTooHigh() { TEST_2007_07_15_12_30_40_987654321.withSecond(60); } //----------------------------------------------------------------------- // withNano() //----------------------------------------------------------------------- ! @Test public void test_withNanoOfSecond_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321; t = t.withNano(1); assertEquals(t.getNano(), 1); t = t.withNano(10);
*** 1258,1288 **** assertEquals(t.getNano(), 100); t = t.withNano(999999999); assertEquals(t.getNano(), 999999999); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_withNanoOfSecond_nanoTooLow() { TEST_2007_07_15_12_30_40_987654321.withNano(-1); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_withNanoOfSecond_nanoTooHigh() { TEST_2007_07_15_12_30_40_987654321.withNano(1000000000); } //----------------------------------------------------------------------- // truncatedTo(TemporalUnit) //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_truncatedTo_normal() { assertEquals(TEST_2007_07_15_12_30_40_987654321.truncatedTo(NANOS), TEST_2007_07_15_12_30_40_987654321); assertEquals(TEST_2007_07_15_12_30_40_987654321.truncatedTo(SECONDS), TEST_2007_07_15_12_30_40_987654321.withNano(0)); assertEquals(TEST_2007_07_15_12_30_40_987654321.truncatedTo(DAYS), TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT)); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_truncatedTo_null() { TEST_2007_07_15_12_30_40_987654321.truncatedTo(null); } //----------------------------------------------------------------------- --- 1308,1338 ---- assertEquals(t.getNano(), 100); t = t.withNano(999999999); assertEquals(t.getNano(), 999999999); } ! @Test(expectedExceptions=DateTimeException.class) public void test_withNanoOfSecond_nanoTooLow() { TEST_2007_07_15_12_30_40_987654321.withNano(-1); } ! @Test(expectedExceptions=DateTimeException.class) public void test_withNanoOfSecond_nanoTooHigh() { TEST_2007_07_15_12_30_40_987654321.withNano(1000000000); } //----------------------------------------------------------------------- // truncatedTo(TemporalUnit) //----------------------------------------------------------------------- ! @Test public void test_truncatedTo_normal() { assertEquals(TEST_2007_07_15_12_30_40_987654321.truncatedTo(NANOS), TEST_2007_07_15_12_30_40_987654321); assertEquals(TEST_2007_07_15_12_30_40_987654321.truncatedTo(SECONDS), TEST_2007_07_15_12_30_40_987654321.withNano(0)); assertEquals(TEST_2007_07_15_12_30_40_987654321.truncatedTo(DAYS), TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT)); } ! @Test(expectedExceptions=NullPointerException.class) public void test_truncatedTo_null() { TEST_2007_07_15_12_30_40_987654321.truncatedTo(null); } //-----------------------------------------------------------------------
*** 1320,1438 **** } //----------------------------------------------------------------------- // plus(long,TemporalUnit) //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_plus_longTemporalUnit_positiveMonths() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(7, ChronoUnit.MONTHS); assertEquals(t, LocalDateTime.of(2008, 2, 15, 12, 30, 40, 987654321)); } ! @Test(groups={"tck"}) public void test_plus_longTemporalUnit_negativeDays() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(-25, ChronoUnit.DAYS); assertEquals(t, LocalDateTime.of(2007, 6, 20, 12, 30, 40, 987654321)); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_plus_longTemporalUnit_null() { TEST_2007_07_15_12_30_40_987654321.plus(1, (TemporalUnit) null); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_plus_longTemporalUnit_invalidTooLarge() { LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).plus(1, ChronoUnit.YEARS); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_plus_longTemporalUnit_invalidTooSmall() { LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).plus(-1, ChronoUnit.YEARS); } //----------------------------------------------------------------------- // plusYears() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_plusYears_int_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(1); check(t, 2008, 7, 15, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusYears_int_negative() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(-1); check(t, 2006, 7, 15, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusYears_int_adjustDay() { LocalDateTime t = createDateMidnight(2008, 2, 29).plusYears(1); check(t, 2009, 2, 28, 0, 0, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_plusYears_int_invalidTooLarge() { createDateMidnight(Year.MAX_VALUE, 1, 1).plusYears(1); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_plusYears_int_invalidTooSmall() { LocalDate.of(Year.MIN_VALUE, 1, 1).plusYears(-1); } //----------------------------------------------------------------------- // plusMonths() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_plusMonths_int_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(1); check(t, 2007, 8, 15, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusMonths_int_overYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(25); check(t, 2009, 8, 15, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusMonths_int_negative() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(-1); check(t, 2007, 6, 15, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusMonths_int_negativeAcrossYear() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(-7); check(t, 2006, 12, 15, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusMonths_int_negativeOverYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(-31); check(t, 2004, 12, 15, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusMonths_int_adjustDayFromLeapYear() { LocalDateTime t = createDateMidnight(2008, 2, 29).plusMonths(12); check(t, 2009, 2, 28, 0, 0, 0, 0); } ! @Test(groups={"tck"}) public void test_plusMonths_int_adjustDayFromMonthLength() { LocalDateTime t = createDateMidnight(2007, 3, 31).plusMonths(1); check(t, 2007, 4, 30, 0, 0, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_plusMonths_int_invalidTooLarge() { createDateMidnight(Year.MAX_VALUE, 12, 1).plusMonths(1); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_plusMonths_int_invalidTooSmall() { createDateMidnight(Year.MIN_VALUE, 1, 1).plusMonths(-1); } //----------------------------------------------------------------------- --- 1370,1488 ---- } //----------------------------------------------------------------------- // plus(long,TemporalUnit) //----------------------------------------------------------------------- ! @Test public void test_plus_longTemporalUnit_positiveMonths() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(7, ChronoUnit.MONTHS); assertEquals(t, LocalDateTime.of(2008, 2, 15, 12, 30, 40, 987654321)); } ! @Test public void test_plus_longTemporalUnit_negativeDays() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(-25, ChronoUnit.DAYS); assertEquals(t, LocalDateTime.of(2007, 6, 20, 12, 30, 40, 987654321)); } ! @Test(expectedExceptions=NullPointerException.class) public void test_plus_longTemporalUnit_null() { TEST_2007_07_15_12_30_40_987654321.plus(1, (TemporalUnit) null); } ! @Test(expectedExceptions=DateTimeException.class) public void test_plus_longTemporalUnit_invalidTooLarge() { LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).plus(1, ChronoUnit.YEARS); } ! @Test(expectedExceptions=DateTimeException.class) public void test_plus_longTemporalUnit_invalidTooSmall() { LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).plus(-1, ChronoUnit.YEARS); } //----------------------------------------------------------------------- // plusYears() //----------------------------------------------------------------------- ! @Test public void test_plusYears_int_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(1); check(t, 2008, 7, 15, 12, 30, 40, 987654321); } ! @Test public void test_plusYears_int_negative() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(-1); check(t, 2006, 7, 15, 12, 30, 40, 987654321); } ! @Test public void test_plusYears_int_adjustDay() { LocalDateTime t = createDateMidnight(2008, 2, 29).plusYears(1); check(t, 2009, 2, 28, 0, 0, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class) public void test_plusYears_int_invalidTooLarge() { createDateMidnight(Year.MAX_VALUE, 1, 1).plusYears(1); } ! @Test(expectedExceptions=DateTimeException.class) public void test_plusYears_int_invalidTooSmall() { LocalDate.of(Year.MIN_VALUE, 1, 1).plusYears(-1); } //----------------------------------------------------------------------- // plusMonths() //----------------------------------------------------------------------- ! @Test public void test_plusMonths_int_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(1); check(t, 2007, 8, 15, 12, 30, 40, 987654321); } ! @Test public void test_plusMonths_int_overYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(25); check(t, 2009, 8, 15, 12, 30, 40, 987654321); } ! @Test public void test_plusMonths_int_negative() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(-1); check(t, 2007, 6, 15, 12, 30, 40, 987654321); } ! @Test public void test_plusMonths_int_negativeAcrossYear() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(-7); check(t, 2006, 12, 15, 12, 30, 40, 987654321); } ! @Test public void test_plusMonths_int_negativeOverYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMonths(-31); check(t, 2004, 12, 15, 12, 30, 40, 987654321); } ! @Test public void test_plusMonths_int_adjustDayFromLeapYear() { LocalDateTime t = createDateMidnight(2008, 2, 29).plusMonths(12); check(t, 2009, 2, 28, 0, 0, 0, 0); } ! @Test public void test_plusMonths_int_adjustDayFromMonthLength() { LocalDateTime t = createDateMidnight(2007, 3, 31).plusMonths(1); check(t, 2007, 4, 30, 0, 0, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class) public void test_plusMonths_int_invalidTooLarge() { createDateMidnight(Year.MAX_VALUE, 12, 1).plusMonths(1); } ! @Test(expectedExceptions=DateTimeException.class) public void test_plusMonths_int_invalidTooSmall() { createDateMidnight(Year.MIN_VALUE, 1, 1).plusMonths(-1); } //-----------------------------------------------------------------------
*** 1468,1548 **** {createDateMidnight(2100, 3, 1)}, {createDateMidnight(2100, 12, 31)}, }; } ! @Test(dataProvider="samplePlusWeeksSymmetry", groups={"tck"}) public void test_plusWeeks_symmetry(LocalDateTime reference) { for (int weeks = 0; weeks < 365 * 8; weeks++) { LocalDateTime t = reference.plusWeeks(weeks).plusWeeks(-weeks); assertEquals(t, reference); t = reference.plusWeeks(-weeks).plusWeeks(weeks); assertEquals(t, reference); } } ! @Test(groups={"tck"}) public void test_plusWeeks_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(1); check(t, 2007, 7, 22, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusWeeks_overMonths() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(9); check(t, 2007, 9, 16, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusWeeks_overYears() { LocalDateTime t = LocalDateTime.of(2006, 7, 16, 12, 30, 40, 987654321).plusWeeks(52); assertEquals(t, TEST_2007_07_15_12_30_40_987654321); } ! @Test(groups={"tck"}) public void test_plusWeeks_overLeapYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(-1).plusWeeks(104); check(t, 2008, 7, 12, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusWeeks_negative() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(-1); check(t, 2007, 7, 8, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusWeeks_negativeAcrossYear() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(-28); check(t, 2006, 12, 31, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusWeeks_negativeOverYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(-104); check(t, 2005, 7, 17, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusWeeks_maximum() { LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 24).plusWeeks(1); check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0); } ! @Test(groups={"tck"}) public void test_plusWeeks_minimum() { LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 8).plusWeeks(-1); check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_plusWeeks_invalidTooLarge() { createDateMidnight(Year.MAX_VALUE, 12, 25).plusWeeks(1); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_plusWeeks_invalidTooSmall() { createDateMidnight(Year.MIN_VALUE, 1, 7).plusWeeks(-1); } //----------------------------------------------------------------------- --- 1518,1598 ---- {createDateMidnight(2100, 3, 1)}, {createDateMidnight(2100, 12, 31)}, }; } ! @Test(dataProvider="samplePlusWeeksSymmetry") public void test_plusWeeks_symmetry(LocalDateTime reference) { for (int weeks = 0; weeks < 365 * 8; weeks++) { LocalDateTime t = reference.plusWeeks(weeks).plusWeeks(-weeks); assertEquals(t, reference); t = reference.plusWeeks(-weeks).plusWeeks(weeks); assertEquals(t, reference); } } ! @Test public void test_plusWeeks_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(1); check(t, 2007, 7, 22, 12, 30, 40, 987654321); } ! @Test public void test_plusWeeks_overMonths() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(9); check(t, 2007, 9, 16, 12, 30, 40, 987654321); } ! @Test public void test_plusWeeks_overYears() { LocalDateTime t = LocalDateTime.of(2006, 7, 16, 12, 30, 40, 987654321).plusWeeks(52); assertEquals(t, TEST_2007_07_15_12_30_40_987654321); } ! @Test public void test_plusWeeks_overLeapYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(-1).plusWeeks(104); check(t, 2008, 7, 12, 12, 30, 40, 987654321); } ! @Test public void test_plusWeeks_negative() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(-1); check(t, 2007, 7, 8, 12, 30, 40, 987654321); } ! @Test public void test_plusWeeks_negativeAcrossYear() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(-28); check(t, 2006, 12, 31, 12, 30, 40, 987654321); } ! @Test public void test_plusWeeks_negativeOverYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusWeeks(-104); check(t, 2005, 7, 17, 12, 30, 40, 987654321); } ! @Test public void test_plusWeeks_maximum() { LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 24).plusWeeks(1); check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0); } ! @Test public void test_plusWeeks_minimum() { LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 8).plusWeeks(-1); check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class) public void test_plusWeeks_invalidTooLarge() { createDateMidnight(Year.MAX_VALUE, 12, 25).plusWeeks(1); } ! @Test(expectedExceptions=DateTimeException.class) public void test_plusWeeks_invalidTooSmall() { createDateMidnight(Year.MIN_VALUE, 1, 7).plusWeeks(-1); } //-----------------------------------------------------------------------
*** 1578,1676 **** {createDateMidnight(2100, 3, 1)}, {createDateMidnight(2100, 12, 31)}, }; } ! @Test(dataProvider="samplePlusDaysSymmetry", groups={"tck"}) public void test_plusDays_symmetry(LocalDateTime reference) { for (int days = 0; days < 365 * 8; days++) { LocalDateTime t = reference.plusDays(days).plusDays(-days); assertEquals(t, reference); t = reference.plusDays(-days).plusDays(days); assertEquals(t, reference); } } ! @Test(groups={"tck"}) public void test_plusDays_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(1); check(t, 2007, 7, 16, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusDays_overMonths() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(62); check(t, 2007, 9, 15, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusDays_overYears() { LocalDateTime t = LocalDateTime.of(2006, 7, 14, 12, 30, 40, 987654321).plusDays(366); assertEquals(t, TEST_2007_07_15_12_30_40_987654321); } ! @Test(groups={"tck"}) public void test_plusDays_overLeapYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(-1).plusDays(365 + 366); check(t, 2008, 7, 15, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusDays_negative() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(-1); check(t, 2007, 7, 14, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusDays_negativeAcrossYear() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(-196); check(t, 2006, 12, 31, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusDays_negativeOverYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(-730); check(t, 2005, 7, 15, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_plusDays_maximum() { LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 30).plusDays(1); check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0); } ! @Test(groups={"tck"}) public void test_plusDays_minimum() { LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 2).plusDays(-1); check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_plusDays_invalidTooLarge() { createDateMidnight(Year.MAX_VALUE, 12, 31).plusDays(1); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_plusDays_invalidTooSmall() { createDateMidnight(Year.MIN_VALUE, 1, 1).plusDays(-1); } ! @Test(expectedExceptions=ArithmeticException.class, groups={"tck"}) public void test_plusDays_overflowTooLarge() { createDateMidnight(Year.MAX_VALUE, 12, 31).plusDays(Long.MAX_VALUE); } ! @Test(expectedExceptions=ArithmeticException.class, groups={"tck"}) public void test_plusDays_overflowTooSmall() { createDateMidnight(Year.MIN_VALUE, 1, 1).plusDays(Long.MIN_VALUE); } //----------------------------------------------------------------------- // plusHours() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_plusHours_one() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); for (int i = 0; i < 50; i++) { --- 1628,1726 ---- {createDateMidnight(2100, 3, 1)}, {createDateMidnight(2100, 12, 31)}, }; } ! @Test(dataProvider="samplePlusDaysSymmetry") public void test_plusDays_symmetry(LocalDateTime reference) { for (int days = 0; days < 365 * 8; days++) { LocalDateTime t = reference.plusDays(days).plusDays(-days); assertEquals(t, reference); t = reference.plusDays(-days).plusDays(days); assertEquals(t, reference); } } ! @Test public void test_plusDays_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(1); check(t, 2007, 7, 16, 12, 30, 40, 987654321); } ! @Test public void test_plusDays_overMonths() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(62); check(t, 2007, 9, 15, 12, 30, 40, 987654321); } ! @Test public void test_plusDays_overYears() { LocalDateTime t = LocalDateTime.of(2006, 7, 14, 12, 30, 40, 987654321).plusDays(366); assertEquals(t, TEST_2007_07_15_12_30_40_987654321); } ! @Test public void test_plusDays_overLeapYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(-1).plusDays(365 + 366); check(t, 2008, 7, 15, 12, 30, 40, 987654321); } ! @Test public void test_plusDays_negative() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(-1); check(t, 2007, 7, 14, 12, 30, 40, 987654321); } ! @Test public void test_plusDays_negativeAcrossYear() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(-196); check(t, 2006, 12, 31, 12, 30, 40, 987654321); } ! @Test public void test_plusDays_negativeOverYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusDays(-730); check(t, 2005, 7, 15, 12, 30, 40, 987654321); } ! @Test public void test_plusDays_maximum() { LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 30).plusDays(1); check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0); } ! @Test public void test_plusDays_minimum() { LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 2).plusDays(-1); check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class) public void test_plusDays_invalidTooLarge() { createDateMidnight(Year.MAX_VALUE, 12, 31).plusDays(1); } ! @Test(expectedExceptions=DateTimeException.class) public void test_plusDays_invalidTooSmall() { createDateMidnight(Year.MIN_VALUE, 1, 1).plusDays(-1); } ! @Test(expectedExceptions=ArithmeticException.class) public void test_plusDays_overflowTooLarge() { createDateMidnight(Year.MAX_VALUE, 12, 31).plusDays(Long.MAX_VALUE); } ! @Test(expectedExceptions=ArithmeticException.class) public void test_plusDays_overflowTooSmall() { createDateMidnight(Year.MIN_VALUE, 1, 1).plusDays(Long.MIN_VALUE); } //----------------------------------------------------------------------- // plusHours() //----------------------------------------------------------------------- ! @Test public void test_plusHours_one() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); for (int i = 0; i < 50; i++) {
*** 1683,1693 **** assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), (i + 1) % 24); } } ! @Test(groups={"tck"}) public void test_plusHours_fromZero() { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = base.toLocalDate().minusDays(3); LocalTime t = LocalTime.of(21, 0); --- 1733,1743 ---- assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), (i + 1) % 24); } } ! @Test public void test_plusHours_fromZero() { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = base.toLocalDate().minusDays(3); LocalTime t = LocalTime.of(21, 0);
*** 1702,1712 **** assertEquals(dt.toLocalDate(), d); assertEquals(dt.toLocalTime(), t); } } ! @Test(groups={"tck"}) public void test_plusHours_fromOne() { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0)); LocalDate d = base.toLocalDate().minusDays(3); LocalTime t = LocalTime.of(22, 0); --- 1752,1762 ---- assertEquals(dt.toLocalDate(), d); assertEquals(dt.toLocalTime(), t); } } ! @Test public void test_plusHours_fromOne() { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0)); LocalDate d = base.toLocalDate().minusDays(3); LocalTime t = LocalTime.of(22, 0);
*** 1725,1735 **** } //----------------------------------------------------------------------- // plusMinutes() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_plusMinutes_one() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); int hour = 0; --- 1775,1785 ---- } //----------------------------------------------------------------------- // plusMinutes() //----------------------------------------------------------------------- ! @Test public void test_plusMinutes_one() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); int hour = 0;
*** 1747,1757 **** assertEquals(t.getHour(), hour); assertEquals(t.getMinute(), min); } } ! @Test(groups={"tck"}) public void test_plusMinutes_fromZero() { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = base.toLocalDate().minusDays(1); LocalTime t = LocalTime.of(22, 49); --- 1797,1807 ---- assertEquals(t.getHour(), hour); assertEquals(t.getMinute(), min); } } ! @Test public void test_plusMinutes_fromZero() { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = base.toLocalDate().minusDays(1); LocalTime t = LocalTime.of(22, 49);
*** 1766,1785 **** assertEquals(dt.toLocalDate(), d, String.valueOf(i)); assertEquals(dt.toLocalTime(), t, String.valueOf(i)); } } ! @Test(groups={"tck"}) public void test_plusMinutes_noChange_oneDay() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMinutes(24 * 60); assertEquals(t.toLocalDate(), TEST_2007_07_15_12_30_40_987654321.toLocalDate().plusDays(1)); } //----------------------------------------------------------------------- // plusSeconds() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_plusSeconds_one() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); int hour = 0; --- 1816,1835 ---- assertEquals(dt.toLocalDate(), d, String.valueOf(i)); assertEquals(dt.toLocalTime(), t, String.valueOf(i)); } } ! @Test public void test_plusMinutes_noChange_oneDay() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMinutes(24 * 60); assertEquals(t.toLocalDate(), TEST_2007_07_15_12_30_40_987654321.toLocalDate().plusDays(1)); } //----------------------------------------------------------------------- // plusSeconds() //----------------------------------------------------------------------- ! @Test public void test_plusSeconds_one() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); int hour = 0;
*** 1850,1880 **** throw new UnsupportedOperationException(); } }; } ! @Test(dataProvider="plusSeconds_fromZero", groups={"tck"}) public void test_plusSeconds_fromZero(int seconds, LocalDate date, int hour, int min, int sec) { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDateTime t = base.plusSeconds(seconds); assertEquals(date, t.toLocalDate()); assertEquals(hour, t.getHour()); assertEquals(min, t.getMinute()); assertEquals(sec, t.getSecond()); } ! @Test(groups={"tck"}) public void test_plusSeconds_noChange_oneDay() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusSeconds(24 * 60 * 60); assertEquals(t.toLocalDate(), TEST_2007_07_15_12_30_40_987654321.toLocalDate().plusDays(1)); } //----------------------------------------------------------------------- // plusNanos() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_plusNanos_halfABillion() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); int hour = 0; --- 1900,1930 ---- throw new UnsupportedOperationException(); } }; } ! @Test(dataProvider="plusSeconds_fromZero") public void test_plusSeconds_fromZero(int seconds, LocalDate date, int hour, int min, int sec) { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDateTime t = base.plusSeconds(seconds); assertEquals(date, t.toLocalDate()); assertEquals(hour, t.getHour()); assertEquals(min, t.getMinute()); assertEquals(sec, t.getSecond()); } ! @Test public void test_plusSeconds_noChange_oneDay() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusSeconds(24 * 60 * 60); assertEquals(t.toLocalDate(), TEST_2007_07_15_12_30_40_987654321.toLocalDate().plusDays(1)); } //----------------------------------------------------------------------- // plusNanos() //----------------------------------------------------------------------- ! @Test public void test_plusNanos_halfABillion() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); int hour = 0;
*** 1954,1964 **** throw new UnsupportedOperationException(); } }; } ! @Test(dataProvider="plusNanos_fromZero", groups={"tck"}) public void test_plusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDateTime t = base.plusNanos(nanoseconds); assertEquals(date, t.toLocalDate()); --- 2004,2014 ---- throw new UnsupportedOperationException(); } }; } ! @Test(dataProvider="plusNanos_fromZero") public void test_plusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDateTime t = base.plusNanos(nanoseconds); assertEquals(date, t.toLocalDate());
*** 1966,1976 **** assertEquals(min, t.getMinute()); assertEquals(sec, t.getSecond()); assertEquals(nanos, t.getNano()); } ! @Test(groups={"tck"}) public void test_plusNanos_noChange_oneDay() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusNanos(24 * 60 * 60 * 1000000000L); assertEquals(t.toLocalDate(), TEST_2007_07_15_12_30_40_987654321.toLocalDate().plusDays(1)); } --- 2016,2026 ---- assertEquals(min, t.getMinute()); assertEquals(sec, t.getSecond()); assertEquals(nanos, t.getNano()); } ! @Test public void test_plusNanos_noChange_oneDay() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusNanos(24 * 60 * 60 * 1000000000L); assertEquals(t.toLocalDate(), TEST_2007_07_15_12_30_40_987654321.toLocalDate().plusDays(1)); }
*** 2009,2127 **** } //----------------------------------------------------------------------- // minus(long,TemporalUnit) //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_minus_longTemporalUnit_positiveMonths() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(7, ChronoUnit.MONTHS); assertEquals(t, LocalDateTime.of(2006, 12, 15, 12, 30, 40, 987654321)); } ! @Test(groups={"tck"}) public void test_minus_longTemporalUnit_negativeDays() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(-25, ChronoUnit.DAYS); assertEquals(t, LocalDateTime.of(2007, 8, 9, 12, 30, 40, 987654321)); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_minus_longTemporalUnit_null() { TEST_2007_07_15_12_30_40_987654321.minus(1, (TemporalUnit) null); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_minus_longTemporalUnit_invalidTooLarge() { LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).minus(-1, ChronoUnit.YEARS); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_minus_longTemporalUnit_invalidTooSmall() { LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).minus(1, ChronoUnit.YEARS); } //----------------------------------------------------------------------- // minusYears() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_minusYears_int_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusYears(1); check(t, 2006, 7, 15, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_minusYears_int_negative() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusYears(-1); check(t, 2008, 7, 15, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_minusYears_int_adjustDay() { LocalDateTime t = createDateMidnight(2008, 2, 29).minusYears(1); check(t, 2007, 2, 28, 0, 0, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_minusYears_int_invalidTooLarge() { createDateMidnight(Year.MAX_VALUE, 1, 1).minusYears(-1); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_minusYears_int_invalidTooSmall() { createDateMidnight(Year.MIN_VALUE, 1, 1).minusYears(1); } //----------------------------------------------------------------------- // minusMonths() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_minusMonths_int_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(1); check(t, 2007, 6, 15, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_minusMonths_int_overYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(25); check(t, 2005, 6, 15, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_minusMonths_int_negative() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(-1); check(t, 2007, 8, 15, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_minusMonths_int_negativeAcrossYear() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(-7); check(t, 2008, 2, 15, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_minusMonths_int_negativeOverYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(-31); check(t, 2010, 2, 15, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_minusMonths_int_adjustDayFromLeapYear() { LocalDateTime t = createDateMidnight(2008, 2, 29).minusMonths(12); check(t, 2007, 2, 28, 0, 0, 0, 0); } ! @Test(groups={"tck"}) public void test_minusMonths_int_adjustDayFromMonthLength() { LocalDateTime t = createDateMidnight(2007, 3, 31).minusMonths(1); check(t, 2007, 2, 28, 0, 0, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_minusMonths_int_invalidTooLarge() { createDateMidnight(Year.MAX_VALUE, 12, 1).minusMonths(-1); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_minusMonths_int_invalidTooSmall() { createDateMidnight(Year.MIN_VALUE, 1, 1).minusMonths(1); } //----------------------------------------------------------------------- --- 2059,2177 ---- } //----------------------------------------------------------------------- // minus(long,TemporalUnit) //----------------------------------------------------------------------- ! @Test public void test_minus_longTemporalUnit_positiveMonths() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(7, ChronoUnit.MONTHS); assertEquals(t, LocalDateTime.of(2006, 12, 15, 12, 30, 40, 987654321)); } ! @Test public void test_minus_longTemporalUnit_negativeDays() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(-25, ChronoUnit.DAYS); assertEquals(t, LocalDateTime.of(2007, 8, 9, 12, 30, 40, 987654321)); } ! @Test(expectedExceptions=NullPointerException.class) public void test_minus_longTemporalUnit_null() { TEST_2007_07_15_12_30_40_987654321.minus(1, (TemporalUnit) null); } ! @Test(expectedExceptions=DateTimeException.class) public void test_minus_longTemporalUnit_invalidTooLarge() { LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).minus(-1, ChronoUnit.YEARS); } ! @Test(expectedExceptions=DateTimeException.class) public void test_minus_longTemporalUnit_invalidTooSmall() { LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).minus(1, ChronoUnit.YEARS); } //----------------------------------------------------------------------- // minusYears() //----------------------------------------------------------------------- ! @Test public void test_minusYears_int_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusYears(1); check(t, 2006, 7, 15, 12, 30, 40, 987654321); } ! @Test public void test_minusYears_int_negative() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusYears(-1); check(t, 2008, 7, 15, 12, 30, 40, 987654321); } ! @Test public void test_minusYears_int_adjustDay() { LocalDateTime t = createDateMidnight(2008, 2, 29).minusYears(1); check(t, 2007, 2, 28, 0, 0, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class) public void test_minusYears_int_invalidTooLarge() { createDateMidnight(Year.MAX_VALUE, 1, 1).minusYears(-1); } ! @Test(expectedExceptions=DateTimeException.class) public void test_minusYears_int_invalidTooSmall() { createDateMidnight(Year.MIN_VALUE, 1, 1).minusYears(1); } //----------------------------------------------------------------------- // minusMonths() //----------------------------------------------------------------------- ! @Test public void test_minusMonths_int_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(1); check(t, 2007, 6, 15, 12, 30, 40, 987654321); } ! @Test public void test_minusMonths_int_overYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(25); check(t, 2005, 6, 15, 12, 30, 40, 987654321); } ! @Test public void test_minusMonths_int_negative() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(-1); check(t, 2007, 8, 15, 12, 30, 40, 987654321); } ! @Test public void test_minusMonths_int_negativeAcrossYear() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(-7); check(t, 2008, 2, 15, 12, 30, 40, 987654321); } ! @Test public void test_minusMonths_int_negativeOverYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMonths(-31); check(t, 2010, 2, 15, 12, 30, 40, 987654321); } ! @Test public void test_minusMonths_int_adjustDayFromLeapYear() { LocalDateTime t = createDateMidnight(2008, 2, 29).minusMonths(12); check(t, 2007, 2, 28, 0, 0, 0, 0); } ! @Test public void test_minusMonths_int_adjustDayFromMonthLength() { LocalDateTime t = createDateMidnight(2007, 3, 31).minusMonths(1); check(t, 2007, 2, 28, 0, 0, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class) public void test_minusMonths_int_invalidTooLarge() { createDateMidnight(Year.MAX_VALUE, 12, 1).minusMonths(-1); } ! @Test(expectedExceptions=DateTimeException.class) public void test_minusMonths_int_invalidTooSmall() { createDateMidnight(Year.MIN_VALUE, 1, 1).minusMonths(1); } //-----------------------------------------------------------------------
*** 2157,2237 **** {createDateMidnight(2100, 3, 1)}, {createDateMidnight(2100, 12, 31)}, }; } ! @Test(dataProvider="sampleMinusWeeksSymmetry", groups={"tck"}) public void test_minusWeeks_symmetry(LocalDateTime reference) { for (int weeks = 0; weeks < 365 * 8; weeks++) { LocalDateTime t = reference.minusWeeks(weeks).minusWeeks(-weeks); assertEquals(t, reference); t = reference.minusWeeks(-weeks).minusWeeks(weeks); assertEquals(t, reference); } } ! @Test(groups={"tck"}) public void test_minusWeeks_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(1); check(t, 2007, 7, 8, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_minusWeeks_overMonths() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(9); check(t, 2007, 5, 13, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_minusWeeks_overYears() { LocalDateTime t = LocalDateTime.of(2008, 7, 13, 12, 30, 40, 987654321).minusWeeks(52); assertEquals(t, TEST_2007_07_15_12_30_40_987654321); } ! @Test(groups={"tck"}) public void test_minusWeeks_overLeapYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusYears(-1).minusWeeks(104); check(t, 2006, 7, 18, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_minusWeeks_negative() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(-1); check(t, 2007, 7, 22, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_minusWeeks_negativeAcrossYear() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(-28); check(t, 2008, 1, 27, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_minusWeeks_negativeOverYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(-104); check(t, 2009, 7, 12, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_minusWeeks_maximum() { LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 24).minusWeeks(-1); check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0); } ! @Test(groups={"tck"}) public void test_minusWeeks_minimum() { LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 8).minusWeeks(1); check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_minusWeeks_invalidTooLarge() { createDateMidnight(Year.MAX_VALUE, 12, 25).minusWeeks(-1); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_minusWeeks_invalidTooSmall() { createDateMidnight(Year.MIN_VALUE, 1, 7).minusWeeks(1); } //----------------------------------------------------------------------- --- 2207,2287 ---- {createDateMidnight(2100, 3, 1)}, {createDateMidnight(2100, 12, 31)}, }; } ! @Test(dataProvider="sampleMinusWeeksSymmetry") public void test_minusWeeks_symmetry(LocalDateTime reference) { for (int weeks = 0; weeks < 365 * 8; weeks++) { LocalDateTime t = reference.minusWeeks(weeks).minusWeeks(-weeks); assertEquals(t, reference); t = reference.minusWeeks(-weeks).minusWeeks(weeks); assertEquals(t, reference); } } ! @Test public void test_minusWeeks_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(1); check(t, 2007, 7, 8, 12, 30, 40, 987654321); } ! @Test public void test_minusWeeks_overMonths() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(9); check(t, 2007, 5, 13, 12, 30, 40, 987654321); } ! @Test public void test_minusWeeks_overYears() { LocalDateTime t = LocalDateTime.of(2008, 7, 13, 12, 30, 40, 987654321).minusWeeks(52); assertEquals(t, TEST_2007_07_15_12_30_40_987654321); } ! @Test public void test_minusWeeks_overLeapYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusYears(-1).minusWeeks(104); check(t, 2006, 7, 18, 12, 30, 40, 987654321); } ! @Test public void test_minusWeeks_negative() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(-1); check(t, 2007, 7, 22, 12, 30, 40, 987654321); } ! @Test public void test_minusWeeks_negativeAcrossYear() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(-28); check(t, 2008, 1, 27, 12, 30, 40, 987654321); } ! @Test public void test_minusWeeks_negativeOverYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusWeeks(-104); check(t, 2009, 7, 12, 12, 30, 40, 987654321); } ! @Test public void test_minusWeeks_maximum() { LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 24).minusWeeks(-1); check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0); } ! @Test public void test_minusWeeks_minimum() { LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 8).minusWeeks(1); check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class) public void test_minusWeeks_invalidTooLarge() { createDateMidnight(Year.MAX_VALUE, 12, 25).minusWeeks(-1); } ! @Test(expectedExceptions=DateTimeException.class) public void test_minusWeeks_invalidTooSmall() { createDateMidnight(Year.MIN_VALUE, 1, 7).minusWeeks(1); } //-----------------------------------------------------------------------
*** 2267,2365 **** {createDateMidnight(2100, 3, 1)}, {createDateMidnight(2100, 12, 31)}, }; } ! @Test(dataProvider="sampleMinusDaysSymmetry", groups={"tck"}) public void test_minusDays_symmetry(LocalDateTime reference) { for (int days = 0; days < 365 * 8; days++) { LocalDateTime t = reference.minusDays(days).minusDays(-days); assertEquals(t, reference); t = reference.minusDays(-days).minusDays(days); assertEquals(t, reference); } } ! @Test(groups={"tck"}) public void test_minusDays_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(1); check(t, 2007, 7, 14, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_minusDays_overMonths() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(62); check(t, 2007, 5, 14, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_minusDays_overYears() { LocalDateTime t = LocalDateTime.of(2008, 7, 16, 12, 30, 40, 987654321).minusDays(367); assertEquals(t, TEST_2007_07_15_12_30_40_987654321); } ! @Test(groups={"tck"}) public void test_minusDays_overLeapYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(2).minusDays(365 + 366); assertEquals(t, TEST_2007_07_15_12_30_40_987654321); } ! @Test(groups={"tck"}) public void test_minusDays_negative() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(-1); check(t, 2007, 7, 16, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_minusDays_negativeAcrossYear() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(-169); check(t, 2007, 12, 31, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_minusDays_negativeOverYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(-731); check(t, 2009, 7, 15, 12, 30, 40, 987654321); } ! @Test(groups={"tck"}) public void test_minusDays_maximum() { LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 30).minusDays(-1); check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0); } ! @Test(groups={"tck"}) public void test_minusDays_minimum() { LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 2).minusDays(1); check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_minusDays_invalidTooLarge() { createDateMidnight(Year.MAX_VALUE, 12, 31).minusDays(-1); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) public void test_minusDays_invalidTooSmall() { createDateMidnight(Year.MIN_VALUE, 1, 1).minusDays(1); } ! @Test(expectedExceptions=ArithmeticException.class, groups={"tck"}) public void test_minusDays_overflowTooLarge() { createDateMidnight(Year.MAX_VALUE, 12, 31).minusDays(Long.MIN_VALUE); } ! @Test(expectedExceptions=ArithmeticException.class, groups={"tck"}) public void test_minusDays_overflowTooSmall() { createDateMidnight(Year.MIN_VALUE, 1, 1).minusDays(Long.MAX_VALUE); } //----------------------------------------------------------------------- // minusHours() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_minusHours_one() { LocalDateTime t =TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); for (int i = 0; i < 50; i++) { --- 2317,2415 ---- {createDateMidnight(2100, 3, 1)}, {createDateMidnight(2100, 12, 31)}, }; } ! @Test(dataProvider="sampleMinusDaysSymmetry") public void test_minusDays_symmetry(LocalDateTime reference) { for (int days = 0; days < 365 * 8; days++) { LocalDateTime t = reference.minusDays(days).minusDays(-days); assertEquals(t, reference); t = reference.minusDays(-days).minusDays(days); assertEquals(t, reference); } } ! @Test public void test_minusDays_normal() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(1); check(t, 2007, 7, 14, 12, 30, 40, 987654321); } ! @Test public void test_minusDays_overMonths() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(62); check(t, 2007, 5, 14, 12, 30, 40, 987654321); } ! @Test public void test_minusDays_overYears() { LocalDateTime t = LocalDateTime.of(2008, 7, 16, 12, 30, 40, 987654321).minusDays(367); assertEquals(t, TEST_2007_07_15_12_30_40_987654321); } ! @Test public void test_minusDays_overLeapYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusYears(2).minusDays(365 + 366); assertEquals(t, TEST_2007_07_15_12_30_40_987654321); } ! @Test public void test_minusDays_negative() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(-1); check(t, 2007, 7, 16, 12, 30, 40, 987654321); } ! @Test public void test_minusDays_negativeAcrossYear() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(-169); check(t, 2007, 12, 31, 12, 30, 40, 987654321); } ! @Test public void test_minusDays_negativeOverYears() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusDays(-731); check(t, 2009, 7, 15, 12, 30, 40, 987654321); } ! @Test public void test_minusDays_maximum() { LocalDateTime t = createDateMidnight(Year.MAX_VALUE, 12, 30).minusDays(-1); check(t, Year.MAX_VALUE, 12, 31, 0, 0, 0, 0); } ! @Test public void test_minusDays_minimum() { LocalDateTime t = createDateMidnight(Year.MIN_VALUE, 1, 2).minusDays(1); check(t, Year.MIN_VALUE, 1, 1, 0, 0, 0, 0); } ! @Test(expectedExceptions=DateTimeException.class) public void test_minusDays_invalidTooLarge() { createDateMidnight(Year.MAX_VALUE, 12, 31).minusDays(-1); } ! @Test(expectedExceptions=DateTimeException.class) public void test_minusDays_invalidTooSmall() { createDateMidnight(Year.MIN_VALUE, 1, 1).minusDays(1); } ! @Test(expectedExceptions=ArithmeticException.class) public void test_minusDays_overflowTooLarge() { createDateMidnight(Year.MAX_VALUE, 12, 31).minusDays(Long.MIN_VALUE); } ! @Test(expectedExceptions=ArithmeticException.class) public void test_minusDays_overflowTooSmall() { createDateMidnight(Year.MIN_VALUE, 1, 1).minusDays(Long.MAX_VALUE); } //----------------------------------------------------------------------- // minusHours() //----------------------------------------------------------------------- ! @Test public void test_minusHours_one() { LocalDateTime t =TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); for (int i = 0; i < 50; i++) {
*** 2372,2382 **** assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24); } } ! @Test(groups={"tck"}) public void test_minusHours_fromZero() { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = base.toLocalDate().plusDays(2); LocalTime t = LocalTime.of(3, 0); --- 2422,2432 ---- assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24); } } ! @Test public void test_minusHours_fromZero() { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = base.toLocalDate().plusDays(2); LocalTime t = LocalTime.of(3, 0);
*** 2391,2401 **** assertEquals(dt.toLocalDate(), d, String.valueOf(i)); assertEquals(dt.toLocalTime(), t); } } ! @Test(groups={"tck"}) public void test_minusHours_fromOne() { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0)); LocalDate d = base.toLocalDate().plusDays(2); LocalTime t = LocalTime.of(4, 0); --- 2441,2451 ---- assertEquals(dt.toLocalDate(), d, String.valueOf(i)); assertEquals(dt.toLocalTime(), t); } } ! @Test public void test_minusHours_fromOne() { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0)); LocalDate d = base.toLocalDate().plusDays(2); LocalTime t = LocalTime.of(4, 0);
*** 2414,2424 **** } //----------------------------------------------------------------------- // minusMinutes() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_minusMinutes_one() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate().minusDays(1); int hour = 0; --- 2464,2474 ---- } //----------------------------------------------------------------------- // minusMinutes() //----------------------------------------------------------------------- ! @Test public void test_minusMinutes_one() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate().minusDays(1); int hour = 0;
*** 2439,2449 **** assertEquals(t.getHour(), hour); assertEquals(t.getMinute(), min); } } ! @Test(groups={"tck"}) public void test_minusMinutes_fromZero() { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = base.toLocalDate().minusDays(1); LocalTime t = LocalTime.of(22, 49); --- 2489,2499 ---- assertEquals(t.getHour(), hour); assertEquals(t.getMinute(), min); } } ! @Test public void test_minusMinutes_fromZero() { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = base.toLocalDate().minusDays(1); LocalTime t = LocalTime.of(22, 49);
*** 2458,2477 **** assertEquals(dt.toLocalDate(), d); assertEquals(dt.toLocalTime(), t); } } ! @Test(groups={"tck"}) public void test_minusMinutes_noChange_oneDay() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMinutes(24 * 60); assertEquals(t.toLocalDate(), TEST_2007_07_15_12_30_40_987654321.toLocalDate().minusDays(1)); } //----------------------------------------------------------------------- // minusSeconds() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_minusSeconds_one() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate().minusDays(1); int hour = 0; --- 2508,2527 ---- assertEquals(dt.toLocalDate(), d); assertEquals(dt.toLocalTime(), t); } } ! @Test public void test_minusMinutes_noChange_oneDay() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minusMinutes(24 * 60); assertEquals(t.toLocalDate(), TEST_2007_07_15_12_30_40_987654321.toLocalDate().minusDays(1)); } //----------------------------------------------------------------------- // minusSeconds() //----------------------------------------------------------------------- ! @Test public void test_minusSeconds_one() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate().minusDays(1); int hour = 0;
*** 2547,2557 **** throw new UnsupportedOperationException(); } }; } ! @Test(dataProvider="minusSeconds_fromZero", groups={"tck"}) public void test_minusSeconds_fromZero(int seconds, LocalDate date, int hour, int min, int sec) { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDateTime t = base.minusSeconds(seconds); assertEquals(date, t.toLocalDate()); --- 2597,2607 ---- throw new UnsupportedOperationException(); } }; } ! @Test(dataProvider="minusSeconds_fromZero") public void test_minusSeconds_fromZero(int seconds, LocalDate date, int hour, int min, int sec) { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDateTime t = base.minusSeconds(seconds); assertEquals(date, t.toLocalDate());
*** 2561,2571 **** } //----------------------------------------------------------------------- // minusNanos() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_minusNanos_halfABillion() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate().minusDays(1); int hour = 0; --- 2611,2621 ---- } //----------------------------------------------------------------------- // minusNanos() //----------------------------------------------------------------------- ! @Test public void test_minusNanos_halfABillion() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate().minusDays(1); int hour = 0;
*** 2652,2662 **** throw new UnsupportedOperationException(); } }; } ! @Test(dataProvider="minusNanos_fromZero", groups={"tck"}) public void test_minusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDateTime t = base.minusNanos(nanoseconds); assertEquals(date, t.toLocalDate()); --- 2702,2712 ---- throw new UnsupportedOperationException(); } }; } ! @Test(dataProvider="minusNanos_fromZero") public void test_minusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDateTime t = base.minusNanos(nanoseconds); assertEquals(date, t.toLocalDate());
*** 2665,2750 **** assertEquals(sec, t.getSecond()); assertEquals(nanos, t.getNano()); } //----------------------------------------------------------------------- // atOffset() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_atOffset() { LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30); assertEquals(t.atOffset(OFFSET_PTWO), OffsetDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), OFFSET_PTWO)); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_atOffset_nullZoneOffset() { LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30); t.atOffset((ZoneOffset) null); } //----------------------------------------------------------------------- // atZone() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_atZone() { LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30); assertEquals(t.atZone(ZONE_PARIS), ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), ZONE_PARIS)); } ! @Test(groups={"tck"}) public void test_atZone_Offset() { LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30); assertEquals(t.atZone(OFFSET_PTWO), ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), OFFSET_PTWO)); } ! @Test(groups={"tck"}) public void test_atZone_dstGap() { LocalDateTime t = LocalDateTime.of(2007, 4, 1, 0, 0); assertEquals(t.atZone(ZONE_GAZA), ZonedDateTime.of(LocalDateTime.of(2007, 4, 1, 1, 0), ZONE_GAZA)); } ! @Test(groups={"tck"}) public void test_atZone_dstOverlap() { LocalDateTime t = LocalDateTime.of(2007, 10, 28, 2, 30); assertEquals(t.atZone(ZONE_PARIS), ZonedDateTime.ofStrict(LocalDateTime.of(2007, 10, 28, 2, 30), OFFSET_PTWO, ZONE_PARIS)); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_atZone_nullTimeZone() { LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30); t.atZone((ZoneId) null); } //----------------------------------------------------------------------- // toEpochSecond() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_toEpochSecond_afterEpoch() { for (int i = -5; i < 5; i++) { ZoneOffset offset = ZoneOffset.ofHours(i); for (int j = 0; j < 100000; j++) { LocalDateTime a = LocalDateTime.of(1970, 1, 1, 0, 0).plusSeconds(j); assertEquals(a.toEpochSecond(offset), j - i * 3600); } } } ! @Test(groups={"tck"}) public void test_toEpochSecond_beforeEpoch() { for (int i = 0; i < 100000; i++) { LocalDateTime a = LocalDateTime.of(1970, 1, 1, 0, 0).minusSeconds(i); assertEquals(a.toEpochSecond(ZoneOffset.UTC), -i); } } //----------------------------------------------------------------------- // compareTo() //----------------------------------------------------------------------- ! @Test(groups={"tck"}) public void test_comparisons() { test_comparisons_LocalDateTime( LocalDate.of(Year.MIN_VALUE, 1, 1), LocalDate.of(Year.MIN_VALUE, 12, 31), LocalDate.of(-1, 1, 1), --- 2715,2978 ---- assertEquals(sec, t.getSecond()); assertEquals(nanos, t.getNano()); } //----------------------------------------------------------------------- + // periodUntil(Temporal, TemporalUnit) + //----------------------------------------------------------------------- + @DataProvider(name="periodUntilUnit") + Object[][] data_periodUntilUnit() { + return new Object[][] { + // date only + {dtNoon(2000, 1, 1), dtNoon(2000, 1, 1), DAYS, 0}, + {dtNoon(2000, 1, 1), dtNoon(2000, 1, 1), WEEKS, 0}, + {dtNoon(2000, 1, 1), dtNoon(2000, 1, 1), MONTHS, 0}, + {dtNoon(2000, 1, 1), dtNoon(2000, 1, 1), YEARS, 0}, + {dtNoon(2000, 1, 1), dtNoon(2000, 1, 1), DECADES, 0}, + {dtNoon(2000, 1, 1), dtNoon(2000, 1, 1), CENTURIES, 0}, + {dtNoon(2000, 1, 1), dtNoon(2000, 1, 1), MILLENNIA, 0}, + + {dtNoon(2000, 1, 15), dtNoon(2000, 2, 14), DAYS, 30}, + {dtNoon(2000, 1, 15), dtNoon(2000, 2, 15), DAYS, 31}, + {dtNoon(2000, 1, 15), dtNoon(2000, 2, 16), DAYS, 32}, + + {dtNoon(2000, 1, 15), dtNoon(2000, 2, 17), WEEKS, 4}, + {dtNoon(2000, 1, 15), dtNoon(2000, 2, 18), WEEKS, 4}, + {dtNoon(2000, 1, 15), dtNoon(2000, 2, 19), WEEKS, 5}, + {dtNoon(2000, 1, 15), dtNoon(2000, 2, 20), WEEKS, 5}, + + {dtNoon(2000, 1, 15), dtNoon(2000, 2, 14), MONTHS, 0}, + {dtNoon(2000, 1, 15), dtNoon(2000, 2, 15), MONTHS, 1}, + {dtNoon(2000, 1, 15), dtNoon(2000, 2, 16), MONTHS, 1}, + {dtNoon(2000, 1, 15), dtNoon(2000, 3, 14), MONTHS, 1}, + {dtNoon(2000, 1, 15), dtNoon(2000, 3, 15), MONTHS, 2}, + {dtNoon(2000, 1, 15), dtNoon(2000, 3, 16), MONTHS, 2}, + + {dtNoon(2000, 1, 15), dtNoon(2001, 1, 14), YEARS, 0}, + {dtNoon(2000, 1, 15), dtNoon(2001, 1, 15), YEARS, 1}, + {dtNoon(2000, 1, 15), dtNoon(2001, 1, 16), YEARS, 1}, + {dtNoon(2000, 1, 15), dtNoon(2004, 1, 14), YEARS, 3}, + {dtNoon(2000, 1, 15), dtNoon(2004, 1, 15), YEARS, 4}, + {dtNoon(2000, 1, 15), dtNoon(2004, 1, 16), YEARS, 4}, + + {dtNoon(2000, 1, 15), dtNoon(2010, 1, 14), DECADES, 0}, + {dtNoon(2000, 1, 15), dtNoon(2010, 1, 15), DECADES, 1}, + + {dtNoon(2000, 1, 15), dtNoon(2100, 1, 14), CENTURIES, 0}, + {dtNoon(2000, 1, 15), dtNoon(2100, 1, 15), CENTURIES, 1}, + + {dtNoon(2000, 1, 15), dtNoon(3000, 1, 14), MILLENNIA, 0}, + {dtNoon(2000, 1, 15), dtNoon(3000, 1, 15), MILLENNIA, 1}, + + // time only + {dtEpoch(0, 0, 0, 0), dtEpoch(0, 0, 0, 0), NANOS, 0}, + {dtEpoch(0, 0, 0, 0), dtEpoch(0, 0, 0, 0), MICROS, 0}, + {dtEpoch(0, 0, 0, 0), dtEpoch(0, 0, 0, 0), MILLIS, 0}, + {dtEpoch(0, 0, 0, 0), dtEpoch(0, 0, 0, 0), SECONDS, 0}, + {dtEpoch(0, 0, 0, 0), dtEpoch(0, 0, 0, 0), MINUTES, 0}, + {dtEpoch(0, 0, 0, 0), dtEpoch(0, 0, 0, 0), HOURS, 0}, + {dtEpoch(0, 0, 0, 0), dtEpoch(0, 0, 0, 0), HALF_DAYS, 0}, + + {dtEpoch(0, 0, 0, 0), dtEpoch(2, 0, 0, 0), NANOS, 2 * 3600 * 1_000_000_000L}, + {dtEpoch(0, 0, 0, 0), dtEpoch(2, 0, 0, 0), MICROS, 2 * 3600 * 1_000_000L}, + {dtEpoch(0, 0, 0, 0), dtEpoch(2, 0, 0, 0), MILLIS, 2 * 3600 * 1_000L}, + {dtEpoch(0, 0, 0, 0), dtEpoch(2, 0, 0, 0), SECONDS, 2 * 3600}, + {dtEpoch(0, 0, 0, 0), dtEpoch(2, 0, 0, 0), MINUTES, 2 * 60}, + {dtEpoch(0, 0, 0, 0), dtEpoch(2, 0, 0, 0), HOURS, 2}, + {dtEpoch(0, 0, 0, 0), dtEpoch(2, 0, 0, 0), HALF_DAYS, 0}, + + {dtEpoch(0, 0, 0, 0), dtEpoch(14, 0, 0, 0), NANOS, 14 * 3600 * 1_000_000_000L}, + {dtEpoch(0, 0, 0, 0), dtEpoch(14, 0, 0, 0), MICROS, 14 * 3600 * 1_000_000L}, + {dtEpoch(0, 0, 0, 0), dtEpoch(14, 0, 0, 0), MILLIS, 14 * 3600 * 1_000L}, + {dtEpoch(0, 0, 0, 0), dtEpoch(14, 0, 0, 0), SECONDS, 14 * 3600}, + {dtEpoch(0, 0, 0, 0), dtEpoch(14, 0, 0, 0), MINUTES, 14 * 60}, + {dtEpoch(0, 0, 0, 0), dtEpoch(14, 0, 0, 0), HOURS, 14}, + {dtEpoch(0, 0, 0, 0), dtEpoch(14, 0, 0, 0), HALF_DAYS, 1}, + + {dtEpoch(0, 0, 0, 0), dtEpoch(2, 30, 40, 1500), NANOS, (2 * 3600 + 30 * 60 + 40) * 1_000_000_000L + 1500}, + {dtEpoch(0, 0, 0, 0), dtEpoch(2, 30, 40, 1500), MICROS, (2 * 3600 + 30 * 60 + 40) * 1_000_000L + 1}, + {dtEpoch(0, 0, 0, 0), dtEpoch(2, 30, 40, 1500), MILLIS, (2 * 3600 + 30 * 60 + 40) * 1_000L}, + {dtEpoch(0, 0, 0, 0), dtEpoch(2, 30, 40, 1500), SECONDS, 2 * 3600 + 30 * 60 + 40}, + {dtEpoch(0, 0, 0, 0), dtEpoch(2, 30, 40, 1500), MINUTES, 2 * 60 + 30}, + {dtEpoch(0, 0, 0, 0), dtEpoch(2, 30, 40, 1500), HOURS, 2}, + + // combinations + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 40, 499), NANOS, -1}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 40, 500), NANOS, 0}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 40, 501), NANOS, 1}, + + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 39, 500), SECONDS, -1}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 39, 501), SECONDS, 0}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 40, 499), SECONDS, 0}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 40, 500), SECONDS, 0}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 40, 501), SECONDS, 0}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 41, 499), SECONDS, 0}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 41, 500), SECONDS, 1}, + + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 499), NANOS, -1 + 86400_000_000_000L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 500), NANOS, 0 + 86400_000_000_000L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 501), NANOS, 1 + 86400_000_000_000L}, + + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 39, 499), SECONDS, -2 + 86400L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 39, 500), SECONDS, -1 + 86400L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 39, 501), SECONDS, -1 + 86400L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 499), SECONDS, -1 + 86400L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 500), SECONDS, 0 + 86400L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 501), SECONDS, 0 + 86400L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 41, 499), SECONDS, 0 + 86400L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 41, 500), SECONDS, 1 + 86400L}, + + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 29, 40, 499), MINUTES, -2 + 24 * 60L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 29, 40, 500), MINUTES, -1 + 24 * 60L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 29, 40, 501), MINUTES, -1 + 24 * 60L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 499), MINUTES, -1 + 24 * 60L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 500), MINUTES, 0 + 24 * 60L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 501), MINUTES, 0 + 24 * 60L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 31, 40, 499), MINUTES, 0 + 24 * 60L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 31, 40, 500), MINUTES, 1 + 24 * 60L}, + + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 11, 30, 40, 499), HOURS, -2 + 24L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 11, 30, 40, 500), HOURS, -1 + 24L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 11, 30, 40, 501), HOURS, -1 + 24L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 499), HOURS, -1 + 24L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 500), HOURS, 0 + 24L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 501), HOURS, 0 + 24L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 13, 30, 40, 499), HOURS, 0 + 24L}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 13, 30, 40, 500), HOURS, 1 + 24L}, + + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 13, 12, 30, 40, 499), DAYS, -2}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 13, 12, 30, 40, 500), DAYS, -2}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 13, 12, 30, 40, 501), DAYS, -1}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 14, 12, 30, 40, 499), DAYS, -1}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 14, 12, 30, 40, 500), DAYS, -1}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 14, 12, 30, 40, 501), DAYS, 0}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 40, 499), DAYS, 0}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 40, 500), DAYS, 0}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 15, 12, 30, 40, 501), DAYS, 0}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 499), DAYS, 0}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 500), DAYS, 1}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 16, 12, 30, 40, 501), DAYS, 1}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 17, 12, 30, 40, 499), DAYS, 1}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 17, 12, 30, 40, 500), DAYS, 2}, + {dt(2000, 1, 15, 12, 30, 40, 500), dt(2000, 1, 17, 12, 30, 40, 501), DAYS, 2}, + }; + } + + @Test(dataProvider="periodUntilUnit") + public void test_periodUntil_TemporalUnit(LocalDateTime dt1, LocalDateTime dt2, TemporalUnit unit, long expected) { + long amount = dt1.periodUntil(dt2, unit); + assertEquals(amount, expected); + } + + @Test(dataProvider="periodUntilUnit") + public void test_periodUntil_TemporalUnit_negated(LocalDateTime dt1, LocalDateTime dt2, TemporalUnit unit, long expected) { + long amount = dt2.periodUntil(dt1, unit); + assertEquals(amount, -expected); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_periodUntil_TemporalUnit_nullEnd() { + TEST_2007_07_15_12_30_40_987654321.periodUntil(null, HOURS); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_periodUntil_TemporalUnit_nullUnit() { + TEST_2007_07_15_12_30_40_987654321.periodUntil(TEST_2007_07_15_12_30_40_987654321, null); + } + + //----------------------------------------------------------------------- + // format(DateTimeFormatter) + //----------------------------------------------------------------------- + @Test + public void test_format_formatter() { + DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s"); + String t = LocalDateTime.of(2010, 12, 3, 11, 30, 45).format(f); + assertEquals(t, "2010 12 3 11 30 45"); + } + + @Test(expectedExceptions=NullPointerException.class) + public void test_format_formatter_null() { + LocalDateTime.of(2010, 12, 3, 11, 30, 45).format(null); + } + + //----------------------------------------------------------------------- // atOffset() //----------------------------------------------------------------------- ! @Test public void test_atOffset() { LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30); assertEquals(t.atOffset(OFFSET_PTWO), OffsetDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), OFFSET_PTWO)); } ! @Test(expectedExceptions=NullPointerException.class) public void test_atOffset_nullZoneOffset() { LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30); t.atOffset((ZoneOffset) null); } //----------------------------------------------------------------------- // atZone() //----------------------------------------------------------------------- ! @Test public void test_atZone() { LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30); assertEquals(t.atZone(ZONE_PARIS), ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), ZONE_PARIS)); } ! @Test public void test_atZone_Offset() { LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30); assertEquals(t.atZone(OFFSET_PTWO), ZonedDateTime.of(LocalDateTime.of(2008, 6, 30, 11, 30), OFFSET_PTWO)); } ! @Test public void test_atZone_dstGap() { LocalDateTime t = LocalDateTime.of(2007, 4, 1, 0, 0); assertEquals(t.atZone(ZONE_GAZA), ZonedDateTime.of(LocalDateTime.of(2007, 4, 1, 1, 0), ZONE_GAZA)); } ! @Test public void test_atZone_dstOverlap() { LocalDateTime t = LocalDateTime.of(2007, 10, 28, 2, 30); assertEquals(t.atZone(ZONE_PARIS), ZonedDateTime.ofStrict(LocalDateTime.of(2007, 10, 28, 2, 30), OFFSET_PTWO, ZONE_PARIS)); } ! @Test(expectedExceptions=NullPointerException.class) public void test_atZone_nullTimeZone() { LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30); t.atZone((ZoneId) null); } //----------------------------------------------------------------------- // toEpochSecond() //----------------------------------------------------------------------- ! @Test public void test_toEpochSecond_afterEpoch() { for (int i = -5; i < 5; i++) { ZoneOffset offset = ZoneOffset.ofHours(i); for (int j = 0; j < 100000; j++) { LocalDateTime a = LocalDateTime.of(1970, 1, 1, 0, 0).plusSeconds(j); assertEquals(a.toEpochSecond(offset), j - i * 3600); } } } ! @Test public void test_toEpochSecond_beforeEpoch() { for (int i = 0; i < 100000; i++) { LocalDateTime a = LocalDateTime.of(1970, 1, 1, 0, 0).minusSeconds(i); assertEquals(a.toEpochSecond(ZoneOffset.UTC), -i); } } //----------------------------------------------------------------------- // compareTo() //----------------------------------------------------------------------- ! @Test public void test_comparisons() { test_comparisons_LocalDateTime( LocalDate.of(Year.MIN_VALUE, 1, 1), LocalDate.of(Year.MIN_VALUE, 12, 31), LocalDate.of(-1, 1, 1),
*** 2821,2846 **** } } } } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_compareTo_ObjectNull() { TEST_2007_07_15_12_30_40_987654321.compareTo(null); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_isBefore_ObjectNull() { TEST_2007_07_15_12_30_40_987654321.isBefore(null); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_isAfter_ObjectNull() { TEST_2007_07_15_12_30_40_987654321.isAfter(null); } ! @Test(expectedExceptions=ClassCastException.class, groups={"tck"}) @SuppressWarnings({"unchecked", "rawtypes"}) public void compareToNonLocalDateTime() { Comparable c = TEST_2007_07_15_12_30_40_987654321; c.compareTo(new Object()); } --- 3049,3074 ---- } } } } ! @Test(expectedExceptions=NullPointerException.class) public void test_compareTo_ObjectNull() { TEST_2007_07_15_12_30_40_987654321.compareTo(null); } ! @Test(expectedExceptions=NullPointerException.class) public void test_isBefore_ObjectNull() { TEST_2007_07_15_12_30_40_987654321.isBefore(null); } ! @Test(expectedExceptions=NullPointerException.class) public void test_isAfter_ObjectNull() { TEST_2007_07_15_12_30_40_987654321.isAfter(null); } ! @Test(expectedExceptions=ClassCastException.class) @SuppressWarnings({"unchecked", "rawtypes"}) public void compareToNonLocalDateTime() { Comparable c = TEST_2007_07_15_12_30_40_987654321; c.compareTo(new Object()); }
*** 2881,2965 **** throw new UnsupportedOperationException(); } }; } ! @Test(dataProvider="sampleDateTimes", groups={"tck"}) public void test_equals_true(int y, int m, int d, int h, int mi, int s, int n) { LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n); LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s, n); assertTrue(a.equals(b)); } ! @Test(dataProvider="sampleDateTimes", groups={"tck"}) public void test_equals_false_year_differs(int y, int m, int d, int h, int mi, int s, int n) { LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n); LocalDateTime b = LocalDateTime.of(y + 1, m, d, h, mi, s, n); assertFalse(a.equals(b)); } ! @Test(dataProvider="sampleDateTimes", groups={"tck"}) public void test_equals_false_month_differs(int y, int m, int d, int h, int mi, int s, int n) { LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n); LocalDateTime b = LocalDateTime.of(y, m + 1, d, h, mi, s, n); assertFalse(a.equals(b)); } ! @Test(dataProvider="sampleDateTimes", groups={"tck"}) public void test_equals_false_day_differs(int y, int m, int d, int h, int mi, int s, int n) { LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n); LocalDateTime b = LocalDateTime.of(y, m, d + 1, h, mi, s, n); assertFalse(a.equals(b)); } ! @Test(dataProvider="sampleDateTimes", groups={"tck"}) public void test_equals_false_hour_differs(int y, int m, int d, int h, int mi, int s, int n) { LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n); LocalDateTime b = LocalDateTime.of(y, m, d, h + 1, mi, s, n); assertFalse(a.equals(b)); } ! @Test(dataProvider="sampleDateTimes", groups={"tck"}) public void test_equals_false_minute_differs(int y, int m, int d, int h, int mi, int s, int n) { LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n); LocalDateTime b = LocalDateTime.of(y, m, d, h, mi + 1, s, n); assertFalse(a.equals(b)); } ! @Test(dataProvider="sampleDateTimes", groups={"tck"}) public void test_equals_false_second_differs(int y, int m, int d, int h, int mi, int s, int n) { LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n); LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s + 1, n); assertFalse(a.equals(b)); } ! @Test(dataProvider="sampleDateTimes", groups={"tck"}) public void test_equals_false_nano_differs(int y, int m, int d, int h, int mi, int s, int n) { LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n); LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s, n + 1); assertFalse(a.equals(b)); } ! @Test(groups={"tck"}) public void test_equals_itself_true() { assertEquals(TEST_2007_07_15_12_30_40_987654321.equals(TEST_2007_07_15_12_30_40_987654321), true); } ! @Test(groups={"tck"}) public void test_equals_string_false() { assertEquals(TEST_2007_07_15_12_30_40_987654321.equals("2007-07-15T12:30:40.987654321"), false); } ! @Test(groups={"tck"}) public void test_equals_null_false() { assertEquals(TEST_2007_07_15_12_30_40_987654321.equals(null), false); } //----------------------------------------------------------------------- // hashCode() //----------------------------------------------------------------------- ! @Test(dataProvider="sampleDateTimes", groups={"tck"}) public void test_hashCode(int y, int m, int d, int h, int mi, int s, int n) { LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n); assertEquals(a.hashCode(), a.hashCode()); LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s, n); assertEquals(a.hashCode(), b.hashCode()); --- 3109,3193 ---- throw new UnsupportedOperationException(); } }; } ! @Test(dataProvider="sampleDateTimes") public void test_equals_true(int y, int m, int d, int h, int mi, int s, int n) { LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n); LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s, n); assertTrue(a.equals(b)); } ! @Test(dataProvider="sampleDateTimes") public void test_equals_false_year_differs(int y, int m, int d, int h, int mi, int s, int n) { LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n); LocalDateTime b = LocalDateTime.of(y + 1, m, d, h, mi, s, n); assertFalse(a.equals(b)); } ! @Test(dataProvider="sampleDateTimes") public void test_equals_false_month_differs(int y, int m, int d, int h, int mi, int s, int n) { LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n); LocalDateTime b = LocalDateTime.of(y, m + 1, d, h, mi, s, n); assertFalse(a.equals(b)); } ! @Test(dataProvider="sampleDateTimes") public void test_equals_false_day_differs(int y, int m, int d, int h, int mi, int s, int n) { LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n); LocalDateTime b = LocalDateTime.of(y, m, d + 1, h, mi, s, n); assertFalse(a.equals(b)); } ! @Test(dataProvider="sampleDateTimes") public void test_equals_false_hour_differs(int y, int m, int d, int h, int mi, int s, int n) { LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n); LocalDateTime b = LocalDateTime.of(y, m, d, h + 1, mi, s, n); assertFalse(a.equals(b)); } ! @Test(dataProvider="sampleDateTimes") public void test_equals_false_minute_differs(int y, int m, int d, int h, int mi, int s, int n) { LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n); LocalDateTime b = LocalDateTime.of(y, m, d, h, mi + 1, s, n); assertFalse(a.equals(b)); } ! @Test(dataProvider="sampleDateTimes") public void test_equals_false_second_differs(int y, int m, int d, int h, int mi, int s, int n) { LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n); LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s + 1, n); assertFalse(a.equals(b)); } ! @Test(dataProvider="sampleDateTimes") public void test_equals_false_nano_differs(int y, int m, int d, int h, int mi, int s, int n) { LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n); LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s, n + 1); assertFalse(a.equals(b)); } ! @Test public void test_equals_itself_true() { assertEquals(TEST_2007_07_15_12_30_40_987654321.equals(TEST_2007_07_15_12_30_40_987654321), true); } ! @Test public void test_equals_string_false() { assertEquals(TEST_2007_07_15_12_30_40_987654321.equals("2007-07-15T12:30:40.987654321"), false); } ! @Test public void test_equals_null_false() { assertEquals(TEST_2007_07_15_12_30_40_987654321.equals(null), false); } //----------------------------------------------------------------------- // hashCode() //----------------------------------------------------------------------- ! @Test(dataProvider="sampleDateTimes") public void test_hashCode(int y, int m, int d, int h, int mi, int s, int n) { LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n); assertEquals(a.hashCode(), a.hashCode()); LocalDateTime b = LocalDateTime.of(y, m, d, h, mi, s, n); assertEquals(a.hashCode(), b.hashCode());
*** 2977,3004 **** {-1, 1, 2, 23, 59, 59, 999990000, "-0001-01-02T23:59:59.999990"}, {-2008, 1, 2, 23, 59, 59, 999999990, "-2008-01-02T23:59:59.999999990"}, }; } ! @Test(dataProvider="sampleToString", groups={"tck"}) public void test_toString(int y, int m, int d, int h, int mi, int s, int n, String expected) { LocalDateTime t = LocalDateTime.of(y, m, d, h, mi, s, n); String str = t.toString(); assertEquals(str, expected); } ! //----------------------------------------------------------------------- ! // toString(DateTimeFormatter) ! //----------------------------------------------------------------------- ! @Test(groups={"tck"}) ! public void test_toString_formatter() { ! DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s"); ! String t = LocalDateTime.of(2010, 12, 3, 11, 30, 45).toString(f); ! assertEquals(t, "2010 12 3 11 30 45"); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) ! public void test_toString_formatter_null() { ! LocalDateTime.of(2010, 12, 3, 11, 30, 45).toString(null); } } --- 3205,3229 ---- {-1, 1, 2, 23, 59, 59, 999990000, "-0001-01-02T23:59:59.999990"}, {-2008, 1, 2, 23, 59, 59, 999999990, "-2008-01-02T23:59:59.999999990"}, }; } ! @Test(dataProvider="sampleToString") public void test_toString(int y, int m, int d, int h, int mi, int s, int n, String expected) { LocalDateTime t = LocalDateTime.of(y, m, d, h, mi, s, n); String str = t.toString(); assertEquals(str, expected); } ! private LocalDateTime dtNoon(int year, int month, int day) { ! return LocalDateTime.of(year, month, day, 12, 0); ! } ! ! private LocalDateTime dtEpoch(int hour, int min, int sec, int nano) { ! return LocalDateTime.of(1970, 1, 1, hour, min, sec, nano); } ! private LocalDateTime dt(int year, int month, int day, int hour, int min, int sec, int nano) { ! return LocalDateTime.of(year, month, day, hour, min, sec, nano); } }