test/java/time/tck/java/time/TCKOffsetDateTime.java

Print this page

        

*** 55,65 **** * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ ! package tck.java.time.temporal; import static java.time.Month.DECEMBER; import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH; import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR; import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH; --- 55,65 ---- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ ! package tck.java.time; import static java.time.Month.DECEMBER; import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH; import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR; import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH;
*** 96,145 **** import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; - import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; - import java.util.ArrayList; - import java.util.Arrays; - import java.util.List; - import java.time.Clock; import java.time.DateTimeException; import java.time.Duration; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.Month; 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.OffsetDate; - import java.time.temporal.OffsetDateTime; - import java.time.temporal.OffsetTime; import java.time.temporal.Queries; import java.time.temporal.Temporal; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; import java.time.temporal.TemporalField; import java.time.temporal.TemporalQuery; ! import java.time.temporal.Year; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; - import tck.java.time.AbstractDateTimeTest; import test.java.time.MockSimplePeriod; /** * Test OffsetDateTime. */ --- 96,140 ---- import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.time.Clock; import java.time.DateTimeException; import java.time.Duration; 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.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.Queries; import java.time.temporal.Temporal; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; import java.time.temporal.TemporalField; import java.time.temporal.TemporalQuery; ! import java.util.ArrayList; ! import java.util.Arrays; ! import java.util.List; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import test.java.time.MockSimplePeriod; /** * Test OffsetDateTime. */
*** 223,233 **** @Test public void test_serialization_format() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(baos) ) { ! dos.writeByte(3); } byte[] bytes = baos.toByteArray(); ByteArrayOutputStream baosDateTime = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(baosDateTime) ) { dos.writeByte(5); --- 218,228 ---- @Test public void test_serialization_format() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(baos) ) { ! dos.writeByte(10); // java.time.Ser.OFFSET_DATE_TIME_TYPE } byte[] bytes = baos.toByteArray(); ByteArrayOutputStream baosDateTime = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(baosDateTime) ) { dos.writeByte(5);
*** 268,283 **** //----------------------------------------------------------------------- @Test(groups={"tck"}) public void now() { OffsetDateTime expected = OffsetDateTime.now(Clock.systemDefaultZone()); OffsetDateTime test = OffsetDateTime.now(); ! long diff = Math.abs(test.getTime().toNanoOfDay() - expected.getTime().toNanoOfDay()); if (diff >= 100000000) { // may be date change expected = OffsetDateTime.now(Clock.systemDefaultZone()); test = OffsetDateTime.now(); ! diff = Math.abs(test.getTime().toNanoOfDay() - expected.getTime().toNanoOfDay()); } assertTrue(diff < 100000000); // less than 0.1 secs } //----------------------------------------------------------------------- --- 263,278 ---- //----------------------------------------------------------------------- @Test(groups={"tck"}) public void now() { OffsetDateTime expected = OffsetDateTime.now(Clock.systemDefaultZone()); OffsetDateTime test = OffsetDateTime.now(); ! long diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay()); if (diff >= 100000000) { // may be date change expected = OffsetDateTime.now(Clock.systemDefaultZone()); test = OffsetDateTime.now(); ! diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay()); } assertTrue(diff < 100000000); // less than 0.1 secs } //-----------------------------------------------------------------------
*** 326,343 **** OffsetDateTime test = OffsetDateTime.now(clock); assertEquals(test.getYear(), 1969); assertEquals(test.getMonth(), Month.DECEMBER); assertEquals(test.getDayOfMonth(), 31); expected = expected.minusSeconds(1); ! assertEquals(test.getTime(), expected); assertEquals(test.getOffset(), ZoneOffset.UTC); } } @Test(groups={"tck"}) public void now_Clock_offsets() { ! OffsetDateTime base = OffsetDateTime.of(LocalDate.of(1970, 1, 1), LocalTime.of(12, 0), ZoneOffset.UTC); for (int i = -9; i < 15; i++) { ZoneOffset offset = ZoneOffset.ofHours(i); Clock clock = Clock.fixed(base.toInstant(), offset); OffsetDateTime test = OffsetDateTime.now(clock); assertEquals(test.getHour(), (12 + i) % 24); --- 321,338 ---- OffsetDateTime test = OffsetDateTime.now(clock); assertEquals(test.getYear(), 1969); assertEquals(test.getMonth(), Month.DECEMBER); assertEquals(test.getDayOfMonth(), 31); expected = expected.minusSeconds(1); ! assertEquals(test.toLocalTime(), expected); assertEquals(test.getOffset(), ZoneOffset.UTC); } } @Test(groups={"tck"}) public void now_Clock_offsets() { ! OffsetDateTime base = OffsetDateTime.of(1970, 1, 1, 12, 0, 0, 0, ZoneOffset.UTC); for (int i = -9; i < 15; i++) { ZoneOffset offset = ZoneOffset.ofHours(i); Clock clock = Clock.fixed(base.toInstant(), offset); OffsetDateTime test = OffsetDateTime.now(clock); assertEquals(test.getHour(), (12 + i) % 24);
*** 372,424 **** assertEquals(test.hashCode(), test.hashCode()); assertEquals(OffsetDateTime.of(LocalDateTime.of(y, mo, d, h, m, s, n), offset), test); } //----------------------------------------------------------------------- ! // dateTime factories ! //----------------------------------------------------------------------- ! @Test(groups={"tck"}) ! public void factory_of_intMonthIntHM() { ! OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, Month.JUNE, 30), ! LocalTime.of(11, 30), OFFSET_PONE); ! check(test, 2008, 6, 30, 11, 30, 0, 0, OFFSET_PONE); ! } ! ! //----------------------------------------------------------------------- ! @Test(groups={"tck"}) ! public void factory_of_intMonthIntHMS() { ! OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, Month.JUNE, 30), ! LocalTime.of(11, 30, 10), OFFSET_PONE); ! check(test, 2008, 6, 30, 11, 30, 10, 0, OFFSET_PONE); ! } ! ! //----------------------------------------------------------------------- ! @Test(groups={"tck"}) ! public void factory_of_intMonthIntHMSN() { ! OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, Month.JUNE, 30), ! LocalTime.of(11, 30, 10, 500), OFFSET_PONE); ! check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_PONE); ! } ! ! //----------------------------------------------------------------------- ! @Test(groups={"tck"}) ! public void factory_of_intsHM() { ! OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_PONE); ! check(test, 2008, 6, 30, 11, 30, 0, 0, OFFSET_PONE); ! } ! ! //----------------------------------------------------------------------- ! @Test(groups={"tck"}) ! public void factory_of_intsHMS() { ! OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 10), OFFSET_PONE); ! check(test, 2008, 6, 30, 11, 30, 10, 0, OFFSET_PONE); ! } ! //----------------------------------------------------------------------- @Test(groups={"tck"}) public void factory_of_intsHMSN() { ! OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 10, 500), OFFSET_PONE); check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_PONE); } //----------------------------------------------------------------------- @Test(groups={"tck"}) --- 367,381 ---- assertEquals(test.hashCode(), test.hashCode()); assertEquals(OffsetDateTime.of(LocalDateTime.of(y, mo, d, h, m, s, n), offset), test); } //----------------------------------------------------------------------- ! // factories //----------------------------------------------------------------------- @Test(groups={"tck"}) public void factory_of_intsHMSN() { ! OffsetDateTime test = OffsetDateTime.of(2008, 6, 30, 11, 30, 10, 500, OFFSET_PONE); check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_PONE); } //----------------------------------------------------------------------- @Test(groups={"tck"})
*** 521,538 **** //----------------------------------------------------------------------- // parse(DateTimeFormatter) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void factory_parse_formatter() { ! DateTimeFormatter f = DateTimeFormatters.pattern("y M d H m s XXX"); OffsetDateTime test = OffsetDateTime.parse("2010 12 3 11 30 0 +01:00", f); assertEquals(test, OffsetDateTime.of(LocalDate.of(2010, 12, 3), LocalTime.of(11, 30), ZoneOffset.ofHours(1))); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void factory_parse_formatter_nullText() { ! DateTimeFormatter f = DateTimeFormatters.pattern("y M d H m s"); OffsetDateTime.parse((String) null, f); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void factory_parse_formatter_nullFormatter() { --- 478,495 ---- //----------------------------------------------------------------------- // parse(DateTimeFormatter) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void factory_parse_formatter() { ! DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s XXX"); OffsetDateTime test = OffsetDateTime.parse("2010 12 3 11 30 0 +01:00", f); assertEquals(test, OffsetDateTime.of(LocalDate.of(2010, 12, 3), LocalTime.of(11, 30), ZoneOffset.ofHours(1))); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void factory_parse_formatter_nullText() { ! DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s"); OffsetDateTime.parse((String) null, f); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void factory_parse_formatter_nullFormatter() {
*** 591,601 **** assertEquals(a.getHour(), localDateTime.getHour()); assertEquals(a.getMinute(), localDateTime.getMinute()); assertEquals(a.getSecond(), localDateTime.getSecond()); assertEquals(a.getNano(), localDateTime.getNano()); - assertEquals(a.toOffsetDate(), OffsetDate.of(localDate, offset)); assertEquals(a.toOffsetTime(), OffsetTime.of(localTime, offset)); assertEquals(a.toString(), localDateTime.toString() + offset.toString()); } //----------------------------------------------------------------------- --- 548,557 ----
*** 641,678 **** } //----------------------------------------------------------------------- // query(TemporalQuery) //----------------------------------------------------------------------- ! @Test ! public void test_query_chrono() { ! assertEquals(TEST_2008_6_30_11_30_59_000000500.query(Queries.chrono()), ISOChrono.INSTANCE); ! assertEquals(Queries.chrono().queryFrom(TEST_2008_6_30_11_30_59_000000500), ISOChrono.INSTANCE); ! } ! ! @Test ! public void test_query_zoneId() { ! assertEquals(TEST_2008_6_30_11_30_59_000000500.query(Queries.zoneId()), null); ! assertEquals(Queries.zoneId().queryFrom(TEST_2008_6_30_11_30_59_000000500), null); ! } ! ! @Test ! public void test_query_precision() { ! assertEquals(TEST_2008_6_30_11_30_59_000000500.query(Queries.precision()), NANOS); ! assertEquals(Queries.precision().queryFrom(TEST_2008_6_30_11_30_59_000000500), NANOS); } ! @Test ! public void test_query_offset() { ! assertEquals(TEST_2008_6_30_11_30_59_000000500.query(Queries.offset()), OFFSET_PONE); ! assertEquals(Queries.offset().queryFrom(TEST_2008_6_30_11_30_59_000000500), OFFSET_PONE); } ! @Test ! public void test_query_zone() { ! assertEquals(TEST_2008_6_30_11_30_59_000000500.query(Queries.zone()), OFFSET_PONE); ! assertEquals(Queries.zone().queryFrom(TEST_2008_6_30_11_30_59_000000500), OFFSET_PONE); } @Test(expectedExceptions=NullPointerException.class) public void test_query_null() { TEST_2008_6_30_11_30_59_000000500.query(null); --- 597,627 ---- } //----------------------------------------------------------------------- // query(TemporalQuery) //----------------------------------------------------------------------- ! @DataProvider(name="query") ! Object[][] data_query() { ! return new Object[][] { ! {TEST_2008_6_30_11_30_59_000000500, Queries.chronology(), IsoChronology.INSTANCE}, ! {TEST_2008_6_30_11_30_59_000000500, Queries.zoneId(), null}, ! {TEST_2008_6_30_11_30_59_000000500, Queries.precision(), ChronoUnit.NANOS}, ! {TEST_2008_6_30_11_30_59_000000500, Queries.zone(), OFFSET_PONE}, ! {TEST_2008_6_30_11_30_59_000000500, Queries.offset(), OFFSET_PONE}, ! {TEST_2008_6_30_11_30_59_000000500, Queries.localDate(), LocalDate.of(2008, 6, 30)}, ! {TEST_2008_6_30_11_30_59_000000500, Queries.localTime(), LocalTime.of(11, 30, 59, 500)}, ! }; } ! @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_2008_6_30_11_30_59_000000500.query(null);
*** 710,725 **** OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(LocalDateTime.of(LocalDate.of(2012, 9, 3), LocalTime.of(19, 15))); assertEquals(test, OffsetDateTime.of(LocalDate.of(2012, 9, 3), LocalTime.of(19, 15), OFFSET_PONE)); } @Test(groups={"tck"}) - public void test_with_adjustment_OffsetDate() { - OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(OffsetDate.of(LocalDate.of(2012, 9, 3), OFFSET_PTWO)); - assertEquals(test, OffsetDateTime.of(LocalDate.of(2012, 9, 3), LocalTime.of(11, 30, 59, 500), OFFSET_PTWO)); - } - - @Test(groups={"tck"}) public void test_with_adjustment_OffsetTime() { OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(OffsetTime.of(LocalTime.of(19, 15), OFFSET_PTWO)); assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(19, 15), OFFSET_PTWO)); } --- 659,668 ----
*** 878,898 **** //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plus_Period() { MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS); OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.plus(period); ! assertEquals(t, OffsetDateTime.of(LocalDate.of(2009, 1, 30), LocalTime.of(11, 30, 59, 500), OFFSET_PONE)); } //----------------------------------------------------------------------- // plus(Duration) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plus_Duration() { Duration dur = Duration.ofSeconds(62, 3); OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.plus(dur); ! assertEquals(t, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 32, 1, 503), OFFSET_PONE)); } @Test(groups={"tck"}) public void test_plus_Duration_zero() { OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.plus(Duration.ZERO); --- 821,841 ---- //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plus_Period() { MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS); OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.plus(period); ! assertEquals(t, OffsetDateTime.of(2009, 1, 30, 11, 30, 59, 500, OFFSET_PONE)); } //----------------------------------------------------------------------- // plus(Duration) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plus_Duration() { Duration dur = Duration.ofSeconds(62, 3); OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.plus(dur); ! assertEquals(t, OffsetDateTime.of(2008, 6, 30, 11, 32, 1, 503, OFFSET_PONE)); } @Test(groups={"tck"}) public void test_plus_Duration_zero() { OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.plus(Duration.ZERO);
*** 907,1009 **** //----------------------------------------------------------------------- // plusYears() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusYears() { ! OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetDateTime test = base.plusYears(1); ! assertEquals(test, OffsetDateTime.of(LocalDate.of(2009, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE)); } //----------------------------------------------------------------------- // plusMonths() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusMonths() { ! OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetDateTime test = base.plusMonths(1); ! assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 7, 30), LocalTime.of(11, 30, 59), OFFSET_PONE)); } //----------------------------------------------------------------------- // plusWeeks() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusWeeks() { ! OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetDateTime test = base.plusWeeks(1); ! assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 7, 7), LocalTime.of(11, 30, 59), OFFSET_PONE)); } //----------------------------------------------------------------------- // plusDays() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusDays() { ! OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetDateTime test = base.plusDays(1); ! assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 7, 1), LocalTime.of(11, 30, 59), OFFSET_PONE)); } //----------------------------------------------------------------------- // plusHours() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusHours() { ! OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetDateTime test = base.plusHours(13); ! assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 7, 1), LocalTime.of(0, 30, 59), OFFSET_PONE)); } //----------------------------------------------------------------------- // plusMinutes() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusMinutes() { ! OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetDateTime test = base.plusMinutes(30); ! assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(12, 0, 59), OFFSET_PONE)); } //----------------------------------------------------------------------- // plusSeconds() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusSeconds() { ! OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetDateTime test = base.plusSeconds(1); ! assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 31, 0), OFFSET_PONE)); } //----------------------------------------------------------------------- // plusNanos() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusNanos() { ! OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 0), OFFSET_PONE); OffsetDateTime test = base.plusNanos(1); ! assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 1), OFFSET_PONE)); } //----------------------------------------------------------------------- // minus(Period) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minus_Period() { MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS); OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.minus(period); ! assertEquals(t, OffsetDateTime.of(LocalDate.of(2007, 11, 30), LocalTime.of(11, 30, 59, 500), OFFSET_PONE)); } //----------------------------------------------------------------------- // minus(Duration) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minus_Duration() { Duration dur = Duration.ofSeconds(62, 3); OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.minus(dur); ! assertEquals(t, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 29, 57, 497), OFFSET_PONE)); } @Test(groups={"tck"}) public void test_minus_Duration_zero() { OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.minus(Duration.ZERO); --- 850,952 ---- //----------------------------------------------------------------------- // plusYears() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusYears() { ! OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); OffsetDateTime test = base.plusYears(1); ! assertEquals(test, OffsetDateTime.of(2009, 6, 30, 11, 30, 59, 0, OFFSET_PONE)); } //----------------------------------------------------------------------- // plusMonths() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusMonths() { ! OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); OffsetDateTime test = base.plusMonths(1); ! assertEquals(test, OffsetDateTime.of(2008, 7, 30, 11, 30, 59, 0, OFFSET_PONE)); } //----------------------------------------------------------------------- // plusWeeks() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusWeeks() { ! OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); OffsetDateTime test = base.plusWeeks(1); ! assertEquals(test, OffsetDateTime.of(2008, 7, 7, 11, 30, 59, 0, OFFSET_PONE)); } //----------------------------------------------------------------------- // plusDays() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusDays() { ! OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); OffsetDateTime test = base.plusDays(1); ! assertEquals(test, OffsetDateTime.of(2008, 7, 1, 11, 30, 59, 0, OFFSET_PONE)); } //----------------------------------------------------------------------- // plusHours() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusHours() { ! OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); OffsetDateTime test = base.plusHours(13); ! assertEquals(test, OffsetDateTime.of(2008, 7, 1, 0, 30, 59, 0, OFFSET_PONE)); } //----------------------------------------------------------------------- // plusMinutes() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusMinutes() { ! OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); OffsetDateTime test = base.plusMinutes(30); ! assertEquals(test, OffsetDateTime.of(2008, 6, 30, 12, 0, 59, 0, OFFSET_PONE)); } //----------------------------------------------------------------------- // plusSeconds() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusSeconds() { ! OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); OffsetDateTime test = base.plusSeconds(1); ! assertEquals(test, OffsetDateTime.of(2008, 6, 30, 11, 31, 0, 0, OFFSET_PONE)); } //----------------------------------------------------------------------- // plusNanos() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusNanos() { ! OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); OffsetDateTime test = base.plusNanos(1); ! assertEquals(test, OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 1, OFFSET_PONE)); } //----------------------------------------------------------------------- // minus(Period) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minus_Period() { MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS); OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.minus(period); ! assertEquals(t, OffsetDateTime.of(2007, 11, 30, 11, 30, 59, 500, OFFSET_PONE)); } //----------------------------------------------------------------------- // minus(Duration) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minus_Duration() { Duration dur = Duration.ofSeconds(62, 3); OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.minus(dur); ! assertEquals(t, OffsetDateTime.of(2008, 6, 30, 11, 29, 57, 497, OFFSET_PONE)); } @Test(groups={"tck"}) public void test_minus_Duration_zero() { OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.minus(Duration.ZERO);
*** 1018,1290 **** //----------------------------------------------------------------------- // minusYears() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusYears() { ! OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetDateTime test = base.minusYears(1); ! assertEquals(test, OffsetDateTime.of(LocalDate.of(2007, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE)); } //----------------------------------------------------------------------- // minusMonths() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusMonths() { ! OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetDateTime test = base.minusMonths(1); ! assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 5, 30), LocalTime.of(11, 30, 59), OFFSET_PONE)); } //----------------------------------------------------------------------- // minusWeeks() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusWeeks() { ! OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetDateTime test = base.minusWeeks(1); ! assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 23), LocalTime.of(11, 30, 59), OFFSET_PONE)); } //----------------------------------------------------------------------- // minusDays() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusDays() { ! OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetDateTime test = base.minusDays(1); ! assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 29), LocalTime.of(11, 30, 59), OFFSET_PONE)); } //----------------------------------------------------------------------- // minusHours() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusHours() { ! OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetDateTime test = base.minusHours(13); ! assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 29), LocalTime.of(22, 30, 59), OFFSET_PONE)); } //----------------------------------------------------------------------- // minusMinutes() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusMinutes() { ! OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetDateTime test = base.minusMinutes(30); ! assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 0, 59), OFFSET_PONE)); } //----------------------------------------------------------------------- // minusSeconds() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusSeconds() { ! OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetDateTime test = base.minusSeconds(1); ! assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 58), OFFSET_PONE)); } //----------------------------------------------------------------------- // minusNanos() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusNanos() { ! OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 0), OFFSET_PONE); OffsetDateTime test = base.minusNanos(1); ! assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 58, 999999999), OFFSET_PONE)); } //----------------------------------------------------------------------- // atZoneSameInstant() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_atZone() { ! OffsetDateTime t = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_MTWO); assertEquals(t.atZoneSameInstant(ZONE_PARIS), ! ZonedDateTime.of(LocalDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(15, 30)), ZONE_PARIS)); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_atZone_nullTimeZone() { ! OffsetDateTime t = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_PTWO); t.atZoneSameInstant((ZoneId) null); } //----------------------------------------------------------------------- // atZoneSimilarLocal() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_atZoneSimilarLocal() { ! OffsetDateTime t = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_MTWO); assertEquals(t.atZoneSimilarLocal(ZONE_PARIS), ! ZonedDateTime.of(LocalDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30)), ZONE_PARIS)); } @Test(groups={"tck"}) public void test_atZoneSimilarLocal_dstGap() { ! OffsetDateTime t = OffsetDateTime.of(LocalDate.of(2007, 4, 1), LocalTime.of(0, 0), OFFSET_MTWO); assertEquals(t.atZoneSimilarLocal(ZONE_GAZA), ! ZonedDateTime.of(LocalDateTime.of(LocalDate.of(2007, 4, 1), LocalTime.of(1, 0)), ZONE_GAZA)); } @Test(groups={"tck"}) public void test_atZone_dstOverlapSummer() { ! OffsetDateTime t = OffsetDateTime.of(LocalDate.of(2007, 10, 28), LocalTime.of(2, 30), OFFSET_PTWO); ! assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getDateTime(), t.getDateTime()); assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getOffset(), OFFSET_PTWO); assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getZone(), ZONE_PARIS); } @Test(groups={"tck"}) public void test_atZone_dstOverlapWinter() { ! OffsetDateTime t = OffsetDateTime.of(LocalDate.of(2007, 10, 28), LocalTime.of(2, 30), OFFSET_PONE); ! assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getDateTime(), t.getDateTime()); assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getOffset(), OFFSET_PONE); assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getZone(), ZONE_PARIS); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_atZoneSimilarLocal_nullTimeZone() { ! OffsetDateTime t = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_PTWO); t.atZoneSimilarLocal((ZoneId) null); } //----------------------------------------------------------------------- // toEpochSecond() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_toEpochSecond_afterEpoch() { for (int i = 0; i < 100000; i++) { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(1970, 1, 1), LocalTime.of(0, 0), ZoneOffset.UTC).plusSeconds(i); assertEquals(a.toEpochSecond(), i); } } @Test(groups={"tck"}) public void test_toEpochSecond_beforeEpoch() { for (int i = 0; i < 100000; i++) { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(1970, 1, 1), LocalTime.of(0, 0), ZoneOffset.UTC).minusSeconds(i); assertEquals(a.toEpochSecond(), -i); } } //----------------------------------------------------------------------- // compareTo() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_compareTo_timeMins() { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 29, 3), OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 2), OFFSET_PONE); // a is before b due to time assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_timeSecs() { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 29, 2), OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 29, 3), OFFSET_PONE); // a is before b due to time assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_timeNanos() { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 29, 40, 4), OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 29, 40, 5), OFFSET_PONE); // a is before b due to time assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_offset() { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_PTWO); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_PONE); // a is before b due to offset assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_offsetNanos() { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 40, 6), OFFSET_PTWO); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 40, 5), OFFSET_PONE); // a is before b due to offset assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_both() { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 50), OFFSET_PTWO); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 20), OFFSET_PONE); // a is before b on instant scale assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_bothNanos() { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 20, 40, 4), OFFSET_PTWO); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(10, 20, 40, 5), OFFSET_PONE); // a is before b on instant scale assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_hourDifference() { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(10, 0), OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 0), OFFSET_PTWO); // a is before b despite being same time-line time assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); assertEquals(a.toInstant().compareTo(b.toInstant()) == 0, true); } @Test(groups={"tck"}) public void test_compareTo_max() { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(Year.MAX_VALUE, 12, 31), LocalTime.of(23, 59), OFFSET_MONE); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(Year.MAX_VALUE, 12, 31), LocalTime.of(23, 59), OFFSET_MTWO); // a is before b due to offset assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); } @Test(groups={"tck"}) public void test_compareTo_min() { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(Year.MIN_VALUE, 1, 1), LocalTime.of(0, 0), OFFSET_PTWO); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(Year.MIN_VALUE, 1, 1), LocalTime.of(0, 0), OFFSET_PONE); // a is before b due to offset assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_compareTo_null() { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE); a.compareTo(null); } @Test(expectedExceptions=ClassCastException.class, groups={"tck"}) @SuppressWarnings({"unchecked", "rawtypes"}) --- 961,1233 ---- //----------------------------------------------------------------------- // minusYears() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusYears() { ! OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); OffsetDateTime test = base.minusYears(1); ! assertEquals(test, OffsetDateTime.of(2007, 6, 30, 11, 30, 59, 0, OFFSET_PONE)); } //----------------------------------------------------------------------- // minusMonths() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusMonths() { ! OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); OffsetDateTime test = base.minusMonths(1); ! assertEquals(test, OffsetDateTime.of(2008, 5, 30, 11, 30, 59, 0, OFFSET_PONE)); } //----------------------------------------------------------------------- // minusWeeks() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusWeeks() { ! OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); OffsetDateTime test = base.minusWeeks(1); ! assertEquals(test, OffsetDateTime.of(2008, 6, 23, 11, 30, 59, 0, OFFSET_PONE)); } //----------------------------------------------------------------------- // minusDays() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusDays() { ! OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); OffsetDateTime test = base.minusDays(1); ! assertEquals(test, OffsetDateTime.of(2008, 6, 29, 11, 30, 59, 0, OFFSET_PONE)); } //----------------------------------------------------------------------- // minusHours() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusHours() { ! OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); OffsetDateTime test = base.minusHours(13); ! assertEquals(test, OffsetDateTime.of(2008, 6, 29, 22, 30, 59, 0, OFFSET_PONE)); } //----------------------------------------------------------------------- // minusMinutes() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusMinutes() { ! OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); OffsetDateTime test = base.minusMinutes(30); ! assertEquals(test, OffsetDateTime.of(2008, 6, 30, 11, 0, 59, 0, OFFSET_PONE)); } //----------------------------------------------------------------------- // minusSeconds() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusSeconds() { ! OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); OffsetDateTime test = base.minusSeconds(1); ! assertEquals(test, OffsetDateTime.of(2008, 6, 30, 11, 30, 58, 0, OFFSET_PONE)); } //----------------------------------------------------------------------- // minusNanos() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusNanos() { ! OffsetDateTime base = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); OffsetDateTime test = base.minusNanos(1); ! assertEquals(test, OffsetDateTime.of(2008, 6, 30, 11, 30, 58, 999999999, OFFSET_PONE)); } //----------------------------------------------------------------------- // atZoneSameInstant() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_atZone() { ! OffsetDateTime t = OffsetDateTime.of(2008, 6, 30, 11, 30, 0, 0, OFFSET_MTWO); assertEquals(t.atZoneSameInstant(ZONE_PARIS), ! ZonedDateTime.of(2008, 6, 30, 15, 30, 0, 0, ZONE_PARIS)); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_atZone_nullTimeZone() { ! OffsetDateTime t = OffsetDateTime.of(2008, 6, 30, 11, 30, 0, 0, OFFSET_PTWO); t.atZoneSameInstant((ZoneId) null); } //----------------------------------------------------------------------- // atZoneSimilarLocal() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_atZoneSimilarLocal() { ! OffsetDateTime t = OffsetDateTime.of(2008, 6, 30, 11, 30, 0, 0, OFFSET_MTWO); assertEquals(t.atZoneSimilarLocal(ZONE_PARIS), ! ZonedDateTime.of(2008, 6, 30, 11, 30, 0, 0, ZONE_PARIS)); } @Test(groups={"tck"}) public void test_atZoneSimilarLocal_dstGap() { ! OffsetDateTime t = OffsetDateTime.of(2007, 4, 1, 0, 0, 0, 0, OFFSET_MTWO); assertEquals(t.atZoneSimilarLocal(ZONE_GAZA), ! ZonedDateTime.of(2007, 4, 1, 1, 0, 0, 0, ZONE_GAZA)); } @Test(groups={"tck"}) public void test_atZone_dstOverlapSummer() { ! OffsetDateTime t = OffsetDateTime.of(2007, 10, 28, 2, 30, 0, 0, OFFSET_PTWO); ! assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).toLocalDateTime(), t.toLocalDateTime()); assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getOffset(), OFFSET_PTWO); assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getZone(), ZONE_PARIS); } @Test(groups={"tck"}) public void test_atZone_dstOverlapWinter() { ! OffsetDateTime t = OffsetDateTime.of(2007, 10, 28, 2, 30, 0, 0, OFFSET_PONE); ! assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).toLocalDateTime(), t.toLocalDateTime()); assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getOffset(), OFFSET_PONE); assertEquals(t.atZoneSimilarLocal(ZONE_PARIS).getZone(), ZONE_PARIS); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_atZoneSimilarLocal_nullTimeZone() { ! OffsetDateTime t = OffsetDateTime.of(2008, 6, 30, 11, 30, 0, 0, OFFSET_PTWO); t.atZoneSimilarLocal((ZoneId) null); } //----------------------------------------------------------------------- // toEpochSecond() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_toEpochSecond_afterEpoch() { for (int i = 0; i < 100000; i++) { ! OffsetDateTime a = OffsetDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).plusSeconds(i); assertEquals(a.toEpochSecond(), i); } } @Test(groups={"tck"}) public void test_toEpochSecond_beforeEpoch() { for (int i = 0; i < 100000; i++) { ! OffsetDateTime a = OffsetDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).minusSeconds(i); assertEquals(a.toEpochSecond(), -i); } } //----------------------------------------------------------------------- // compareTo() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_compareTo_timeMins() { ! OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 29, 3, 0, OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 30, 2, 0, OFFSET_PONE); // a is before b due to time assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_timeSecs() { ! OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 29, 2, 0, OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 29, 3, 0, OFFSET_PONE); // a is before b due to time assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_timeNanos() { ! OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 29, 40, 4, OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 29, 40, 5, OFFSET_PONE); // a is before b due to time assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_offset() { ! OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 0, 0, OFFSET_PTWO); ! OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 30, 0, 0, OFFSET_PONE); // a is before b due to offset assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_offsetNanos() { ! OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 40, 6, OFFSET_PTWO); ! OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 30, 40, 5, OFFSET_PONE); // a is before b due to offset assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_both() { ! OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 50, 0, 0, OFFSET_PTWO); ! OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 20, 0, 0, OFFSET_PONE); // a is before b on instant scale assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_bothNanos() { ! OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 20, 40, 4, OFFSET_PTWO); ! OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 10, 20, 40, 5, OFFSET_PONE); // a is before b on instant scale assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_hourDifference() { ! OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 10, 0, 0, 0, OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 0, 0, 0, OFFSET_PTWO); // a is before b despite being same time-line time assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); assertEquals(a.toInstant().compareTo(b.toInstant()) == 0, true); } @Test(groups={"tck"}) public void test_compareTo_max() { ! OffsetDateTime a = OffsetDateTime.of(Year.MAX_VALUE, 12, 31, 23, 59, 0, 0, OFFSET_MONE); ! OffsetDateTime b = OffsetDateTime.of(Year.MAX_VALUE, 12, 31, 23, 59, 0, 0, OFFSET_MTWO); // a is before b due to offset assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); } @Test(groups={"tck"}) public void test_compareTo_min() { ! OffsetDateTime a = OffsetDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0, 0, 0, OFFSET_PTWO); ! OffsetDateTime b = OffsetDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0, 0, 0, OFFSET_PONE); // a is before b due to offset assertEquals(a.compareTo(b) < 0, true); assertEquals(b.compareTo(a) > 0, true); assertEquals(a.compareTo(a) == 0, true); assertEquals(b.compareTo(b) == 0, true); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_compareTo_null() { ! OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); a.compareTo(null); } @Test(expectedExceptions=ClassCastException.class, groups={"tck"}) @SuppressWarnings({"unchecked", "rawtypes"})
*** 1296,1307 **** //----------------------------------------------------------------------- // isAfter() / isBefore() / isEqual() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_isBeforeIsAfterIsEqual1() { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 58, 3), OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 2), OFFSET_PONE); // a is before b due to time assertEquals(a.isBefore(b), true); assertEquals(a.isEqual(b), false); assertEquals(a.isAfter(b), false); assertEquals(b.isBefore(a), false); --- 1239,1250 ---- //----------------------------------------------------------------------- // isAfter() / isBefore() / isEqual() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_isBeforeIsAfterIsEqual1() { ! OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 58, 3, OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 2, OFFSET_PONE); // a is before b due to time assertEquals(a.isBefore(b), true); assertEquals(a.isEqual(b), false); assertEquals(a.isAfter(b), false); assertEquals(b.isBefore(a), false);
*** 1318,1329 **** assertEquals(b.isAfter(b), false); } @Test(groups={"tck"}) public void test_isBeforeIsAfterIsEqual2() { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 2), OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 3), OFFSET_PONE); // a is before b due to time assertEquals(a.isBefore(b), true); assertEquals(a.isEqual(b), false); assertEquals(a.isAfter(b), false); assertEquals(b.isBefore(a), false); --- 1261,1272 ---- assertEquals(b.isAfter(b), false); } @Test(groups={"tck"}) public void test_isBeforeIsAfterIsEqual2() { ! OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 2, OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 3, OFFSET_PONE); // a is before b due to time assertEquals(a.isBefore(b), true); assertEquals(a.isEqual(b), false); assertEquals(a.isAfter(b), false); assertEquals(b.isBefore(a), false);
*** 1340,1351 **** assertEquals(b.isAfter(b), false); } @Test(groups={"tck"}) public void test_isBeforeIsAfterIsEqual_instantComparison() { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(10, 0), OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 0), OFFSET_PTWO); // a is same instant as b assertEquals(a.isBefore(b), false); assertEquals(a.isEqual(b), true); assertEquals(a.isAfter(b), false); assertEquals(b.isBefore(a), false); --- 1283,1294 ---- assertEquals(b.isAfter(b), false); } @Test(groups={"tck"}) public void test_isBeforeIsAfterIsEqual_instantComparison() { ! OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 10, 0, 0, 0, OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 11, 0, 0, 0, OFFSET_PTWO); // a is same instant as b assertEquals(a.isBefore(b), false); assertEquals(a.isEqual(b), true); assertEquals(a.isAfter(b), false); assertEquals(b.isBefore(a), false);
*** 1362,1435 **** assertEquals(b.isAfter(b), false); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_isBefore_null() { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE); a.isBefore(null); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_isEqual_null() { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE); a.isEqual(null); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_isAfter_null() { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE); a.isAfter(null); } //----------------------------------------------------------------------- // equals() / hashCode() //----------------------------------------------------------------------- @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_equals_true(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), OFFSET_PONE); assertEquals(a.equals(b), true); assertEquals(a.hashCode() == b.hashCode(), true); } @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_equals_false_year_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(y + 1, o, d), LocalTime.of(h, m, s, n), OFFSET_PONE); assertEquals(a.equals(b), false); } @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_equals_false_hour_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) { h = (h == 23 ? 22 : h); ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h + 1, m, s, n), OFFSET_PONE); assertEquals(a.equals(b), false); } @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_equals_false_minute_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) { m = (m == 59 ? 58 : m); ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m + 1, s, n), OFFSET_PONE); assertEquals(a.equals(b), false); } @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_equals_false_second_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) { s = (s == 59 ? 58 : s); ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s + 1, n), OFFSET_PONE); assertEquals(a.equals(b), false); } @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_equals_false_nano_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) { n = (n == 999999999 ? 999999998 : n); ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n + 1), OFFSET_PONE); assertEquals(a.equals(b), false); } @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_equals_false_offset_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) { ! OffsetDateTime a = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), OFFSET_PTWO); assertEquals(a.equals(b), false); } @Test(groups={"tck"}) public void test_equals_itself_true() { --- 1305,1378 ---- assertEquals(b.isAfter(b), false); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_isBefore_null() { ! OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); a.isBefore(null); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_isEqual_null() { ! OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); a.isEqual(null); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_isAfter_null() { ! OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 0, OFFSET_PONE); a.isAfter(null); } //----------------------------------------------------------------------- // equals() / hashCode() //----------------------------------------------------------------------- @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_equals_true(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) { ! OffsetDateTime a = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE); assertEquals(a.equals(b), true); assertEquals(a.hashCode() == b.hashCode(), true); } @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_equals_false_year_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) { ! OffsetDateTime a = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(y + 1, o, d, h, m, s, n, OFFSET_PONE); assertEquals(a.equals(b), false); } @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_equals_false_hour_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) { h = (h == 23 ? 22 : h); ! OffsetDateTime a = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(y, o, d, h + 1, m, s, n, OFFSET_PONE); assertEquals(a.equals(b), false); } @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_equals_false_minute_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) { m = (m == 59 ? 58 : m); ! OffsetDateTime a = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(y, o, d, h, m + 1, s, n, OFFSET_PONE); assertEquals(a.equals(b), false); } @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_equals_false_second_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) { s = (s == 59 ? 58 : s); ! OffsetDateTime a = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(y, o, d, h, m, s + 1, n, OFFSET_PONE); assertEquals(a.equals(b), false); } @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_equals_false_nano_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) { n = (n == 999999999 ? 999999998 : n); ! OffsetDateTime a = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(y, o, d, h, m, s, n + 1, OFFSET_PONE); assertEquals(a.equals(b), false); } @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_equals_false_offset_differs(int y, int o, int d, int h, int m, int s, int n, ZoneOffset ignored) { ! OffsetDateTime a = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PONE); ! OffsetDateTime b = OffsetDateTime.of(y, o, d, h, m, s, n, OFFSET_PTWO); assertEquals(a.equals(b), false); } @Test(groups={"tck"}) public void test_equals_itself_true() {
*** 1463,1488 **** }; } @Test(dataProvider="sampleToString", groups={"tck"}) public void test_toString(int y, int o, int d, int h, int m, int s, int n, String offsetId, String expected) { ! OffsetDateTime t = OffsetDateTime.of(LocalDate.of(y, o, d), LocalTime.of(h, m, s, n), ZoneOffset.of(offsetId)); String str = t.toString(); assertEquals(str, expected); } //----------------------------------------------------------------------- // toString(DateTimeFormatter) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_toString_formatter() { ! DateTimeFormatter f = DateTimeFormatters.pattern("y M d H m s"); ! String t = OffsetDateTime.of(LocalDate.of(2010, 12, 3), LocalTime.of(11, 30), OFFSET_PONE).toString(f); assertEquals(t, "2010 12 3 11 30 0"); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_toString_formatter_null() { ! OffsetDateTime.of(LocalDate.of(2010, 12, 3), LocalTime.of(11, 30), OFFSET_PONE).toString(null); } } --- 1406,1431 ---- }; } @Test(dataProvider="sampleToString", groups={"tck"}) public void test_toString(int y, int o, int d, int h, int m, int s, int n, String offsetId, String expected) { ! OffsetDateTime t = OffsetDateTime.of(y, o, d, h, m, s, n, ZoneOffset.of(offsetId)); 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 = OffsetDateTime.of(2010, 12, 3, 11, 30, 0, 0, OFFSET_PONE).toString(f); assertEquals(t, "2010 12 3 11 30 0"); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_toString_formatter_null() { ! OffsetDateTime.of(2010, 12, 3, 11, 30, 0, 0, OFFSET_PONE).toString(null); } }