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

Print this page

        

*** 86,145 **** 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.DAYS; import static java.time.temporal.ChronoUnit.NANOS; import static java.time.temporal.ChronoUnit.SECONDS; 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 java.io.ByteArrayOutputStream; import java.io.DataOutputStream; - import java.io.IOException; - import java.util.ArrayList; - import java.util.Arrays; - import java.util.Iterator; - import java.util.List; - import java.time.Clock; import java.time.DateTimeException; import java.time.DayOfWeek; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.Month; ! import java.time.Period; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; - import java.time.format.DateTimeFormatters; import java.time.format.DateTimeParseException; import java.time.temporal.ChronoField; import java.time.temporal.ChronoUnit; - import java.time.temporal.ISOChrono; import java.time.temporal.JulianFields; - import java.time.temporal.OffsetDateTime; import java.time.temporal.Queries; import java.time.temporal.Temporal; import java.time.temporal.TemporalAccessor; - import java.time.temporal.TemporalAdder; import java.time.temporal.TemporalAdjuster; import java.time.temporal.TemporalField; import java.time.temporal.TemporalQuery; - import java.time.temporal.TemporalSubtractor; import java.time.temporal.TemporalUnit; ! import java.time.temporal.Year; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; - import test.java.time.MockSimplePeriod; /** * Test LocalDateTime. */ @Test --- 86,141 ---- 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.DAYS; + 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.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 java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.time.Clock; import java.time.DateTimeException; import java.time.DayOfWeek; import java.time.Instant; 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; import java.time.temporal.TemporalQuery; import java.time.temporal.TemporalUnit; ! import java.util.ArrayList; ! import java.util.Arrays; ! import java.util.Iterator; ! import java.util.List; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; /** * Test LocalDateTime. */ @Test
*** 278,293 **** //----------------------------------------------------------------------- @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.getTime().toNanoOfDay() - expected.getTime().toNanoOfDay()); if (diff >= 100000000) { // may be date change expected = LocalDateTime.now(Clock.systemDefaultZone()); test = LocalDateTime.now(); ! diff = Math.abs(test.getTime().toNanoOfDay() - expected.getTime().toNanoOfDay()); } assertTrue(diff < 100000000); // less than 0.1 secs } //----------------------------------------------------------------------- --- 274,289 ---- //----------------------------------------------------------------------- @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) { // may be date change expected = LocalDateTime.now(Clock.systemDefaultZone()); test = LocalDateTime.now(); ! diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay()); } assertTrue(diff < 100000000); // less than 0.1 secs } //-----------------------------------------------------------------------
*** 362,372 **** LocalDateTime test = LocalDateTime.now(clock); assertEquals(test.getYear(), 1969); assertEquals(test.getMonth(), Month.DECEMBER); assertEquals(test.getDayOfMonth(), 31); expected = expected.minusSeconds(1); ! assertEquals(test.getTime(), expected); } } //----------------------------------------------------------------------- @Test(groups={"tck"}) --- 358,368 ---- LocalDateTime test = LocalDateTime.now(clock); assertEquals(test.getYear(), 1969); assertEquals(test.getMonth(), Month.DECEMBER); assertEquals(test.getDayOfMonth(), 31); expected = expected.minusSeconds(1); ! assertEquals(test.toLocalTime(), expected); } } //----------------------------------------------------------------------- @Test(groups={"tck"})
*** 913,930 **** //----------------------------------------------------------------------- // parse(DateTimeFormatter) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void factory_parse_formatter() { ! DateTimeFormatter f = DateTimeFormatters.pattern("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 = DateTimeFormatters.pattern("y M d H m s"); LocalDateTime.parse((String) null, f); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void factory_parse_formatter_nullFormatter() { --- 909,926 ---- //----------------------------------------------------------------------- // 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() {
*** 969,1006 **** } //----------------------------------------------------------------------- // query(TemporalQuery) //----------------------------------------------------------------------- ! @Test ! public void test_query_chrono() { ! assertEquals(TEST_2007_07_15_12_30_40_987654321.query(Queries.chrono()), ISOChrono.INSTANCE); ! assertEquals(Queries.chrono().queryFrom(TEST_2007_07_15_12_30_40_987654321), ISOChrono.INSTANCE); ! } ! ! @Test ! public void test_query_zoneId() { ! assertEquals(TEST_2007_07_15_12_30_40_987654321.query(Queries.zoneId()), null); ! assertEquals(Queries.zoneId().queryFrom(TEST_2007_07_15_12_30_40_987654321), null); ! } ! ! @Test ! public void test_query_precision() { ! assertEquals(TEST_2007_07_15_12_30_40_987654321.query(Queries.precision()), NANOS); ! assertEquals(Queries.precision().queryFrom(TEST_2007_07_15_12_30_40_987654321), NANOS); } ! @Test ! public void test_query_offset() { ! assertEquals(TEST_2007_07_15_12_30_40_987654321.query(Queries.offset()), null); ! assertEquals(Queries.offset().queryFrom(TEST_2007_07_15_12_30_40_987654321), null); } ! @Test ! public void test_query_zone() { ! assertEquals(TEST_2007_07_15_12_30_40_987654321.query(Queries.zone()), null); ! assertEquals(Queries.zone().queryFrom(TEST_2007_07_15_12_30_40_987654321), null); } @Test(expectedExceptions=NullPointerException.class) public void test_query_null() { TEST_2007_07_15_12_30_40_987654321.query(null); --- 965,995 ---- } //----------------------------------------------------------------------- // 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) { ! assertEquals(temporal.query(query), expected); } ! @Test(dataProvider="query") ! public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) { ! assertEquals(query.queryFrom(temporal), expected); } @Test(expectedExceptions=NullPointerException.class) public void test_query_null() { TEST_2007_07_15_12_30_40_987654321.query(null);
*** 1063,1073 **** 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.getDate(), LocalTime.of(h, m, s, ns)); assertEquals(a.getHour(), h); assertEquals(a.getMinute(), m); assertEquals(a.getSecond(), s); assertEquals(a.getNano(), ns); } --- 1052,1062 ---- 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); assertEquals(a.getNano(), ns); }
*** 1080,1090 **** DayOfWeek dow = DayOfWeek.MONDAY; for (Month month : Month.values()) { int length = month.length(false); for (int i = 1; i <= length; i++) { LocalDateTime d = LocalDateTime.of(LocalDate.of(2007, month, i), ! TEST_2007_07_15_12_30_40_987654321.getTime()); assertSame(d.getDayOfWeek(), dow); dow = dow.plus(1); } } } --- 1069,1079 ---- DayOfWeek dow = DayOfWeek.MONDAY; for (Month month : Month.values()) { int length = month.length(false); for (int i = 1; i <= length; i++) { LocalDateTime d = LocalDateTime.of(LocalDate.of(2007, month, i), ! TEST_2007_07_15_12_30_40_987654321.toLocalTime()); assertSame(d.getDayOfWeek(), dow); dow = dow.plus(1); } } }
*** 1295,1352 **** public void test_truncatedTo_null() { TEST_2007_07_15_12_30_40_987654321.truncatedTo(null); } //----------------------------------------------------------------------- ! // plus(adjuster) //----------------------------------------------------------------------- ! @Test(groups={"tck"}) ! public void test_plus_adjuster() { ! Period p = Period.ofTime(0, 0, 62, 3); ! LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(p); ! assertEquals(t, LocalDateTime.of(2007, 7, 15, 12, 31, 42, 987654324)); ! } ! ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) ! public void test_plus_adjuster_null() { ! TEST_2007_07_15_12_30_40_987654321.plus((TemporalAdder) null); ! } ! ! //----------------------------------------------------------------------- ! // plus(Period) ! //----------------------------------------------------------------------- ! @Test(groups={"tck"}) ! public void test_plus_Period_positiveMonths() { ! MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS); LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(period); assertEquals(t, LocalDateTime.of(2008, 2, 15, 12, 30, 40, 987654321)); } ! @Test(groups={"tck"}) ! public void test_plus_Period_negativeDays() { ! MockSimplePeriod period = MockSimplePeriod.of(-25, ChronoUnit.DAYS); LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(period); assertEquals(t, LocalDateTime.of(2007, 6, 20, 12, 30, 40, 987654321)); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) ! public void test_plus_Period_null() { ! TEST_2007_07_15_12_30_40_987654321.plus((MockSimplePeriod) null); ! } ! ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) ! public void test_plus_Period_invalidTooLarge() { ! MockSimplePeriod period = MockSimplePeriod.of(1, ChronoUnit.YEARS); LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).plus(period); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) ! public void test_plus_Period_invalidTooSmall() { ! MockSimplePeriod period = MockSimplePeriod.of(-1, ChronoUnit.YEARS); LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).plus(period); } //----------------------------------------------------------------------- // plus(long,TemporalUnit) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plus_longTemporalUnit_positiveMonths() { --- 1284,1326 ---- public void test_truncatedTo_null() { TEST_2007_07_15_12_30_40_987654321.truncatedTo(null); } //----------------------------------------------------------------------- ! // plus(TemporalAmount) //----------------------------------------------------------------------- ! @Test ! public void test_plus_TemporalAmount_positiveMonths() { ! MockSimplePeriod period = MockSimplePeriod.of(7, MONTHS); LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(period); assertEquals(t, LocalDateTime.of(2008, 2, 15, 12, 30, 40, 987654321)); } ! @Test ! public void test_plus_TemporalAmount_negativeDays() { ! MockSimplePeriod period = MockSimplePeriod.of(-25, DAYS); LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plus(period); assertEquals(t, LocalDateTime.of(2007, 6, 20, 12, 30, 40, 987654321)); } ! @Test(expectedExceptions=DateTimeException.class) ! public void test_plus_TemporalAmount_invalidTooLarge() { ! MockSimplePeriod period = MockSimplePeriod.of(1, YEARS); LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).plus(period); } ! @Test(expectedExceptions=DateTimeException.class) ! public void test_plus_TemporalAmount_invalidTooSmall() { ! MockSimplePeriod period = MockSimplePeriod.of(-1, YEARS); LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).plus(period); } + @Test(expectedExceptions=NullPointerException.class) + public void test_plus_TemporalAmount_null() { + TEST_2007_07_15_12_30_40_987654321.plus((TemporalAmount) null); + } + //----------------------------------------------------------------------- // plus(long,TemporalUnit) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plus_longTemporalUnit_positiveMonths() {
*** 1695,1741 **** // 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.getDate(); for (int i = 0; i < 50; i++) { t = t.plusHours(1); if ((i + 1) % 24 == 0) { d = d.plusDays(1); } ! assertEquals(t.getDate(), 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.getDate().minusDays(3); LocalTime t = LocalTime.of(21, 0); for (int i = -50; i < 50; i++) { LocalDateTime dt = base.plusHours(i); t = t.plusHours(1); if (t.getHour() == 0) { d = d.plusDays(1); } ! assertEquals(dt.getDate(), d); ! assertEquals(dt.getTime(), 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.getDate().minusDays(3); LocalTime t = LocalTime.of(22, 0); for (int i = -50; i < 50; i++) { LocalDateTime dt = base.plusHours(i); --- 1669,1715 ---- // 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++) { t = t.plusHours(1); if ((i + 1) % 24 == 0) { d = d.plusDays(1); } ! 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); for (int i = -50; i < 50; i++) { LocalDateTime dt = base.plusHours(i); t = t.plusHours(1); if (t.getHour() == 0) { d = d.plusDays(1); } ! 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); for (int i = -50; i < 50; i++) { LocalDateTime dt = base.plusHours(i);
*** 1743,1764 **** if (t.getHour() == 0) { d = d.plusDays(1); } ! assertEquals(dt.getDate(), d); ! assertEquals(dt.getTime(), t); } } //----------------------------------------------------------------------- // 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.getDate(); int hour = 0; int min = 0; for (int i = 0; i < 70; i++) { --- 1717,1738 ---- if (t.getHour() == 0) { d = d.plusDays(1); } ! assertEquals(dt.toLocalDate(), d); ! assertEquals(dt.toLocalTime(), t); } } //----------------------------------------------------------------------- // 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; int min = 0; for (int i = 0; i < 70; i++) {
*** 1767,1814 **** if (min == 60) { hour++; min = 0; } ! assertEquals(t.getDate(), d); 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.getDate().minusDays(1); LocalTime t = LocalTime.of(22, 49); for (int i = -70; i < 70; i++) { LocalDateTime dt = base.plusMinutes(i); t = t.plusMinutes(1); if (t == LocalTime.MIDNIGHT) { d = d.plusDays(1); } ! assertEquals(dt.getDate(), d, String.valueOf(i)); ! assertEquals(dt.getTime(), 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.getDate(), TEST_2007_07_15_12_30_40_987654321.getDate().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.getDate(); int hour = 0; int min = 0; int sec = 0; --- 1741,1788 ---- if (min == 60) { hour++; min = 0; } ! assertEquals(t.toLocalDate(), d); 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); for (int i = -70; i < 70; i++) { LocalDateTime dt = base.plusMinutes(i); t = t.plusMinutes(1); if (t == LocalTime.MIDNIGHT) { d = d.plusDays(1); } ! 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; int min = 0; int sec = 0;
*** 1822,1832 **** if (min == 60) { hour++; min = 0; } ! assertEquals(t.getDate(), d); assertEquals(t.getHour(), hour); assertEquals(t.getMinute(), min); assertEquals(t.getSecond(), sec); } } --- 1796,1806 ---- if (min == 60) { hour++; min = 0; } ! assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), hour); assertEquals(t.getMinute(), min); assertEquals(t.getSecond(), sec); } }
*** 1835,1845 **** Iterator<Object[]> plusSeconds_fromZero() { return new Iterator<Object[]>() { int delta = 30; int i = -3660; ! LocalDate date = TEST_2007_07_15_12_30_40_987654321.getDate().minusDays(1); int hour = 22; int min = 59; int sec = 0; public boolean hasNext() { --- 1809,1819 ---- Iterator<Object[]> plusSeconds_fromZero() { return new Iterator<Object[]>() { int delta = 30; int i = -3660; ! LocalDate date = TEST_2007_07_15_12_30_40_987654321.toLocalDate().minusDays(1); int hour = 22; int min = 59; int sec = 0; public boolean hasNext() {
*** 1881,1909 **** @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.getDate()); 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.getDate(), TEST_2007_07_15_12_30_40_987654321.getDate().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.getDate(); int hour = 0; int min = 0; int sec = 0; int nanos = 0; --- 1855,1883 ---- @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; int min = 0; int sec = 0; int nanos = 0;
*** 1922,1932 **** if (min == 60) { hour++; min = 0; } ! assertEquals(t.getDate(), d, String.valueOf(i)); assertEquals(t.getHour(), hour); assertEquals(t.getMinute(), min); assertEquals(t.getSecond(), sec); assertEquals(t.getNano(), nanos); } --- 1896,1906 ---- if (min == 60) { hour++; min = 0; } ! assertEquals(t.toLocalDate(), d, String.valueOf(i)); assertEquals(t.getHour(), hour); assertEquals(t.getMinute(), min); assertEquals(t.getSecond(), sec); assertEquals(t.getNano(), nanos); }
*** 1936,1946 **** Iterator<Object[]> plusNanos_fromZero() { return new Iterator<Object[]>() { long delta = 7500000000L; long i = -3660 * 1000000000L; ! LocalDate date = TEST_2007_07_15_12_30_40_987654321.getDate().minusDays(1); int hour = 22; int min = 59; int sec = 0; long nanos = 0; --- 1910,1920 ---- Iterator<Object[]> plusNanos_fromZero() { return new Iterator<Object[]>() { long delta = 7500000000L; long i = -3660 * 1000000000L; ! LocalDate date = TEST_2007_07_15_12_30_40_987654321.toLocalDate().minusDays(1); int hour = 22; int min = 59; int sec = 0; long nanos = 0;
*** 1985,2056 **** @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.getDate()); assertEquals(hour, t.getHour()); 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.getDate(), TEST_2007_07_15_12_30_40_987654321.getDate().plusDays(1)); ! } ! ! //----------------------------------------------------------------------- ! // minus(adjuster) ! //----------------------------------------------------------------------- ! @Test(groups={"tck"}) ! public void test_minus_adjuster() { ! Period p = Period.ofTime(0, 0, 62, 3); ! LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(p); ! assertEquals(t, LocalDateTime.of(2007, 7, 15, 12, 29, 38, 987654318)); ! } ! ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) ! public void test_minus_adjuster_null() { ! TEST_2007_07_15_12_30_40_987654321.minus((TemporalSubtractor) null); } //----------------------------------------------------------------------- ! // minus(Period) //----------------------------------------------------------------------- ! @Test(groups={"tck"}) ! public void test_minus_Period_positiveMonths() { ! MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS); LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(period); assertEquals(t, LocalDateTime.of(2006, 12, 15, 12, 30, 40, 987654321)); } ! @Test(groups={"tck"}) ! public void test_minus_Period_negativeDays() { ! MockSimplePeriod period = MockSimplePeriod.of(-25, ChronoUnit.DAYS); LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(period); assertEquals(t, LocalDateTime.of(2007, 8, 9, 12, 30, 40, 987654321)); } ! @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) ! public void test_minus_Period_null() { ! TEST_2007_07_15_12_30_40_987654321.minus((MockSimplePeriod) null); ! } ! ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) ! public void test_minus_Period_invalidTooLarge() { ! MockSimplePeriod period = MockSimplePeriod.of(-1, ChronoUnit.YEARS); LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).minus(period); } ! @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) ! public void test_minus_Period_invalidTooSmall() { ! MockSimplePeriod period = MockSimplePeriod.of(1, ChronoUnit.YEARS); LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).minus(period); } //----------------------------------------------------------------------- // minus(long,TemporalUnit) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minus_longTemporalUnit_positiveMonths() { --- 1959,2015 ---- @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()); assertEquals(hour, t.getHour()); 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)); } //----------------------------------------------------------------------- ! // minus(TemporalAmount) //----------------------------------------------------------------------- ! @Test ! public void test_minus_TemporalAmount_positiveMonths() { ! MockSimplePeriod period = MockSimplePeriod.of(7, MONTHS); LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(period); assertEquals(t, LocalDateTime.of(2006, 12, 15, 12, 30, 40, 987654321)); } ! @Test ! public void test_minus_TemporalAmount_negativeDays() { ! MockSimplePeriod period = MockSimplePeriod.of(-25, DAYS); LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.minus(period); assertEquals(t, LocalDateTime.of(2007, 8, 9, 12, 30, 40, 987654321)); } ! @Test(expectedExceptions=DateTimeException.class) ! public void test_minus_TemporalAmount_invalidTooLarge() { ! MockSimplePeriod period = MockSimplePeriod.of(-1, YEARS); LocalDateTime.of(Year.MAX_VALUE, 1, 1, 0, 0).minus(period); } ! @Test(expectedExceptions=DateTimeException.class) ! public void test_minus_TemporalAmount_invalidTooSmall() { ! MockSimplePeriod period = MockSimplePeriod.of(1, YEARS); LocalDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0).minus(period); } + @Test(expectedExceptions=NullPointerException.class) + public void test_minus_TemporalAmount_null() { + TEST_2007_07_15_12_30_40_987654321.minus((TemporalAmount) null); + } + //----------------------------------------------------------------------- // minus(long,TemporalUnit) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minus_longTemporalUnit_positiveMonths() {
*** 2399,2445 **** // 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.getDate(); for (int i = 0; i < 50; i++) { t = t.minusHours(1); if (i % 24 == 0) { d = d.minusDays(1); } ! assertEquals(t.getDate(), 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.getDate().plusDays(2); LocalTime t = LocalTime.of(3, 0); for (int i = -50; i < 50; i++) { LocalDateTime dt = base.minusHours(i); t = t.minusHours(1); if (t.getHour() == 23) { d = d.minusDays(1); } ! assertEquals(dt.getDate(), d, String.valueOf(i)); ! assertEquals(dt.getTime(), 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.getDate().plusDays(2); LocalTime t = LocalTime.of(4, 0); for (int i = -50; i < 50; i++) { LocalDateTime dt = base.minusHours(i); --- 2358,2404 ---- // 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++) { t = t.minusHours(1); if (i % 24 == 0) { d = d.minusDays(1); } ! 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); for (int i = -50; i < 50; i++) { LocalDateTime dt = base.minusHours(i); t = t.minusHours(1); if (t.getHour() == 23) { d = d.minusDays(1); } ! 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); for (int i = -50; i < 50; i++) { LocalDateTime dt = base.minusHours(i);
*** 2447,2468 **** if (t.getHour() == 23) { d = d.minusDays(1); } ! assertEquals(dt.getDate(), d, String.valueOf(i)); ! assertEquals(dt.getTime(), t); } } //----------------------------------------------------------------------- // 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.getDate().minusDays(1); int hour = 0; int min = 0; for (int i = 0; i < 70; i++) { --- 2406,2427 ---- if (t.getHour() == 23) { d = d.minusDays(1); } ! assertEquals(dt.toLocalDate(), d, String.valueOf(i)); ! assertEquals(dt.toLocalTime(), t); } } //----------------------------------------------------------------------- // 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; int min = 0; for (int i = 0; i < 70; i++) {
*** 2474,2521 **** if (hour == -1) { hour = 23; } } ! assertEquals(t.getDate(), d); 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.getDate().minusDays(1); LocalTime t = LocalTime.of(22, 49); for (int i = 70; i > -70; i--) { LocalDateTime dt = base.minusMinutes(i); t = t.plusMinutes(1); if (t == LocalTime.MIDNIGHT) { d = d.plusDays(1); } ! assertEquals(dt.getDate(), d); ! assertEquals(dt.getTime(), 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.getDate(), TEST_2007_07_15_12_30_40_987654321.getDate().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.getDate().minusDays(1); int hour = 0; int min = 0; int sec = 0; --- 2433,2480 ---- if (hour == -1) { hour = 23; } } ! assertEquals(t.toLocalDate(), d); 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); for (int i = 70; i > -70; i--) { LocalDateTime dt = base.minusMinutes(i); t = t.plusMinutes(1); if (t == LocalTime.MIDNIGHT) { d = d.plusDays(1); } ! 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; int min = 0; int sec = 0;
*** 2534,2544 **** hour = 23; } } } ! assertEquals(t.getDate(), d); assertEquals(t.getHour(), hour); assertEquals(t.getMinute(), min); assertEquals(t.getSecond(), sec); } } --- 2493,2503 ---- hour = 23; } } } ! assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), hour); assertEquals(t.getMinute(), min); assertEquals(t.getSecond(), sec); } }
*** 2547,2557 **** Iterator<Object[]> minusSeconds_fromZero() { return new Iterator<Object[]>() { int delta = 30; int i = 3660; ! LocalDate date = TEST_2007_07_15_12_30_40_987654321.getDate().minusDays(1); int hour = 22; int min = 59; int sec = 0; public boolean hasNext() { --- 2506,2516 ---- Iterator<Object[]> minusSeconds_fromZero() { return new Iterator<Object[]>() { int delta = 30; int i = 3660; ! LocalDate date = TEST_2007_07_15_12_30_40_987654321.toLocalDate().minusDays(1); int hour = 22; int min = 59; int sec = 0; public boolean hasNext() {
*** 2593,2603 **** @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.getDate()); assertEquals(hour, t.getHour()); assertEquals(min, t.getMinute()); assertEquals(sec, t.getSecond()); } --- 2552,2562 ---- @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()); assertEquals(hour, t.getHour()); assertEquals(min, t.getMinute()); assertEquals(sec, t.getSecond()); }
*** 2605,2615 **** // 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.getDate().minusDays(1); int hour = 0; int min = 0; int sec = 0; int nanos = 0; --- 2564,2574 ---- // 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; int min = 0; int sec = 0; int nanos = 0;
*** 2635,2645 **** } } } } ! assertEquals(t.getDate(), d); assertEquals(t.getHour(), hour); assertEquals(t.getMinute(), min); assertEquals(t.getSecond(), sec); assertEquals(t.getNano(), nanos); } --- 2594,2604 ---- } } } } ! assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), hour); assertEquals(t.getMinute(), min); assertEquals(t.getSecond(), sec); assertEquals(t.getNano(), nanos); }
*** 2649,2659 **** Iterator<Object[]> minusNanos_fromZero() { return new Iterator<Object[]>() { long delta = 7500000000L; long i = 3660 * 1000000000L; ! LocalDate date = TEST_2007_07_15_12_30_40_987654321.getDate().minusDays(1); int hour = 22; int min = 59; int sec = 0; long nanos = 0; --- 2608,2618 ---- Iterator<Object[]> minusNanos_fromZero() { return new Iterator<Object[]>() { long delta = 7500000000L; long i = 3660 * 1000000000L; ! LocalDate date = TEST_2007_07_15_12_30_40_987654321.toLocalDate().minusDays(1); int hour = 22; int min = 59; int sec = 0; long nanos = 0;
*** 2698,2708 **** @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.getDate()); assertEquals(hour, t.getHour()); assertEquals(min, t.getMinute()); assertEquals(sec, t.getSecond()); assertEquals(nanos, t.getNano()); } --- 2657,2667 ---- @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()); assertEquals(hour, t.getHour()); assertEquals(min, t.getMinute()); assertEquals(sec, t.getSecond()); assertEquals(nanos, t.getNano()); }
*** 3030,3040 **** //----------------------------------------------------------------------- // toString(DateTimeFormatter) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_toString_formatter() { ! DateTimeFormatter f = DateTimeFormatters.pattern("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"}) --- 2989,2999 ---- //----------------------------------------------------------------------- // 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"})