test/java/time/tck/java/time/TCKOffsetTime.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.temporal.ChronoField.AMPM_OF_DAY; import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_AMPM; import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_DAY; import static java.time.temporal.ChronoField.HOUR_OF_AMPM; --- 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.temporal.ChronoField.AMPM_OF_DAY; import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_AMPM; import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_DAY; import static java.time.temporal.ChronoField.HOUR_OF_AMPM;
*** 82,130 **** import static org.testng.Assert.assertNotNull; 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.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; 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.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.TemporalAdder; import java.time.temporal.TemporalAdjuster; import java.time.temporal.TemporalField; import java.time.temporal.TemporalQuery; ! import java.time.temporal.TemporalSubtractor; 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 OffsetTime. */ --- 82,123 ---- import static org.testng.Assert.assertNotNull; 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.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; + import java.time.OffsetTime; 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.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.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 OffsetTime. */
*** 136,146 **** private static final LocalDate DATE = LocalDate.of(2008, 12, 3); private OffsetTime TEST_11_30_59_500_PONE; @BeforeMethod(groups={"tck","implementation"}) public void setUp() { ! TEST_11_30_59_500_PONE = OffsetTime.of(LocalTime.of(11, 30, 59, 500), OFFSET_PONE); } //----------------------------------------------------------------------- @Override protected List<TemporalAccessor> samples() { --- 129,139 ---- private static final LocalDate DATE = LocalDate.of(2008, 12, 3); private OffsetTime TEST_11_30_59_500_PONE; @BeforeMethod(groups={"tck","implementation"}) public void setUp() { ! TEST_11_30_59_500_PONE = OffsetTime.of(11, 30, 59, 500, OFFSET_PONE); } //----------------------------------------------------------------------- @Override protected List<TemporalAccessor> samples() {
*** 191,201 **** @Test public void test_serialization_format() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(baos) ) { ! dos.writeByte(2); } byte[] bytes = baos.toByteArray(); ByteArrayOutputStream baosTime = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(baosTime) ) { dos.writeByte(4); --- 184,194 ---- @Test public void test_serialization_format() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(baos) ) { ! dos.writeByte(9); // java.time.Ser.OFFSET_TIME_TYPE } byte[] bytes = baos.toByteArray(); ByteArrayOutputStream baosTime = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(baosTime) ) { dos.writeByte(4);
*** 209,219 **** try (DataOutputStream dos = new DataOutputStream(baosOffset) ) { dos.writeByte(8); dos.writeByte(4); // quarter hours stored: 3600 / 900 } byte[] bytesOffset = baosOffset.toByteArray(); ! assertSerializedBySer(OffsetTime.of(LocalTime.of(22, 17, 59, 464_000_000), ZoneOffset.ofHours(1)), bytes, bytesTime, bytesOffset); } //----------------------------------------------------------------------- // constants --- 202,212 ---- try (DataOutputStream dos = new DataOutputStream(baosOffset) ) { dos.writeByte(8); dos.writeByte(4); // quarter hours stored: 3600 / 900 } byte[] bytesOffset = baosOffset.toByteArray(); ! assertSerializedBySer(OffsetTime.of(22, 17, 59, 464_000_000, ZoneOffset.ofHours(1)), bytes, bytesTime, bytesOffset); } //----------------------------------------------------------------------- // constants
*** 235,245 **** public void now() { ZonedDateTime nowDT = ZonedDateTime.now(); OffsetTime expected = OffsetTime.now(Clock.systemDefaultZone()); OffsetTime test = OffsetTime.now(); ! long diff = Math.abs(test.getTime().toNanoOfDay() - expected.getTime().toNanoOfDay()); assertTrue(diff < 100000000); // less than 0.1 secs assertEquals(test.getOffset(), nowDT.getOffset()); } //----------------------------------------------------------------------- --- 228,238 ---- public void now() { ZonedDateTime nowDT = ZonedDateTime.now(); OffsetTime expected = OffsetTime.now(Clock.systemDefaultZone()); OffsetTime test = OffsetTime.now(); ! long diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay()); assertTrue(diff < 100000000); // less than 0.1 secs assertEquals(test.getOffset(), nowDT.getOffset()); } //-----------------------------------------------------------------------
*** 300,310 **** //----------------------------------------------------------------------- // factories //----------------------------------------------------------------------- private void check(OffsetTime test, int h, int m, int s, int n, ZoneOffset offset) { ! assertEquals(test.getTime(), LocalTime.of(h, m, s, n)); assertEquals(test.getOffset(), offset); assertEquals(test.getHour(), h); assertEquals(test.getMinute(), m); assertEquals(test.getSecond(), s); --- 293,303 ---- //----------------------------------------------------------------------- // factories //----------------------------------------------------------------------- private void check(OffsetTime test, int h, int m, int s, int n, ZoneOffset offset) { ! assertEquals(test.toLocalTime(), LocalTime.of(h, m, s, n)); assertEquals(test.getOffset(), offset); assertEquals(test.getHour(), h); assertEquals(test.getMinute(), m); assertEquals(test.getSecond(), s);
*** 315,340 **** assertEquals(OffsetTime.of(LocalTime.of(h, m, s, n), offset), test); } //----------------------------------------------------------------------- @Test(groups={"tck"}) - public void factory_intsHM() { - OffsetTime test = OffsetTime.of(LocalTime.of(11, 30), OFFSET_PONE); - check(test, 11, 30, 0, 0, OFFSET_PONE); - } - - //----------------------------------------------------------------------- - @Test(groups={"tck"}) - public void factory_intsHMS() { - OffsetTime test = OffsetTime.of(LocalTime.of(11, 30, 10), OFFSET_PONE); - check(test, 11, 30, 10, 0, OFFSET_PONE); - } - - //----------------------------------------------------------------------- - @Test(groups={"tck"}) public void factory_intsHMSN() { ! OffsetTime test = OffsetTime.of(LocalTime.of(11, 30, 10, 500), OFFSET_PONE); check(test, 11, 30, 10, 500, OFFSET_PONE); } //----------------------------------------------------------------------- @Test(groups={"tck"}) --- 308,319 ---- assertEquals(OffsetTime.of(LocalTime.of(h, m, s, n), offset), test); } //----------------------------------------------------------------------- @Test(groups={"tck"}) public void factory_intsHMSN() { ! OffsetTime test = OffsetTime.of(11, 30, 10, 500, OFFSET_PONE); check(test, 11, 30, 10, 500, OFFSET_PONE); } //----------------------------------------------------------------------- @Test(groups={"tck"})
*** 415,425 **** //----------------------------------------------------------------------- // from(TemporalAccessor) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void factory_from_TemporalAccessor_OT() { ! assertEquals(OffsetTime.from(OffsetTime.of(LocalTime.of(17, 30), OFFSET_PONE)), OffsetTime.of(LocalTime.of(17, 30), OFFSET_PONE)); } @Test(groups={"tck"}) public void test_from_TemporalAccessor_ZDT() { ZonedDateTime base = LocalDateTime.of(2007, 7, 15, 11, 30, 59, 500).atZone(OFFSET_PONE); --- 394,404 ---- //----------------------------------------------------------------------- // from(TemporalAccessor) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void factory_from_TemporalAccessor_OT() { ! assertEquals(OffsetTime.from(OffsetTime.of(17, 30, 0, 0, OFFSET_PONE)), OffsetTime.of(17, 30, 0, 0, OFFSET_PONE)); } @Test(groups={"tck"}) public void test_from_TemporalAccessor_ZDT() { ZonedDateTime base = LocalDateTime.of(2007, 7, 15, 11, 30, 59, 500).atZone(OFFSET_PONE);
*** 485,502 **** //----------------------------------------------------------------------- // parse(DateTimeFormatter) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void factory_parse_formatter() { ! DateTimeFormatter f = DateTimeFormatters.pattern("H m s XXX"); OffsetTime test = OffsetTime.parse("11 30 0 +01:00", f); ! assertEquals(test, OffsetTime.of(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"); OffsetTime.parse((String) null, f); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void factory_parse_formatter_nullFormatter() { --- 464,481 ---- //----------------------------------------------------------------------- // parse(DateTimeFormatter) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void factory_parse_formatter() { ! DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s XXX"); OffsetTime test = OffsetTime.parse("11 30 0 +01:00", f); ! assertEquals(test, OffsetTime.of(11, 30, 0, 0, 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"); OffsetTime.parse((String) null, f); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void factory_parse_formatter_nullFormatter() {
*** 520,530 **** @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void constructor_nullOffset() throws Throwable { Constructor<OffsetTime> con = OffsetTime.class.getDeclaredConstructor(LocalTime.class, ZoneOffset.class); con.setAccessible(true); try { ! con.newInstance(LocalTime.of(11, 30), null); } catch (InvocationTargetException ex) { throw ex.getCause(); } } --- 499,509 ---- @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void constructor_nullOffset() throws Throwable { Constructor<OffsetTime> con = OffsetTime.class.getDeclaredConstructor(LocalTime.class, ZoneOffset.class); con.setAccessible(true); try { ! con.newInstance(LocalTime.of(11, 30, 0, 0), null); } catch (InvocationTargetException ex) { throw ex.getCause(); } }
*** 543,553 **** @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_get(int h, int m, int s, int n, ZoneOffset offset) { LocalTime localTime = LocalTime.of(h, m, s, n); OffsetTime a = OffsetTime.of(localTime, offset); ! assertEquals(a.getTime(), localTime); assertEquals(a.getOffset(), offset); assertEquals(a.toString(), localTime.toString() + offset.toString()); assertEquals(a.getHour(), localTime.getHour()); assertEquals(a.getMinute(), localTime.getMinute()); assertEquals(a.getSecond(), localTime.getSecond()); --- 522,532 ---- @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_get(int h, int m, int s, int n, ZoneOffset offset) { LocalTime localTime = LocalTime.of(h, m, s, n); OffsetTime a = OffsetTime.of(localTime, offset); ! assertEquals(a.toLocalTime(), localTime); assertEquals(a.getOffset(), offset); assertEquals(a.toString(), localTime.toString() + offset.toString()); assertEquals(a.getHour(), localTime.getHour()); assertEquals(a.getMinute(), localTime.getMinute()); assertEquals(a.getSecond(), localTime.getSecond());
*** 557,567 **** //----------------------------------------------------------------------- // get(TemporalField) //----------------------------------------------------------------------- @Test public void test_get_TemporalField() { ! OffsetTime test = OffsetTime.of(LocalTime.of(12, 30, 40, 987654321), OFFSET_PONE); assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12); assertEquals(test.get(ChronoField.MINUTE_OF_HOUR), 30); assertEquals(test.get(ChronoField.SECOND_OF_MINUTE), 40); assertEquals(test.get(ChronoField.NANO_OF_SECOND), 987654321); assertEquals(test.get(ChronoField.HOUR_OF_AMPM), 0); --- 536,546 ---- //----------------------------------------------------------------------- // get(TemporalField) //----------------------------------------------------------------------- @Test public void test_get_TemporalField() { ! OffsetTime test = OffsetTime.of(12, 30, 40, 987654321, OFFSET_PONE); assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12); assertEquals(test.get(ChronoField.MINUTE_OF_HOUR), 30); assertEquals(test.get(ChronoField.SECOND_OF_MINUTE), 40); assertEquals(test.get(ChronoField.NANO_OF_SECOND), 987654321); assertEquals(test.get(ChronoField.HOUR_OF_AMPM), 0);
*** 570,580 **** assertEquals(test.get(ChronoField.OFFSET_SECONDS), 3600); } @Test public void test_getLong_TemporalField() { ! OffsetTime test = OffsetTime.of(LocalTime.of(12, 30, 40, 987654321), OFFSET_PONE); assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12); assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30); assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40); assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321); assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0); --- 549,559 ---- assertEquals(test.get(ChronoField.OFFSET_SECONDS), 3600); } @Test public void test_getLong_TemporalField() { ! OffsetTime test = OffsetTime.of(12, 30, 40, 987654321, OFFSET_PONE); assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12); assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30); assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40); assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321); assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0);
*** 584,621 **** } //----------------------------------------------------------------------- // query(TemporalQuery) //----------------------------------------------------------------------- ! @Test ! public void test_query_chrono() { ! assertEquals(TEST_11_30_59_500_PONE.query(Queries.chrono()), null); ! assertEquals(Queries.chrono().queryFrom(TEST_11_30_59_500_PONE), null); ! } ! ! @Test ! public void test_query_zoneId() { ! assertEquals(TEST_11_30_59_500_PONE.query(Queries.zoneId()), null); ! assertEquals(Queries.zoneId().queryFrom(TEST_11_30_59_500_PONE), null); ! } ! ! @Test ! public void test_query_precision() { ! assertEquals(TEST_11_30_59_500_PONE.query(Queries.precision()), NANOS); ! assertEquals(Queries.precision().queryFrom(TEST_11_30_59_500_PONE), NANOS); } ! @Test ! public void test_query_offset() { ! assertEquals(TEST_11_30_59_500_PONE.query(Queries.offset()), OFFSET_PONE); ! assertEquals(Queries.offset().queryFrom(TEST_11_30_59_500_PONE), OFFSET_PONE); } ! @Test ! public void test_query_zone() { ! assertEquals(TEST_11_30_59_500_PONE.query(Queries.zone()), OFFSET_PONE); ! assertEquals(Queries.zone().queryFrom(TEST_11_30_59_500_PONE), OFFSET_PONE); } @Test(expectedExceptions=NullPointerException.class) public void test_query_null() { TEST_11_30_59_500_PONE.query(null); --- 563,593 ---- } //----------------------------------------------------------------------- // query(TemporalQuery) //----------------------------------------------------------------------- ! @DataProvider(name="query") ! Object[][] data_query() { ! return new Object[][] { ! {TEST_11_30_59_500_PONE, Queries.chronology(), null}, ! {TEST_11_30_59_500_PONE, Queries.zoneId(), null}, ! {TEST_11_30_59_500_PONE, Queries.precision(), ChronoUnit.NANOS}, ! {TEST_11_30_59_500_PONE, Queries.zone(), OFFSET_PONE}, ! {TEST_11_30_59_500_PONE, Queries.offset(), OFFSET_PONE}, ! {TEST_11_30_59_500_PONE, Queries.localDate(), null}, ! {TEST_11_30_59_500_PONE, 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_11_30_59_500_PONE.query(null);
*** 624,682 **** //----------------------------------------------------------------------- // withOffsetSameLocal() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_withOffsetSameLocal() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.withOffsetSameLocal(OFFSET_PTWO); ! assertEquals(test.getTime(), base.getTime()); assertEquals(test.getOffset(), OFFSET_PTWO); } @Test(groups={"tck"}) public void test_withOffsetSameLocal_noChange() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.withOffsetSameLocal(OFFSET_PONE); assertEquals(test, base); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_withOffsetSameLocal_null() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); base.withOffsetSameLocal(null); } //----------------------------------------------------------------------- // withOffsetSameInstant() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_withOffsetSameInstant() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.withOffsetSameInstant(OFFSET_PTWO); ! OffsetTime expected = OffsetTime.of(LocalTime.of(12, 30, 59), OFFSET_PTWO); assertEquals(test, expected); } @Test(groups={"tck"}) public void test_withOffsetSameInstant_noChange() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.withOffsetSameInstant(OFFSET_PONE); assertEquals(test, base); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_withOffsetSameInstant_null() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); base.withOffsetSameInstant(null); } //----------------------------------------------------------------------- // with(WithAdjuster) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_with_adjustment() { ! final OffsetTime sample = OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE); TemporalAdjuster adjuster = new TemporalAdjuster() { @Override public Temporal adjustInto(Temporal dateTime) { return sample; } --- 596,654 ---- //----------------------------------------------------------------------- // withOffsetSameLocal() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_withOffsetSameLocal() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.withOffsetSameLocal(OFFSET_PTWO); ! assertEquals(test.toLocalTime(), base.toLocalTime()); assertEquals(test.getOffset(), OFFSET_PTWO); } @Test(groups={"tck"}) public void test_withOffsetSameLocal_noChange() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.withOffsetSameLocal(OFFSET_PONE); assertEquals(test, base); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_withOffsetSameLocal_null() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); base.withOffsetSameLocal(null); } //----------------------------------------------------------------------- // withOffsetSameInstant() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_withOffsetSameInstant() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.withOffsetSameInstant(OFFSET_PTWO); ! OffsetTime expected = OffsetTime.of(12, 30, 59, 0, OFFSET_PTWO); assertEquals(test, expected); } @Test(groups={"tck"}) public void test_withOffsetSameInstant_noChange() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.withOffsetSameInstant(OFFSET_PONE); assertEquals(test, base); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_withOffsetSameInstant_null() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); base.withOffsetSameInstant(null); } //----------------------------------------------------------------------- // with(WithAdjuster) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_with_adjustment() { ! final OffsetTime sample = OffsetTime.of(23, 5, 0, 0, OFFSET_PONE); TemporalAdjuster adjuster = new TemporalAdjuster() { @Override public Temporal adjustInto(Temporal dateTime) { return sample; }
*** 685,718 **** } @Test(groups={"tck"}) public void test_with_adjustment_LocalTime() { OffsetTime test = TEST_11_30_59_500_PONE.with(LocalTime.of(13, 30)); ! assertEquals(test, OffsetTime.of(LocalTime.of(13, 30), OFFSET_PONE)); } @Test(groups={"tck"}) public void test_with_adjustment_OffsetTime() { ! OffsetTime test = TEST_11_30_59_500_PONE.with(OffsetTime.of(LocalTime.of(13, 35), OFFSET_PTWO)); ! assertEquals(test, OffsetTime.of(LocalTime.of(13, 35), OFFSET_PTWO)); } @Test(groups={"tck"}) public void test_with_adjustment_ZoneOffset() { OffsetTime test = TEST_11_30_59_500_PONE.with(OFFSET_PTWO); ! assertEquals(test, OffsetTime.of(LocalTime.of(11, 30, 59, 500), OFFSET_PTWO)); } @Test(groups={"tck"}) public void test_with_adjustment_AmPm() { OffsetTime test = TEST_11_30_59_500_PONE.with(new TemporalAdjuster() { @Override public Temporal adjustInto(Temporal dateTime) { return dateTime.with(HOUR_OF_DAY, 23); } }); ! assertEquals(test, OffsetTime.of(LocalTime.of(23, 30, 59, 500), OFFSET_PONE)); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_with_adjustment_null() { TEST_11_30_59_500_PONE.with((TemporalAdjuster) null); --- 657,690 ---- } @Test(groups={"tck"}) public void test_with_adjustment_LocalTime() { OffsetTime test = TEST_11_30_59_500_PONE.with(LocalTime.of(13, 30)); ! assertEquals(test, OffsetTime.of(13, 30, 0, 0, OFFSET_PONE)); } @Test(groups={"tck"}) public void test_with_adjustment_OffsetTime() { ! OffsetTime test = TEST_11_30_59_500_PONE.with(OffsetTime.of(13, 35, 0, 0, OFFSET_PTWO)); ! assertEquals(test, OffsetTime.of(13, 35, 0, 0, OFFSET_PTWO)); } @Test(groups={"tck"}) public void test_with_adjustment_ZoneOffset() { OffsetTime test = TEST_11_30_59_500_PONE.with(OFFSET_PTWO); ! assertEquals(test, OffsetTime.of(11, 30, 59, 500, OFFSET_PTWO)); } @Test(groups={"tck"}) public void test_with_adjustment_AmPm() { OffsetTime test = TEST_11_30_59_500_PONE.with(new TemporalAdjuster() { @Override public Temporal adjustInto(Temporal dateTime) { return dateTime.with(HOUR_OF_DAY, 23); } }); ! assertEquals(test, OffsetTime.of(23, 30, 59, 500, OFFSET_PONE)); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_with_adjustment_null() { TEST_11_30_59_500_PONE.with((TemporalAdjuster) null);
*** 721,739 **** //----------------------------------------------------------------------- // with(TemporalField, long) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_with_TemporalField() { ! OffsetTime test = OffsetTime.of(LocalTime.of(12, 30, 40, 987654321), OFFSET_PONE); ! assertEquals(test.with(ChronoField.HOUR_OF_DAY, 15), OffsetTime.of(LocalTime.of(15, 30, 40, 987654321), OFFSET_PONE)); ! assertEquals(test.with(ChronoField.MINUTE_OF_HOUR, 50), OffsetTime.of(LocalTime.of(12, 50, 40, 987654321), OFFSET_PONE)); ! assertEquals(test.with(ChronoField.SECOND_OF_MINUTE, 50), OffsetTime.of(LocalTime.of(12, 30, 50, 987654321), OFFSET_PONE)); ! assertEquals(test.with(ChronoField.NANO_OF_SECOND, 12345), OffsetTime.of(LocalTime.of(12, 30, 40, 12345), OFFSET_PONE)); ! assertEquals(test.with(ChronoField.HOUR_OF_AMPM, 6), OffsetTime.of(LocalTime.of(18, 30, 40, 987654321), OFFSET_PONE)); ! assertEquals(test.with(ChronoField.AMPM_OF_DAY, 0), OffsetTime.of(LocalTime.of(0, 30, 40, 987654321), OFFSET_PONE)); ! assertEquals(test.with(ChronoField.OFFSET_SECONDS, 7205), OffsetTime.of(LocalTime.of(12, 30, 40, 987654321), ZoneOffset.ofHoursMinutesSeconds(2, 0, 5))); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"} ) public void test_with_TemporalField_null() { TEST_11_30_59_500_PONE.with((TemporalField) null, 0); --- 693,711 ---- //----------------------------------------------------------------------- // with(TemporalField, long) //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_with_TemporalField() { ! OffsetTime test = OffsetTime.of(12, 30, 40, 987654321, OFFSET_PONE); ! assertEquals(test.with(ChronoField.HOUR_OF_DAY, 15), OffsetTime.of(15, 30, 40, 987654321, OFFSET_PONE)); ! assertEquals(test.with(ChronoField.MINUTE_OF_HOUR, 50), OffsetTime.of(12, 50, 40, 987654321, OFFSET_PONE)); ! assertEquals(test.with(ChronoField.SECOND_OF_MINUTE, 50), OffsetTime.of(12, 30, 50, 987654321, OFFSET_PONE)); ! assertEquals(test.with(ChronoField.NANO_OF_SECOND, 12345), OffsetTime.of(12, 30, 40, 12345, OFFSET_PONE)); ! assertEquals(test.with(ChronoField.HOUR_OF_AMPM, 6), OffsetTime.of(18, 30, 40, 987654321, OFFSET_PONE)); ! assertEquals(test.with(ChronoField.AMPM_OF_DAY, 0), OffsetTime.of(0, 30, 40, 987654321, OFFSET_PONE)); ! assertEquals(test.with(ChronoField.OFFSET_SECONDS, 7205), OffsetTime.of(12, 30, 40, 987654321, ZoneOffset.ofHoursMinutesSeconds(2, 0, 5))); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"} ) public void test_with_TemporalField_null() { TEST_11_30_59_500_PONE.with((TemporalField) null, 0);
*** 747,815 **** //----------------------------------------------------------------------- // withHour() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_withHour_normal() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.withHour(15); ! assertEquals(test, OffsetTime.of(LocalTime.of(15, 30, 59), OFFSET_PONE)); } @Test(groups={"tck"}) public void test_withHour_noChange() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.withHour(11); assertEquals(test, base); } //----------------------------------------------------------------------- // withMinute() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_withMinute_normal() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.withMinute(15); ! assertEquals(test, OffsetTime.of(LocalTime.of(11, 15, 59), OFFSET_PONE)); } @Test(groups={"tck"}) public void test_withMinute_noChange() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.withMinute(30); assertEquals(test, base); } //----------------------------------------------------------------------- // withSecond() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_withSecond_normal() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.withSecond(15); ! assertEquals(test, OffsetTime.of(LocalTime.of(11, 30, 15), OFFSET_PONE)); } @Test(groups={"tck"}) public void test_withSecond_noChange() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.withSecond(59); assertEquals(test, base); } //----------------------------------------------------------------------- // withNano() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_withNanoOfSecond_normal() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59, 1), OFFSET_PONE); OffsetTime test = base.withNano(15); ! assertEquals(test, OffsetTime.of(LocalTime.of(11, 30, 59, 15), OFFSET_PONE)); } @Test(groups={"tck"}) public void test_withNanoOfSecond_noChange() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59, 1), OFFSET_PONE); OffsetTime test = base.withNano(1); assertEquals(test, base); } //----------------------------------------------------------------------- --- 719,787 ---- //----------------------------------------------------------------------- // withHour() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_withHour_normal() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.withHour(15); ! assertEquals(test, OffsetTime.of(15, 30, 59, 0, OFFSET_PONE)); } @Test(groups={"tck"}) public void test_withHour_noChange() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.withHour(11); assertEquals(test, base); } //----------------------------------------------------------------------- // withMinute() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_withMinute_normal() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.withMinute(15); ! assertEquals(test, OffsetTime.of(11, 15, 59, 0, OFFSET_PONE)); } @Test(groups={"tck"}) public void test_withMinute_noChange() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.withMinute(30); assertEquals(test, base); } //----------------------------------------------------------------------- // withSecond() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_withSecond_normal() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.withSecond(15); ! assertEquals(test, OffsetTime.of(11, 30, 15, 0, OFFSET_PONE)); } @Test(groups={"tck"}) public void test_withSecond_noChange() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.withSecond(59); assertEquals(test, base); } //----------------------------------------------------------------------- // withNano() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_withNanoOfSecond_normal() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 1, OFFSET_PONE); OffsetTime test = base.withNano(15); ! assertEquals(test, OffsetTime.of(11, 30, 59, 15, OFFSET_PONE)); } @Test(groups={"tck"}) public void test_withNanoOfSecond_noChange() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 1, OFFSET_PONE); OffsetTime test = base.withNano(1); assertEquals(test, base); } //-----------------------------------------------------------------------
*** 832,842 **** //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plus_PlusAdjuster() { MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MINUTES); OffsetTime t = TEST_11_30_59_500_PONE.plus(period); ! assertEquals(t, OffsetTime.of(LocalTime.of(11, 37, 59, 500), OFFSET_PONE)); } @Test(groups={"tck"}) public void test_plus_PlusAdjuster_noChange() { OffsetTime t = TEST_11_30_59_500_PONE.plus(MockSimplePeriod.of(0, SECONDS)); --- 804,814 ---- //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plus_PlusAdjuster() { MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MINUTES); OffsetTime t = TEST_11_30_59_500_PONE.plus(period); ! assertEquals(t, OffsetTime.of(11, 37, 59, 500, OFFSET_PONE)); } @Test(groups={"tck"}) public void test_plus_PlusAdjuster_noChange() { OffsetTime t = TEST_11_30_59_500_PONE.plus(MockSimplePeriod.of(0, SECONDS));
*** 849,925 **** assertEquals(t, TEST_11_30_59_500_PONE); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_plus_PlusAdjuster_null() { ! TEST_11_30_59_500_PONE.plus((TemporalAdder) null); } //----------------------------------------------------------------------- // plusHours() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusHours() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.plusHours(13); ! assertEquals(test, OffsetTime.of(LocalTime.of(0, 30, 59), OFFSET_PONE)); } @Test(groups={"tck"}) public void test_plusHours_zero() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.plusHours(0); assertEquals(test, base); } //----------------------------------------------------------------------- // plusMinutes() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusMinutes() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.plusMinutes(30); ! assertEquals(test, OffsetTime.of(LocalTime.of(12, 0, 59), OFFSET_PONE)); } @Test(groups={"tck"}) public void test_plusMinutes_zero() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.plusMinutes(0); assertEquals(test, base); } //----------------------------------------------------------------------- // plusSeconds() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusSeconds() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.plusSeconds(1); ! assertEquals(test, OffsetTime.of(LocalTime.of(11, 31, 0), OFFSET_PONE)); } @Test(groups={"tck"}) public void test_plusSeconds_zero() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.plusSeconds(0); assertEquals(test, base); } //----------------------------------------------------------------------- // plusNanos() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusNanos() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59, 0), OFFSET_PONE); OffsetTime test = base.plusNanos(1); ! assertEquals(test, OffsetTime.of(LocalTime.of(11, 30, 59, 1), OFFSET_PONE)); } @Test(groups={"tck"}) public void test_plusNanos_zero() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.plusNanos(0); assertEquals(test, base); } //----------------------------------------------------------------------- --- 821,897 ---- assertEquals(t, TEST_11_30_59_500_PONE); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_plus_PlusAdjuster_null() { ! TEST_11_30_59_500_PONE.plus((TemporalAmount) null); } //----------------------------------------------------------------------- // plusHours() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusHours() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.plusHours(13); ! assertEquals(test, OffsetTime.of(0, 30, 59, 0, OFFSET_PONE)); } @Test(groups={"tck"}) public void test_plusHours_zero() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.plusHours(0); assertEquals(test, base); } //----------------------------------------------------------------------- // plusMinutes() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusMinutes() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.plusMinutes(30); ! assertEquals(test, OffsetTime.of(12, 0, 59, 0, OFFSET_PONE)); } @Test(groups={"tck"}) public void test_plusMinutes_zero() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.plusMinutes(0); assertEquals(test, base); } //----------------------------------------------------------------------- // plusSeconds() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusSeconds() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.plusSeconds(1); ! assertEquals(test, OffsetTime.of(11, 31, 0, 0, OFFSET_PONE)); } @Test(groups={"tck"}) public void test_plusSeconds_zero() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.plusSeconds(0); assertEquals(test, base); } //----------------------------------------------------------------------- // plusNanos() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_plusNanos() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.plusNanos(1); ! assertEquals(test, OffsetTime.of(11, 30, 59, 1, OFFSET_PONE)); } @Test(groups={"tck"}) public void test_plusNanos_zero() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.plusNanos(0); assertEquals(test, base); } //-----------------------------------------------------------------------
*** 927,937 **** //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minus_MinusAdjuster() { MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MINUTES); OffsetTime t = TEST_11_30_59_500_PONE.minus(period); ! assertEquals(t, OffsetTime.of(LocalTime.of(11, 23, 59, 500), OFFSET_PONE)); } @Test(groups={"tck"}) public void test_minus_MinusAdjuster_noChange() { OffsetTime t = TEST_11_30_59_500_PONE.minus(MockSimplePeriod.of(0, SECONDS)); --- 899,909 ---- //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minus_MinusAdjuster() { MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MINUTES); OffsetTime t = TEST_11_30_59_500_PONE.minus(period); ! assertEquals(t, OffsetTime.of(11, 23, 59, 500, OFFSET_PONE)); } @Test(groups={"tck"}) public void test_minus_MinusAdjuster_noChange() { OffsetTime t = TEST_11_30_59_500_PONE.minus(MockSimplePeriod.of(0, SECONDS));
*** 944,1085 **** assertEquals(t, TEST_11_30_59_500_PONE); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_minus_MinusAdjuster_null() { ! TEST_11_30_59_500_PONE.minus((TemporalSubtractor) null); } //----------------------------------------------------------------------- // minusHours() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusHours() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.minusHours(-13); ! assertEquals(test, OffsetTime.of(LocalTime.of(0, 30, 59), OFFSET_PONE)); } @Test(groups={"tck"}) public void test_minusHours_zero() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.minusHours(0); assertEquals(test, base); } //----------------------------------------------------------------------- // minusMinutes() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusMinutes() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.minusMinutes(50); ! assertEquals(test, OffsetTime.of(LocalTime.of(10, 40, 59), OFFSET_PONE)); } @Test(groups={"tck"}) public void test_minusMinutes_zero() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.minusMinutes(0); assertEquals(test, base); } //----------------------------------------------------------------------- // minusSeconds() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusSeconds() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.minusSeconds(60); ! assertEquals(test, OffsetTime.of(LocalTime.of(11, 29, 59), OFFSET_PONE)); } @Test(groups={"tck"}) public void test_minusSeconds_zero() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.minusSeconds(0); assertEquals(test, base); } //----------------------------------------------------------------------- // minusNanos() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusNanos() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59, 0), OFFSET_PONE); OffsetTime test = base.minusNanos(1); ! assertEquals(test, OffsetTime.of(LocalTime.of(11, 30, 58, 999999999), OFFSET_PONE)); } @Test(groups={"tck"}) public void test_minusNanos_zero() { ! OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); OffsetTime test = base.minusNanos(0); assertEquals(test, base); } //----------------------------------------------------------------------- // compareTo() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_compareTo_time() { ! OffsetTime a = OffsetTime.of(LocalTime.of(11, 29), OFFSET_PONE); ! OffsetTime b = OffsetTime.of(LocalTime.of(11, 30), 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(convertInstant(a).compareTo(convertInstant(b)) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_offset() { ! OffsetTime a = OffsetTime.of(LocalTime.of(11, 30), OFFSET_PTWO); ! OffsetTime b = OffsetTime.of(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(convertInstant(a).compareTo(convertInstant(b)) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_both() { ! OffsetTime a = OffsetTime.of(LocalTime.of(11, 50), OFFSET_PTWO); ! OffsetTime b = OffsetTime.of(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(convertInstant(a).compareTo(convertInstant(b)) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_bothNearStartOfDay() { ! OffsetTime a = OffsetTime.of(LocalTime.of(0, 10), OFFSET_PONE); ! OffsetTime b = OffsetTime.of(LocalTime.of(2, 30), OFFSET_PTWO); // 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(convertInstant(a).compareTo(convertInstant(b)) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_hourDifference() { ! OffsetTime a = OffsetTime.of(LocalTime.of(10, 0), OFFSET_PONE); ! OffsetTime b = OffsetTime.of(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(convertInstant(a).compareTo(convertInstant(b)) == 0, true); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_compareTo_null() { ! OffsetTime a = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); a.compareTo(null); } @Test(expectedExceptions=ClassCastException.class, groups={"tck"}) @SuppressWarnings({"unchecked", "rawtypes"}) --- 916,1057 ---- assertEquals(t, TEST_11_30_59_500_PONE); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_minus_MinusAdjuster_null() { ! TEST_11_30_59_500_PONE.minus((TemporalAmount) null); } //----------------------------------------------------------------------- // minusHours() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusHours() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.minusHours(-13); ! assertEquals(test, OffsetTime.of(0, 30, 59, 0, OFFSET_PONE)); } @Test(groups={"tck"}) public void test_minusHours_zero() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.minusHours(0); assertEquals(test, base); } //----------------------------------------------------------------------- // minusMinutes() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusMinutes() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.minusMinutes(50); ! assertEquals(test, OffsetTime.of(10, 40, 59, 0, OFFSET_PONE)); } @Test(groups={"tck"}) public void test_minusMinutes_zero() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.minusMinutes(0); assertEquals(test, base); } //----------------------------------------------------------------------- // minusSeconds() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusSeconds() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.minusSeconds(60); ! assertEquals(test, OffsetTime.of(11, 29, 59, 0, OFFSET_PONE)); } @Test(groups={"tck"}) public void test_minusSeconds_zero() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.minusSeconds(0); assertEquals(test, base); } //----------------------------------------------------------------------- // minusNanos() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_minusNanos() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.minusNanos(1); ! assertEquals(test, OffsetTime.of(11, 30, 58, 999999999, OFFSET_PONE)); } @Test(groups={"tck"}) public void test_minusNanos_zero() { ! OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); OffsetTime test = base.minusNanos(0); assertEquals(test, base); } //----------------------------------------------------------------------- // compareTo() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_compareTo_time() { ! OffsetTime a = OffsetTime.of(11, 29, 0, 0, OFFSET_PONE); ! OffsetTime b = OffsetTime.of(11, 30, 0, 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(convertInstant(a).compareTo(convertInstant(b)) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_offset() { ! OffsetTime a = OffsetTime.of(11, 30, 0, 0, OFFSET_PTWO); ! OffsetTime b = OffsetTime.of(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(convertInstant(a).compareTo(convertInstant(b)) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_both() { ! OffsetTime a = OffsetTime.of(11, 50, 0, 0, OFFSET_PTWO); ! OffsetTime b = OffsetTime.of(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(convertInstant(a).compareTo(convertInstant(b)) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_bothNearStartOfDay() { ! OffsetTime a = OffsetTime.of(0, 10, 0, 0, OFFSET_PONE); ! OffsetTime b = OffsetTime.of(2, 30, 0, 0, OFFSET_PTWO); // 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(convertInstant(a).compareTo(convertInstant(b)) < 0, true); } @Test(groups={"tck"}) public void test_compareTo_hourDifference() { ! OffsetTime a = OffsetTime.of(10, 0, 0, 0, OFFSET_PONE); ! OffsetTime b = OffsetTime.of(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(convertInstant(a).compareTo(convertInstant(b)) == 0, true); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_compareTo_null() { ! OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); a.compareTo(null); } @Test(expectedExceptions=ClassCastException.class, groups={"tck"}) @SuppressWarnings({"unchecked", "rawtypes"})
*** 1087,1106 **** Comparable c = TEST_11_30_59_500_PONE; c.compareTo(new Object()); } private Instant convertInstant(OffsetTime ot) { ! return DATE.atTime(ot.getTime()).toInstant(ot.getOffset()); } //----------------------------------------------------------------------- // isAfter() / isBefore() / isEqual() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_isBeforeIsAfterIsEqual1() { ! OffsetTime a = OffsetTime.of(LocalTime.of(11, 30, 58), OFFSET_PONE); ! OffsetTime b = OffsetTime.of(LocalTime.of(11, 30, 59), 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); --- 1059,1078 ---- Comparable c = TEST_11_30_59_500_PONE; c.compareTo(new Object()); } private Instant convertInstant(OffsetTime ot) { ! return DATE.atTime(ot.toLocalTime()).toInstant(ot.getOffset()); } //----------------------------------------------------------------------- // isAfter() / isBefore() / isEqual() //----------------------------------------------------------------------- @Test(groups={"tck"}) public void test_isBeforeIsAfterIsEqual1() { ! OffsetTime a = OffsetTime.of(11, 30, 58, 0, OFFSET_PONE); ! OffsetTime b = OffsetTime.of(11, 30, 59, 0, 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);
*** 1117,1128 **** assertEquals(b.isAfter(b), false); } @Test(groups={"tck"}) public void test_isBeforeIsAfterIsEqual1nanos() { ! OffsetTime a = OffsetTime.of(LocalTime.of(11, 30, 59, 3), OFFSET_PONE); ! OffsetTime b = OffsetTime.of(LocalTime.of(11, 30, 59, 4), 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); --- 1089,1100 ---- assertEquals(b.isAfter(b), false); } @Test(groups={"tck"}) public void test_isBeforeIsAfterIsEqual1nanos() { ! OffsetTime a = OffsetTime.of(11, 30, 59, 3, OFFSET_PONE); ! OffsetTime b = OffsetTime.of(11, 30, 59, 4, 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);
*** 1139,1150 **** assertEquals(b.isAfter(b), false); } @Test(groups={"tck"}) public void test_isBeforeIsAfterIsEqual2() { ! OffsetTime a = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PTWO); ! OffsetTime b = OffsetTime.of(LocalTime.of(11, 30, 58), OFFSET_PONE); // a is before b due to offset assertEquals(a.isBefore(b), true); assertEquals(a.isEqual(b), false); assertEquals(a.isAfter(b), false); assertEquals(b.isBefore(a), false); --- 1111,1122 ---- assertEquals(b.isAfter(b), false); } @Test(groups={"tck"}) public void test_isBeforeIsAfterIsEqual2() { ! OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PTWO); ! OffsetTime b = OffsetTime.of(11, 30, 58, 0, OFFSET_PONE); // a is before b due to offset assertEquals(a.isBefore(b), true); assertEquals(a.isEqual(b), false); assertEquals(a.isAfter(b), false); assertEquals(b.isBefore(a), false);
*** 1161,1172 **** assertEquals(b.isAfter(b), false); } @Test(groups={"tck"}) public void test_isBeforeIsAfterIsEqual2nanos() { ! OffsetTime a = OffsetTime.of(LocalTime.of(11, 30, 59, 4), ZoneOffset.ofTotalSeconds(OFFSET_PONE.getTotalSeconds() + 1)); ! OffsetTime b = OffsetTime.of(LocalTime.of(11, 30, 59, 3), OFFSET_PONE); // a is before b due to offset assertEquals(a.isBefore(b), true); assertEquals(a.isEqual(b), false); assertEquals(a.isAfter(b), false); assertEquals(b.isBefore(a), false); --- 1133,1144 ---- assertEquals(b.isAfter(b), false); } @Test(groups={"tck"}) public void test_isBeforeIsAfterIsEqual2nanos() { ! OffsetTime a = OffsetTime.of(11, 30, 59, 4, ZoneOffset.ofTotalSeconds(OFFSET_PONE.getTotalSeconds() + 1)); ! OffsetTime b = OffsetTime.of(11, 30, 59, 3, OFFSET_PONE); // a is before b due to offset assertEquals(a.isBefore(b), true); assertEquals(a.isEqual(b), false); assertEquals(a.isAfter(b), false); assertEquals(b.isBefore(a), false);
*** 1183,1194 **** assertEquals(b.isAfter(b), false); } @Test(groups={"tck"}) public void test_isBeforeIsAfterIsEqual_instantComparison() { ! OffsetTime a = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PTWO); ! OffsetTime b = OffsetTime.of(LocalTime.of(10, 30, 59), OFFSET_PONE); // 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); --- 1155,1166 ---- assertEquals(b.isAfter(b), false); } @Test(groups={"tck"}) public void test_isBeforeIsAfterIsEqual_instantComparison() { ! OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PTWO); ! OffsetTime b = OffsetTime.of(10, 30, 59, 0, OFFSET_PONE); // 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);
*** 1205,1272 **** assertEquals(b.isAfter(b), false); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_isBefore_null() { ! OffsetTime a = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); a.isBefore(null); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_isAfter_null() { ! OffsetTime a = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); a.isAfter(null); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_isEqual_null() { ! OffsetTime a = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE); a.isEqual(null); } //----------------------------------------------------------------------- // equals() / hashCode() //----------------------------------------------------------------------- @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_equals_true(int h, int m, int s, int n, ZoneOffset ignored) { ! OffsetTime a = OffsetTime.of(LocalTime.of(h, m, s, n), OFFSET_PONE); ! OffsetTime b = OffsetTime.of(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_hour_differs(int h, int m, int s, int n, ZoneOffset ignored) { h = (h == 23 ? 22 : h); ! OffsetTime a = OffsetTime.of(LocalTime.of(h, m, s, n), OFFSET_PONE); ! OffsetTime b = OffsetTime.of(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 h, int m, int s, int n, ZoneOffset ignored) { m = (m == 59 ? 58 : m); ! OffsetTime a = OffsetTime.of(LocalTime.of(h, m, s, n), OFFSET_PONE); ! OffsetTime b = OffsetTime.of(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 h, int m, int s, int n, ZoneOffset ignored) { s = (s == 59 ? 58 : s); ! OffsetTime a = OffsetTime.of(LocalTime.of(h, m, s, n), OFFSET_PONE); ! OffsetTime b = OffsetTime.of(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 h, int m, int s, int n, ZoneOffset ignored) { n = (n == 999999999 ? 999999998 : n); ! OffsetTime a = OffsetTime.of(LocalTime.of(h, m, s, n), OFFSET_PONE); ! OffsetTime b = OffsetTime.of(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 h, int m, int s, int n, ZoneOffset ignored) { ! OffsetTime a = OffsetTime.of(LocalTime.of(h, m, s, n), OFFSET_PONE); ! OffsetTime b = OffsetTime.of(LocalTime.of(h, m, s, n), OFFSET_PTWO); assertEquals(a.equals(b), false); } @Test(groups={"tck"}) public void test_equals_itself_true() { --- 1177,1244 ---- assertEquals(b.isAfter(b), false); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_isBefore_null() { ! OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); a.isBefore(null); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_isAfter_null() { ! OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); a.isAfter(null); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_isEqual_null() { ! OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); a.isEqual(null); } //----------------------------------------------------------------------- // equals() / hashCode() //----------------------------------------------------------------------- @Test(dataProvider="sampleTimes", groups={"tck"}) public void test_equals_true(int h, int m, int s, int n, ZoneOffset ignored) { ! OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE); ! OffsetTime b = OffsetTime.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_hour_differs(int h, int m, int s, int n, ZoneOffset ignored) { h = (h == 23 ? 22 : h); ! OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE); ! OffsetTime b = OffsetTime.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 h, int m, int s, int n, ZoneOffset ignored) { m = (m == 59 ? 58 : m); ! OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE); ! OffsetTime b = OffsetTime.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 h, int m, int s, int n, ZoneOffset ignored) { s = (s == 59 ? 58 : s); ! OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE); ! OffsetTime b = OffsetTime.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 h, int m, int s, int n, ZoneOffset ignored) { n = (n == 999999999 ? 999999998 : n); ! OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE); ! OffsetTime b = OffsetTime.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 h, int m, int s, int n, ZoneOffset ignored) { ! OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE); ! OffsetTime b = OffsetTime.of(h, m, s, n, OFFSET_PTWO); assertEquals(a.equals(b), false); } @Test(groups={"tck"}) public void test_equals_itself_true() {
*** 1300,1325 **** }; } @Test(dataProvider="sampleToString", groups={"tck"}) public void test_toString(int h, int m, int s, int n, String offsetId, String expected) { ! OffsetTime t = OffsetTime.of(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("H m s"); ! String t = OffsetTime.of(LocalTime.of(11, 30), OFFSET_PONE).toString(f); assertEquals(t, "11 30 0"); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_toString_formatter_null() { ! OffsetTime.of(LocalTime.of(11, 30), OFFSET_PONE).toString(null); } } --- 1272,1297 ---- }; } @Test(dataProvider="sampleToString", groups={"tck"}) public void test_toString(int h, int m, int s, int n, String offsetId, String expected) { ! OffsetTime t = OffsetTime.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 = DateTimeFormatter.ofPattern("H m s"); ! String t = OffsetTime.of(11, 30, 0, 0, OFFSET_PONE).toString(f); assertEquals(t, "11 30 0"); } @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) public void test_toString_formatter_null() { ! OffsetTime.of(11, 30, 0, 0, OFFSET_PONE).toString(null); } }