test/java/time/tck/java/time/TCKOffsetTime.java

Print this page




  40  *  * Redistributions in binary form must reproduce the above copyright notice,
  41  *    this list of conditions and the following disclaimer in the documentation
  42  *    and/or other materials provided with the distribution.
  43  *
  44  *  * Neither the name of JSR-310 nor the names of its contributors
  45  *    may be used to endorse or promote products derived from this software
  46  *    without specific prior written permission.
  47  *
  48  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  49  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  50  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  51  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  52  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  53  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  54  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  55  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  56  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  57  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59  */
  60 package tck.java.time.temporal;
  61 
  62 import static java.time.temporal.ChronoField.AMPM_OF_DAY;
  63 import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_AMPM;
  64 import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_DAY;
  65 import static java.time.temporal.ChronoField.HOUR_OF_AMPM;
  66 import static java.time.temporal.ChronoField.HOUR_OF_DAY;
  67 import static java.time.temporal.ChronoField.MICRO_OF_DAY;
  68 import static java.time.temporal.ChronoField.MICRO_OF_SECOND;
  69 import static java.time.temporal.ChronoField.MILLI_OF_DAY;
  70 import static java.time.temporal.ChronoField.MILLI_OF_SECOND;
  71 import static java.time.temporal.ChronoField.MINUTE_OF_DAY;
  72 import static java.time.temporal.ChronoField.MINUTE_OF_HOUR;
  73 import static java.time.temporal.ChronoField.NANO_OF_DAY;
  74 import static java.time.temporal.ChronoField.NANO_OF_SECOND;
  75 import static java.time.temporal.ChronoField.OFFSET_SECONDS;
  76 import static java.time.temporal.ChronoField.SECOND_OF_DAY;
  77 import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
  78 import static java.time.temporal.ChronoUnit.DAYS;
  79 import static java.time.temporal.ChronoUnit.NANOS;
  80 import static java.time.temporal.ChronoUnit.SECONDS;
  81 import static org.testng.Assert.assertEquals;
  82 import static org.testng.Assert.assertNotNull;
  83 import static org.testng.Assert.assertTrue;
  84 
  85 import java.io.ByteArrayOutputStream;
  86 import java.io.DataOutputStream;
  87 import java.io.IOException;
  88 import java.lang.reflect.Constructor;
  89 import java.lang.reflect.InvocationTargetException;
  90 import java.util.ArrayList;
  91 import java.util.Arrays;
  92 import java.util.List;
  93 
  94 import java.time.Clock;
  95 import java.time.DateTimeException;
  96 import java.time.Instant;
  97 import java.time.LocalDate;
  98 import java.time.LocalDateTime;
  99 import java.time.LocalTime;

 100 import java.time.Period;
 101 import java.time.ZoneId;
 102 import java.time.ZoneOffset;
 103 import java.time.ZonedDateTime;
 104 import java.time.format.DateTimeFormatter;
 105 import java.time.format.DateTimeFormatters;
 106 import java.time.format.DateTimeParseException;
 107 import java.time.temporal.ChronoField;
 108 import java.time.temporal.ChronoUnit;
 109 import java.time.temporal.JulianFields;
 110 import java.time.temporal.OffsetDate;
 111 import java.time.temporal.OffsetDateTime;
 112 import java.time.temporal.OffsetTime;
 113 import java.time.temporal.Queries;
 114 import java.time.temporal.Temporal;
 115 import java.time.temporal.TemporalAccessor;
 116 import java.time.temporal.TemporalAdder;
 117 import java.time.temporal.TemporalAdjuster;

 118 import java.time.temporal.TemporalField;
 119 import java.time.temporal.TemporalQuery;
 120 import java.time.temporal.TemporalSubtractor;


 121 
 122 import org.testng.annotations.BeforeMethod;
 123 import org.testng.annotations.DataProvider;
 124 import org.testng.annotations.Test;
 125 import tck.java.time.AbstractDateTimeTest;
 126 import test.java.time.MockSimplePeriod;
 127 
 128 /**
 129  * Test OffsetTime.
 130  */
 131 @Test
 132 public class TCKOffsetTime extends AbstractDateTimeTest {
 133 
 134     private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1);
 135     private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2);
 136     private static final LocalDate DATE = LocalDate.of(2008, 12, 3);
 137     private OffsetTime TEST_11_30_59_500_PONE;
 138 
 139     @BeforeMethod(groups={"tck","implementation"})
 140     public void setUp() {
 141         TEST_11_30_59_500_PONE = OffsetTime.of(LocalTime.of(11, 30, 59, 500), OFFSET_PONE);
 142     }
 143 
 144     //-----------------------------------------------------------------------
 145     @Override
 146     protected List<TemporalAccessor> samples() {
 147         TemporalAccessor[] array = {TEST_11_30_59_500_PONE, OffsetTime.MIN, OffsetTime.MAX};
 148         return Arrays.asList(array);
 149     }
 150 
 151     @Override
 152     protected List<TemporalField> validFields() {
 153         TemporalField[] array = {
 154             NANO_OF_SECOND,
 155             NANO_OF_DAY,
 156             MICRO_OF_SECOND,
 157             MICRO_OF_DAY,
 158             MILLI_OF_SECOND,
 159             MILLI_OF_DAY,
 160             SECOND_OF_MINUTE,
 161             SECOND_OF_DAY,


 176         List<TemporalField> list = new ArrayList<>(Arrays.<TemporalField>asList(ChronoField.values()));
 177         list.removeAll(validFields());
 178         list.add(JulianFields.JULIAN_DAY);
 179         list.add(JulianFields.MODIFIED_JULIAN_DAY);
 180         list.add(JulianFields.RATA_DIE);
 181         return list;
 182     }
 183 
 184     //-----------------------------------------------------------------------
 185     @Test
 186     public void test_serialization() throws Exception {
 187         assertSerializable(TEST_11_30_59_500_PONE);
 188         assertSerializable(OffsetTime.MIN);
 189         assertSerializable(OffsetTime.MAX);
 190     }
 191 
 192     @Test
 193     public void test_serialization_format() throws Exception {
 194         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 195         try (DataOutputStream dos = new DataOutputStream(baos) ) {
 196             dos.writeByte(2);
 197         }
 198         byte[] bytes = baos.toByteArray();
 199         ByteArrayOutputStream baosTime = new ByteArrayOutputStream();
 200         try (DataOutputStream dos = new DataOutputStream(baosTime) ) {
 201             dos.writeByte(4);
 202             dos.writeByte(22);
 203             dos.writeByte(17);
 204             dos.writeByte(59);
 205             dos.writeInt(464_000_000);
 206         }
 207         byte[] bytesTime = baosTime.toByteArray();
 208         ByteArrayOutputStream baosOffset = new ByteArrayOutputStream();
 209         try (DataOutputStream dos = new DataOutputStream(baosOffset) ) {
 210             dos.writeByte(8);
 211             dos.writeByte(4);  // quarter hours stored: 3600 / 900
 212         }
 213         byte[] bytesOffset = baosOffset.toByteArray();
 214         assertSerializedBySer(OffsetTime.of(LocalTime.of(22, 17, 59, 464_000_000), ZoneOffset.ofHours(1)), bytes,
 215                 bytesTime, bytesOffset);
 216     }
 217 
 218     //-----------------------------------------------------------------------
 219     // constants
 220     //-----------------------------------------------------------------------
 221     @Test
 222     public void constant_MIN() {
 223         check(OffsetTime.MIN, 0, 0, 0, 0, ZoneOffset.MAX);
 224     }
 225 
 226     @Test
 227     public void constant_MAX() {
 228         check(OffsetTime.MAX, 23, 59, 59, 999999999, ZoneOffset.MIN);
 229     }
 230 
 231     //-----------------------------------------------------------------------
 232     // now()
 233     //-----------------------------------------------------------------------
 234     @Test(groups={"tck"})
 235     public void now() {
 236         ZonedDateTime nowDT = ZonedDateTime.now();
 237 
 238         OffsetTime expected = OffsetTime.now(Clock.systemDefaultZone());
 239         OffsetTime test = OffsetTime.now();
 240         long diff = Math.abs(test.getTime().toNanoOfDay() - expected.getTime().toNanoOfDay());
 241         assertTrue(diff < 100000000);  // less than 0.1 secs
 242         assertEquals(test.getOffset(), nowDT.getOffset());
 243     }
 244 
 245     //-----------------------------------------------------------------------
 246     // now(Clock)
 247     //-----------------------------------------------------------------------
 248     @Test(groups={"tck"})
 249     public void now_Clock_allSecsInDay() {
 250         for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
 251             Instant instant = Instant.ofEpochSecond(i, 8);
 252             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 253             OffsetTime test = OffsetTime.now(clock);
 254             assertEquals(test.getHour(), (i / (60 * 60)) % 24);
 255             assertEquals(test.getMinute(), (i / 60) % 60);
 256             assertEquals(test.getSecond(), i % 60);
 257             assertEquals(test.getNano(), 8);
 258             assertEquals(test.getOffset(), ZoneOffset.UTC);
 259         }
 260     }


 285             assertEquals(test.getSecond(), 0);
 286             assertEquals(test.getNano(), 0);
 287             assertEquals(test.getOffset(), offset);
 288         }
 289     }
 290 
 291     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 292     public void now_Clock_nullZoneId() {
 293         OffsetTime.now((ZoneId) null);
 294     }
 295 
 296     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 297     public void now_Clock_nullClock() {
 298         OffsetTime.now((Clock) null);
 299     }
 300 
 301     //-----------------------------------------------------------------------
 302     // factories
 303     //-----------------------------------------------------------------------
 304     private void check(OffsetTime test, int h, int m, int s, int n, ZoneOffset offset) {
 305         assertEquals(test.getTime(), LocalTime.of(h, m, s, n));
 306         assertEquals(test.getOffset(), offset);
 307 
 308         assertEquals(test.getHour(), h);
 309         assertEquals(test.getMinute(), m);
 310         assertEquals(test.getSecond(), s);
 311         assertEquals(test.getNano(), n);
 312 
 313         assertEquals(test, test);
 314         assertEquals(test.hashCode(), test.hashCode());
 315         assertEquals(OffsetTime.of(LocalTime.of(h, m, s, n), offset), test);
 316     }
 317 
 318     //-----------------------------------------------------------------------
 319     @Test(groups={"tck"})
 320     public void factory_intsHM() {
 321         OffsetTime test = OffsetTime.of(LocalTime.of(11, 30), OFFSET_PONE);
 322         check(test, 11, 30, 0, 0, OFFSET_PONE);
 323     }
 324 
 325     //-----------------------------------------------------------------------
 326     @Test(groups={"tck"})
 327     public void factory_intsHMS() {
 328         OffsetTime test = OffsetTime.of(LocalTime.of(11, 30, 10), OFFSET_PONE);
 329         check(test, 11, 30, 10, 0, OFFSET_PONE);
 330     }
 331 
 332     //-----------------------------------------------------------------------
 333     @Test(groups={"tck"})
 334     public void factory_intsHMSN() {
 335         OffsetTime test = OffsetTime.of(LocalTime.of(11, 30, 10, 500), OFFSET_PONE);
 336         check(test, 11, 30, 10, 500, OFFSET_PONE);
 337     }
 338 
 339     //-----------------------------------------------------------------------
 340     @Test(groups={"tck"})
 341     public void factory_LocalTimeZoneOffset() {
 342         LocalTime localTime = LocalTime.of(11, 30, 10, 500);
 343         OffsetTime test = OffsetTime.of(localTime, OFFSET_PONE);
 344         check(test, 11, 30, 10, 500, OFFSET_PONE);
 345     }
 346 
 347     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 348     public void factory_LocalTimeZoneOffset_nullTime() {
 349         OffsetTime.of((LocalTime) null, OFFSET_PONE);
 350     }
 351 
 352     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 353     public void factory_LocalTimeZoneOffset_nullOffset() {
 354         LocalTime localTime = LocalTime.of(11, 30, 10, 500);
 355         OffsetTime.of(localTime, (ZoneOffset) null);


 400         assertEquals(test.getHour(), 23);
 401         assertEquals(test.getMinute(), 59);
 402         assertEquals(test.getSecond(), 59);
 403         assertEquals(test.getNano(), 999_999_999);
 404     }
 405 
 406     @Test(groups={"tck"})
 407     public void factory_ofInstant_minYear() {
 408         OffsetTime test = OffsetTime.ofInstant(Instant.MIN, ZoneOffset.UTC);
 409         assertEquals(test.getHour(), 0);
 410         assertEquals(test.getMinute(), 0);
 411         assertEquals(test.getSecond(), 0);
 412         assertEquals(test.getNano(), 0);
 413     }
 414 
 415     //-----------------------------------------------------------------------
 416     // from(TemporalAccessor)
 417     //-----------------------------------------------------------------------
 418     @Test(groups={"tck"})
 419     public void factory_from_TemporalAccessor_OT() {
 420         assertEquals(OffsetTime.from(OffsetTime.of(LocalTime.of(17, 30), OFFSET_PONE)), OffsetTime.of(LocalTime.of(17, 30), OFFSET_PONE));
 421     }
 422 
 423     @Test(groups={"tck"})
 424     public void test_from_TemporalAccessor_ZDT() {
 425         ZonedDateTime base = LocalDateTime.of(2007, 7, 15, 11, 30, 59, 500).atZone(OFFSET_PONE);
 426         assertEquals(OffsetTime.from(base), TEST_11_30_59_500_PONE);
 427     }
 428 
 429     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 430     public void factory_from_TemporalAccessor_invalid_noDerive() {
 431         OffsetTime.from(LocalDate.of(2007, 7, 15));
 432     }
 433 
 434     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 435     public void factory_from_TemporalAccessor_null() {
 436         OffsetTime.from((TemporalAccessor) null);
 437     }
 438 
 439     //-----------------------------------------------------------------------
 440     // parse()


 470     @Test(expectedExceptions={DateTimeParseException.class}, groups={"tck"})
 471     public void factory_parse_illegalHour() {
 472         OffsetTime.parse("25:00+01:00");
 473     }
 474 
 475     @Test(expectedExceptions={DateTimeParseException.class}, groups={"tck"})
 476     public void factory_parse_illegalMinute() {
 477         OffsetTime.parse("12:60+01:00");
 478     }
 479 
 480     @Test(expectedExceptions={DateTimeParseException.class}, groups={"tck"})
 481     public void factory_parse_illegalSecond() {
 482         OffsetTime.parse("12:12:60+01:00");
 483     }
 484 
 485     //-----------------------------------------------------------------------
 486     // parse(DateTimeFormatter)
 487     //-----------------------------------------------------------------------
 488     @Test(groups={"tck"})
 489     public void factory_parse_formatter() {
 490         DateTimeFormatter f = DateTimeFormatters.pattern("H m s XXX");
 491         OffsetTime test = OffsetTime.parse("11 30 0 +01:00", f);
 492         assertEquals(test, OffsetTime.of(LocalTime.of(11, 30), ZoneOffset.ofHours(1)));
 493     }
 494 
 495     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 496     public void factory_parse_formatter_nullText() {
 497         DateTimeFormatter f = DateTimeFormatters.pattern("y M d H m s");
 498         OffsetTime.parse((String) null, f);
 499     }
 500 
 501     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 502     public void factory_parse_formatter_nullFormatter() {
 503         OffsetTime.parse("ANY", null);
 504     }
 505 
 506     //-----------------------------------------------------------------------
 507     // constructor
 508     //-----------------------------------------------------------------------
 509     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 510     public void constructor_nullTime() throws Throwable  {
 511         Constructor<OffsetTime> con = OffsetTime.class.getDeclaredConstructor(LocalTime.class, ZoneOffset.class);
 512         con.setAccessible(true);
 513         try {
 514             con.newInstance(null, OFFSET_PONE);
 515         } catch (InvocationTargetException ex) {
 516             throw ex.getCause();
 517         }
 518     }
 519 
 520     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 521     public void constructor_nullOffset() throws Throwable  {
 522         Constructor<OffsetTime> con = OffsetTime.class.getDeclaredConstructor(LocalTime.class, ZoneOffset.class);
 523         con.setAccessible(true);
 524         try {
 525             con.newInstance(LocalTime.of(11, 30), null);
 526         } catch (InvocationTargetException ex) {
 527             throw ex.getCause();
 528         }
 529     }
 530 
 531     //-----------------------------------------------------------------------
 532     // basics
 533     //-----------------------------------------------------------------------
 534     @DataProvider(name="sampleTimes")
 535     Object[][] provider_sampleTimes() {
 536         return new Object[][] {
 537             {11, 30, 20, 500, OFFSET_PONE},
 538             {11, 0, 0, 0, OFFSET_PONE},
 539             {23, 59, 59, 999999999, OFFSET_PONE},
 540         };
 541     }
 542 
 543     @Test(dataProvider="sampleTimes", groups={"tck"})
 544     public void test_get(int h, int m, int s, int n, ZoneOffset offset) {
 545         LocalTime localTime = LocalTime.of(h, m, s, n);
 546         OffsetTime a = OffsetTime.of(localTime, offset);
 547 
 548         assertEquals(a.getTime(), localTime);
 549         assertEquals(a.getOffset(), offset);
 550         assertEquals(a.toString(), localTime.toString() + offset.toString());
 551         assertEquals(a.getHour(), localTime.getHour());
 552         assertEquals(a.getMinute(), localTime.getMinute());
 553         assertEquals(a.getSecond(), localTime.getSecond());
 554         assertEquals(a.getNano(), localTime.getNano());
 555     }
 556 
 557     //-----------------------------------------------------------------------
 558     // get(TemporalField)
 559     //-----------------------------------------------------------------------
 560     @Test
 561     public void test_get_TemporalField() {
 562         OffsetTime test = OffsetTime.of(LocalTime.of(12, 30, 40, 987654321), OFFSET_PONE);
 563         assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12);
 564         assertEquals(test.get(ChronoField.MINUTE_OF_HOUR), 30);
 565         assertEquals(test.get(ChronoField.SECOND_OF_MINUTE), 40);
 566         assertEquals(test.get(ChronoField.NANO_OF_SECOND), 987654321);
 567         assertEquals(test.get(ChronoField.HOUR_OF_AMPM), 0);
 568         assertEquals(test.get(ChronoField.AMPM_OF_DAY), 1);
 569 
 570         assertEquals(test.get(ChronoField.OFFSET_SECONDS), 3600);
 571     }
 572 
 573     @Test
 574     public void test_getLong_TemporalField() {
 575         OffsetTime test = OffsetTime.of(LocalTime.of(12, 30, 40, 987654321), OFFSET_PONE);
 576         assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12);
 577         assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30);
 578         assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40);
 579         assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321);
 580         assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0);
 581         assertEquals(test.getLong(ChronoField.AMPM_OF_DAY), 1);
 582 
 583         assertEquals(test.getLong(ChronoField.OFFSET_SECONDS), 3600);
 584     }
 585 
 586     //-----------------------------------------------------------------------
 587     // query(TemporalQuery)
 588     //-----------------------------------------------------------------------
 589     @Test
 590     public void test_query_chrono() {
 591         assertEquals(TEST_11_30_59_500_PONE.query(Queries.chrono()), null);
 592         assertEquals(Queries.chrono().queryFrom(TEST_11_30_59_500_PONE), null);
 593     }
 594 
 595     @Test
 596     public void test_query_zoneId() {
 597         assertEquals(TEST_11_30_59_500_PONE.query(Queries.zoneId()), null);
 598         assertEquals(Queries.zoneId().queryFrom(TEST_11_30_59_500_PONE), null);
 599     }
 600 
 601     @Test
 602     public void test_query_precision() {
 603         assertEquals(TEST_11_30_59_500_PONE.query(Queries.precision()), NANOS);
 604         assertEquals(Queries.precision().queryFrom(TEST_11_30_59_500_PONE), NANOS);
 605     }
 606 
 607     @Test
 608     public void test_query_offset() {
 609         assertEquals(TEST_11_30_59_500_PONE.query(Queries.offset()), OFFSET_PONE);
 610         assertEquals(Queries.offset().queryFrom(TEST_11_30_59_500_PONE), OFFSET_PONE);
 611     }
 612 
 613     @Test
 614     public void test_query_zone() {
 615         assertEquals(TEST_11_30_59_500_PONE.query(Queries.zone()), OFFSET_PONE);
 616         assertEquals(Queries.zone().queryFrom(TEST_11_30_59_500_PONE), OFFSET_PONE);
 617     }
 618 
 619     @Test(expectedExceptions=NullPointerException.class)
 620     public void test_query_null() {
 621         TEST_11_30_59_500_PONE.query(null);
 622     }
 623 
 624     //-----------------------------------------------------------------------
 625     // withOffsetSameLocal()
 626     //-----------------------------------------------------------------------
 627     @Test(groups={"tck"})
 628     public void test_withOffsetSameLocal() {
 629         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 630         OffsetTime test = base.withOffsetSameLocal(OFFSET_PTWO);
 631         assertEquals(test.getTime(), base.getTime());
 632         assertEquals(test.getOffset(), OFFSET_PTWO);
 633     }
 634 
 635     @Test(groups={"tck"})
 636     public void test_withOffsetSameLocal_noChange() {
 637         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 638         OffsetTime test = base.withOffsetSameLocal(OFFSET_PONE);
 639         assertEquals(test, base);
 640     }
 641 
 642     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 643     public void test_withOffsetSameLocal_null() {
 644         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 645         base.withOffsetSameLocal(null);
 646     }
 647 
 648     //-----------------------------------------------------------------------
 649     // withOffsetSameInstant()
 650     //-----------------------------------------------------------------------
 651     @Test(groups={"tck"})
 652     public void test_withOffsetSameInstant() {
 653         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 654         OffsetTime test = base.withOffsetSameInstant(OFFSET_PTWO);
 655         OffsetTime expected = OffsetTime.of(LocalTime.of(12, 30, 59), OFFSET_PTWO);
 656         assertEquals(test, expected);
 657     }
 658 
 659     @Test(groups={"tck"})
 660     public void test_withOffsetSameInstant_noChange() {
 661         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 662         OffsetTime test = base.withOffsetSameInstant(OFFSET_PONE);
 663         assertEquals(test, base);
 664     }
 665 
 666     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 667     public void test_withOffsetSameInstant_null() {
 668         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 669         base.withOffsetSameInstant(null);
 670     }
 671 
 672     //-----------------------------------------------------------------------
 673     // with(WithAdjuster)
 674     //-----------------------------------------------------------------------
 675     @Test(groups={"tck"})
 676     public void test_with_adjustment() {
 677         final OffsetTime sample = OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE);
 678         TemporalAdjuster adjuster = new TemporalAdjuster() {
 679             @Override
 680             public Temporal adjustInto(Temporal dateTime) {
 681                 return sample;
 682             }
 683         };
 684         assertEquals(TEST_11_30_59_500_PONE.with(adjuster), sample);
 685     }
 686 
 687     @Test(groups={"tck"})
 688     public void test_with_adjustment_LocalTime() {
 689         OffsetTime test = TEST_11_30_59_500_PONE.with(LocalTime.of(13, 30));
 690         assertEquals(test, OffsetTime.of(LocalTime.of(13, 30), OFFSET_PONE));
 691     }
 692 
 693     @Test(groups={"tck"})
 694     public void test_with_adjustment_OffsetTime() {
 695         OffsetTime test = TEST_11_30_59_500_PONE.with(OffsetTime.of(LocalTime.of(13, 35), OFFSET_PTWO));
 696         assertEquals(test, OffsetTime.of(LocalTime.of(13, 35), OFFSET_PTWO));
 697     }
 698 
 699     @Test(groups={"tck"})
 700     public void test_with_adjustment_ZoneOffset() {
 701         OffsetTime test = TEST_11_30_59_500_PONE.with(OFFSET_PTWO);
 702         assertEquals(test, OffsetTime.of(LocalTime.of(11, 30, 59, 500), OFFSET_PTWO));
 703     }
 704 
 705     @Test(groups={"tck"})
 706     public void test_with_adjustment_AmPm() {
 707         OffsetTime test = TEST_11_30_59_500_PONE.with(new TemporalAdjuster() {
 708             @Override
 709             public Temporal adjustInto(Temporal dateTime) {
 710                 return dateTime.with(HOUR_OF_DAY, 23);
 711             }
 712         });
 713         assertEquals(test, OffsetTime.of(LocalTime.of(23, 30, 59, 500), OFFSET_PONE));
 714     }
 715 
 716     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 717     public void test_with_adjustment_null() {
 718         TEST_11_30_59_500_PONE.with((TemporalAdjuster) null);
 719     }
 720 
 721     //-----------------------------------------------------------------------
 722     // with(TemporalField, long)
 723     //-----------------------------------------------------------------------
 724     @Test(groups={"tck"})
 725     public void test_with_TemporalField() {
 726         OffsetTime test = OffsetTime.of(LocalTime.of(12, 30, 40, 987654321), OFFSET_PONE);
 727         assertEquals(test.with(ChronoField.HOUR_OF_DAY, 15), OffsetTime.of(LocalTime.of(15, 30, 40, 987654321), OFFSET_PONE));
 728         assertEquals(test.with(ChronoField.MINUTE_OF_HOUR, 50), OffsetTime.of(LocalTime.of(12, 50, 40, 987654321), OFFSET_PONE));
 729         assertEquals(test.with(ChronoField.SECOND_OF_MINUTE, 50), OffsetTime.of(LocalTime.of(12, 30, 50, 987654321), OFFSET_PONE));
 730         assertEquals(test.with(ChronoField.NANO_OF_SECOND, 12345), OffsetTime.of(LocalTime.of(12, 30, 40, 12345), OFFSET_PONE));
 731         assertEquals(test.with(ChronoField.HOUR_OF_AMPM, 6), OffsetTime.of(LocalTime.of(18, 30, 40, 987654321), OFFSET_PONE));
 732         assertEquals(test.with(ChronoField.AMPM_OF_DAY, 0), OffsetTime.of(LocalTime.of(0, 30, 40, 987654321), OFFSET_PONE));
 733 
 734         assertEquals(test.with(ChronoField.OFFSET_SECONDS, 7205), OffsetTime.of(LocalTime.of(12, 30, 40, 987654321), ZoneOffset.ofHoursMinutesSeconds(2, 0, 5)));
 735     }
 736 
 737     @Test(expectedExceptions=NullPointerException.class, groups={"tck"} )
 738     public void test_with_TemporalField_null() {
 739         TEST_11_30_59_500_PONE.with((TemporalField) null, 0);
 740     }
 741 
 742     @Test(expectedExceptions=DateTimeException.class, groups={"tck"} )
 743     public void test_with_TemporalField_invalidField() {
 744         TEST_11_30_59_500_PONE.with(ChronoField.YEAR, 0);
 745     }
 746 
 747     //-----------------------------------------------------------------------
 748     // withHour()
 749     //-----------------------------------------------------------------------
 750     @Test(groups={"tck"})
 751     public void test_withHour_normal() {
 752         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 753         OffsetTime test = base.withHour(15);
 754         assertEquals(test, OffsetTime.of(LocalTime.of(15, 30, 59), OFFSET_PONE));
 755     }
 756 
 757     @Test(groups={"tck"})
 758     public void test_withHour_noChange() {
 759         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 760         OffsetTime test = base.withHour(11);
 761         assertEquals(test, base);
 762     }
 763 
 764     //-----------------------------------------------------------------------
 765     // withMinute()
 766     //-----------------------------------------------------------------------
 767     @Test(groups={"tck"})
 768     public void test_withMinute_normal() {
 769         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 770         OffsetTime test = base.withMinute(15);
 771         assertEquals(test, OffsetTime.of(LocalTime.of(11, 15, 59), OFFSET_PONE));
 772     }
 773 
 774     @Test(groups={"tck"})
 775     public void test_withMinute_noChange() {
 776         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 777         OffsetTime test = base.withMinute(30);
 778         assertEquals(test, base);
 779     }
 780 
 781     //-----------------------------------------------------------------------
 782     // withSecond()
 783     //-----------------------------------------------------------------------
 784     @Test(groups={"tck"})
 785     public void test_withSecond_normal() {
 786         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 787         OffsetTime test = base.withSecond(15);
 788         assertEquals(test, OffsetTime.of(LocalTime.of(11, 30, 15), OFFSET_PONE));
 789     }
 790 
 791     @Test(groups={"tck"})
 792     public void test_withSecond_noChange() {
 793         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 794         OffsetTime test = base.withSecond(59);
 795         assertEquals(test, base);
 796     }
 797 
 798     //-----------------------------------------------------------------------
 799     // withNano()
 800     //-----------------------------------------------------------------------
 801     @Test(groups={"tck"})
 802     public void test_withNanoOfSecond_normal() {
 803         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59, 1), OFFSET_PONE);
 804         OffsetTime test = base.withNano(15);
 805         assertEquals(test, OffsetTime.of(LocalTime.of(11, 30, 59, 15), OFFSET_PONE));
 806     }
 807 
 808     @Test(groups={"tck"})
 809     public void test_withNanoOfSecond_noChange() {
 810         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59, 1), OFFSET_PONE);
 811         OffsetTime test = base.withNano(1);
 812         assertEquals(test, base);
 813     }
 814 
 815     //-----------------------------------------------------------------------
 816     // truncatedTo(TemporalUnit)
 817     //-----------------------------------------------------------------------
 818     @Test(groups={"tck"})
 819     public void test_truncatedTo_normal() {
 820         assertEquals(TEST_11_30_59_500_PONE.truncatedTo(NANOS), TEST_11_30_59_500_PONE);
 821         assertEquals(TEST_11_30_59_500_PONE.truncatedTo(SECONDS), TEST_11_30_59_500_PONE.withNano(0));
 822         assertEquals(TEST_11_30_59_500_PONE.truncatedTo(DAYS), TEST_11_30_59_500_PONE.with(LocalTime.MIDNIGHT));
 823     }
 824 
 825     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 826     public void test_truncatedTo_null() {
 827         TEST_11_30_59_500_PONE.truncatedTo(null);
 828     }
 829 
 830     //-----------------------------------------------------------------------
 831     // plus(PlusAdjuster)
 832     //-----------------------------------------------------------------------
 833     @Test(groups={"tck"})
 834     public void test_plus_PlusAdjuster() {
 835         MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MINUTES);
 836         OffsetTime t = TEST_11_30_59_500_PONE.plus(period);
 837         assertEquals(t, OffsetTime.of(LocalTime.of(11, 37, 59, 500), OFFSET_PONE));
 838     }
 839 
 840     @Test(groups={"tck"})
 841     public void test_plus_PlusAdjuster_noChange() {
 842         OffsetTime t = TEST_11_30_59_500_PONE.plus(MockSimplePeriod.of(0, SECONDS));
 843         assertEquals(t, TEST_11_30_59_500_PONE);
 844     }
 845 
 846     @Test(groups={"tck"})
 847     public void test_plus_PlusAdjuster_zero() {
 848         OffsetTime t = TEST_11_30_59_500_PONE.plus(Period.ZERO);
 849         assertEquals(t, TEST_11_30_59_500_PONE);
 850     }
 851 
 852     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 853     public void test_plus_PlusAdjuster_null() {
 854         TEST_11_30_59_500_PONE.plus((TemporalAdder) null);
 855     }
 856 
 857     //-----------------------------------------------------------------------
 858     // plusHours()
 859     //-----------------------------------------------------------------------
 860     @Test(groups={"tck"})
 861     public void test_plusHours() {
 862         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 863         OffsetTime test = base.plusHours(13);
 864         assertEquals(test, OffsetTime.of(LocalTime.of(0, 30, 59), OFFSET_PONE));
 865     }
 866 
 867     @Test(groups={"tck"})
 868     public void test_plusHours_zero() {
 869         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 870         OffsetTime test = base.plusHours(0);
 871         assertEquals(test, base);
 872     }
 873 
 874     //-----------------------------------------------------------------------
 875     // plusMinutes()
 876     //-----------------------------------------------------------------------
 877     @Test(groups={"tck"})
 878     public void test_plusMinutes() {
 879         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 880         OffsetTime test = base.plusMinutes(30);
 881         assertEquals(test, OffsetTime.of(LocalTime.of(12, 0, 59), OFFSET_PONE));
 882     }
 883 
 884     @Test(groups={"tck"})
 885     public void test_plusMinutes_zero() {
 886         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 887         OffsetTime test = base.plusMinutes(0);
 888         assertEquals(test, base);
 889     }
 890 
 891     //-----------------------------------------------------------------------
 892     // plusSeconds()
 893     //-----------------------------------------------------------------------
 894     @Test(groups={"tck"})
 895     public void test_plusSeconds() {
 896         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 897         OffsetTime test = base.plusSeconds(1);
 898         assertEquals(test, OffsetTime.of(LocalTime.of(11, 31, 0), OFFSET_PONE));
 899     }
 900 
 901     @Test(groups={"tck"})
 902     public void test_plusSeconds_zero() {
 903         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 904         OffsetTime test = base.plusSeconds(0);
 905         assertEquals(test, base);
 906     }
 907 
 908     //-----------------------------------------------------------------------
 909     // plusNanos()
 910     //-----------------------------------------------------------------------
 911     @Test(groups={"tck"})
 912     public void test_plusNanos() {
 913         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59, 0), OFFSET_PONE);
 914         OffsetTime test = base.plusNanos(1);
 915         assertEquals(test, OffsetTime.of(LocalTime.of(11, 30, 59, 1), OFFSET_PONE));
 916     }
 917 
 918     @Test(groups={"tck"})
 919     public void test_plusNanos_zero() {
 920         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 921         OffsetTime test = base.plusNanos(0);
 922         assertEquals(test, base);
 923     }
 924 
 925     //-----------------------------------------------------------------------
 926     // minus(MinusAdjuster)
 927     //-----------------------------------------------------------------------
 928     @Test(groups={"tck"})
 929     public void test_minus_MinusAdjuster() {
 930         MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MINUTES);
 931         OffsetTime t = TEST_11_30_59_500_PONE.minus(period);
 932         assertEquals(t, OffsetTime.of(LocalTime.of(11, 23, 59, 500), OFFSET_PONE));
 933     }
 934 
 935     @Test(groups={"tck"})
 936     public void test_minus_MinusAdjuster_noChange() {
 937         OffsetTime t = TEST_11_30_59_500_PONE.minus(MockSimplePeriod.of(0, SECONDS));
 938         assertEquals(t, TEST_11_30_59_500_PONE);
 939     }
 940 
 941     @Test(groups={"tck"})
 942     public void test_minus_MinusAdjuster_zero() {
 943         OffsetTime t = TEST_11_30_59_500_PONE.minus(Period.ZERO);
 944         assertEquals(t, TEST_11_30_59_500_PONE);
 945     }
 946 
 947     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 948     public void test_minus_MinusAdjuster_null() {
 949         TEST_11_30_59_500_PONE.minus((TemporalSubtractor) null);
 950     }
 951 
 952     //-----------------------------------------------------------------------
 953     // minusHours()
 954     //-----------------------------------------------------------------------
 955     @Test(groups={"tck"})
 956     public void test_minusHours() {
 957         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 958         OffsetTime test = base.minusHours(-13);
 959         assertEquals(test, OffsetTime.of(LocalTime.of(0, 30, 59), OFFSET_PONE));
 960     }
 961 
 962     @Test(groups={"tck"})
 963     public void test_minusHours_zero() {
 964         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 965         OffsetTime test = base.minusHours(0);
 966         assertEquals(test, base);
 967     }
 968 
 969     //-----------------------------------------------------------------------
 970     // minusMinutes()
 971     //-----------------------------------------------------------------------
 972     @Test(groups={"tck"})
 973     public void test_minusMinutes() {
 974         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 975         OffsetTime test = base.minusMinutes(50);
 976         assertEquals(test, OffsetTime.of(LocalTime.of(10, 40, 59), OFFSET_PONE));
 977     }
 978 
 979     @Test(groups={"tck"})
 980     public void test_minusMinutes_zero() {
 981         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 982         OffsetTime test = base.minusMinutes(0);
 983         assertEquals(test, base);
 984     }
 985 
 986     //-----------------------------------------------------------------------
 987     // minusSeconds()
 988     //-----------------------------------------------------------------------
 989     @Test(groups={"tck"})
 990     public void test_minusSeconds() {
 991         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 992         OffsetTime test = base.minusSeconds(60);
 993         assertEquals(test, OffsetTime.of(LocalTime.of(11, 29, 59), OFFSET_PONE));
 994     }
 995 
 996     @Test(groups={"tck"})
 997     public void test_minusSeconds_zero() {
 998         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
 999         OffsetTime test = base.minusSeconds(0);
1000         assertEquals(test, base);
1001     }
1002 
1003     //-----------------------------------------------------------------------
1004     // minusNanos()
1005     //-----------------------------------------------------------------------
1006     @Test(groups={"tck"})
1007     public void test_minusNanos() {
1008         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59, 0), OFFSET_PONE);
1009         OffsetTime test = base.minusNanos(1);
1010         assertEquals(test, OffsetTime.of(LocalTime.of(11, 30, 58, 999999999), OFFSET_PONE));
1011     }
1012 
1013     @Test(groups={"tck"})
1014     public void test_minusNanos_zero() {
1015         OffsetTime base = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
1016         OffsetTime test = base.minusNanos(0);
1017         assertEquals(test, base);
1018     }
1019 
1020     //-----------------------------------------------------------------------
1021     // compareTo()
1022     //-----------------------------------------------------------------------
1023     @Test(groups={"tck"})
1024     public void test_compareTo_time() {
1025         OffsetTime a = OffsetTime.of(LocalTime.of(11, 29), OFFSET_PONE);
1026         OffsetTime b = OffsetTime.of(LocalTime.of(11, 30), OFFSET_PONE);  // a is before b due to time
1027         assertEquals(a.compareTo(b) < 0, true);
1028         assertEquals(b.compareTo(a) > 0, true);
1029         assertEquals(a.compareTo(a) == 0, true);
1030         assertEquals(b.compareTo(b) == 0, true);
1031         assertEquals(convertInstant(a).compareTo(convertInstant(b)) < 0, true);
1032     }
1033 
1034     @Test(groups={"tck"})
1035     public void test_compareTo_offset() {
1036         OffsetTime a = OffsetTime.of(LocalTime.of(11, 30), OFFSET_PTWO);
1037         OffsetTime b = OffsetTime.of(LocalTime.of(11, 30), OFFSET_PONE);  // a is before b due to offset
1038         assertEquals(a.compareTo(b) < 0, true);
1039         assertEquals(b.compareTo(a) > 0, true);
1040         assertEquals(a.compareTo(a) == 0, true);
1041         assertEquals(b.compareTo(b) == 0, true);
1042         assertEquals(convertInstant(a).compareTo(convertInstant(b)) < 0, true);
1043     }
1044 
1045     @Test(groups={"tck"})
1046     public void test_compareTo_both() {
1047         OffsetTime a = OffsetTime.of(LocalTime.of(11, 50), OFFSET_PTWO);
1048         OffsetTime b = OffsetTime.of(LocalTime.of(11, 20), OFFSET_PONE);  // a is before b on instant scale
1049         assertEquals(a.compareTo(b) < 0, true);
1050         assertEquals(b.compareTo(a) > 0, true);
1051         assertEquals(a.compareTo(a) == 0, true);
1052         assertEquals(b.compareTo(b) == 0, true);
1053         assertEquals(convertInstant(a).compareTo(convertInstant(b)) < 0, true);
1054     }
1055 
1056     @Test(groups={"tck"})
1057     public void test_compareTo_bothNearStartOfDay() {
1058         OffsetTime a = OffsetTime.of(LocalTime.of(0, 10), OFFSET_PONE);
1059         OffsetTime b = OffsetTime.of(LocalTime.of(2, 30), OFFSET_PTWO);  // a is before b on instant scale
1060         assertEquals(a.compareTo(b) < 0, true);
1061         assertEquals(b.compareTo(a) > 0, true);
1062         assertEquals(a.compareTo(a) == 0, true);
1063         assertEquals(b.compareTo(b) == 0, true);
1064         assertEquals(convertInstant(a).compareTo(convertInstant(b)) < 0, true);
1065     }
1066 
1067     @Test(groups={"tck"})
1068     public void test_compareTo_hourDifference() {
1069         OffsetTime a = OffsetTime.of(LocalTime.of(10, 0), OFFSET_PONE);
1070         OffsetTime b = OffsetTime.of(LocalTime.of(11, 0), OFFSET_PTWO);  // a is before b despite being same time-line time
1071         assertEquals(a.compareTo(b) < 0, true);
1072         assertEquals(b.compareTo(a) > 0, true);
1073         assertEquals(a.compareTo(a) == 0, true);
1074         assertEquals(b.compareTo(b) == 0, true);
1075         assertEquals(convertInstant(a).compareTo(convertInstant(b)) == 0, true);
1076     }
1077 
1078     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1079     public void test_compareTo_null() {
1080         OffsetTime a = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
1081         a.compareTo(null);
1082     }
1083 
1084     @Test(expectedExceptions=ClassCastException.class, groups={"tck"})
1085     @SuppressWarnings({"unchecked", "rawtypes"})
1086     public void compareToNonOffsetTime() {
1087        Comparable c = TEST_11_30_59_500_PONE;
1088        c.compareTo(new Object());
1089     }
1090 
1091     private Instant convertInstant(OffsetTime ot) {
1092         return DATE.atTime(ot.getTime()).toInstant(ot.getOffset());
1093     }
1094 
1095     //-----------------------------------------------------------------------
1096     // isAfter() / isBefore() / isEqual()
1097     //-----------------------------------------------------------------------
1098     @Test(groups={"tck"})
1099     public void test_isBeforeIsAfterIsEqual1() {
1100         OffsetTime a = OffsetTime.of(LocalTime.of(11, 30, 58), OFFSET_PONE);
1101         OffsetTime b = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);  // a is before b due to time
1102         assertEquals(a.isBefore(b), true);
1103         assertEquals(a.isEqual(b), false);
1104         assertEquals(a.isAfter(b), false);
1105 
1106         assertEquals(b.isBefore(a), false);
1107         assertEquals(b.isEqual(a), false);
1108         assertEquals(b.isAfter(a), true);
1109 
1110         assertEquals(a.isBefore(a), false);
1111         assertEquals(b.isBefore(b), false);
1112 
1113         assertEquals(a.isEqual(a), true);
1114         assertEquals(b.isEqual(b), true);
1115 
1116         assertEquals(a.isAfter(a), false);
1117         assertEquals(b.isAfter(b), false);
1118     }
1119 
1120     @Test(groups={"tck"})
1121     public void test_isBeforeIsAfterIsEqual1nanos() {
1122         OffsetTime a = OffsetTime.of(LocalTime.of(11, 30, 59, 3), OFFSET_PONE);
1123         OffsetTime b = OffsetTime.of(LocalTime.of(11, 30, 59, 4), OFFSET_PONE);  // a is before b due to time
1124         assertEquals(a.isBefore(b), true);
1125         assertEquals(a.isEqual(b), false);
1126         assertEquals(a.isAfter(b), false);
1127 
1128         assertEquals(b.isBefore(a), false);
1129         assertEquals(b.isEqual(a), false);
1130         assertEquals(b.isAfter(a), true);
1131 
1132         assertEquals(a.isBefore(a), false);
1133         assertEquals(b.isBefore(b), false);
1134 
1135         assertEquals(a.isEqual(a), true);
1136         assertEquals(b.isEqual(b), true);
1137 
1138         assertEquals(a.isAfter(a), false);
1139         assertEquals(b.isAfter(b), false);
1140     }
1141 
1142     @Test(groups={"tck"})
1143     public void test_isBeforeIsAfterIsEqual2() {
1144         OffsetTime a = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PTWO);
1145         OffsetTime b = OffsetTime.of(LocalTime.of(11, 30, 58), OFFSET_PONE);  // a is before b due to offset
1146         assertEquals(a.isBefore(b), true);
1147         assertEquals(a.isEqual(b), false);
1148         assertEquals(a.isAfter(b), false);
1149 
1150         assertEquals(b.isBefore(a), false);
1151         assertEquals(b.isEqual(a), false);
1152         assertEquals(b.isAfter(a), true);
1153 
1154         assertEquals(a.isBefore(a), false);
1155         assertEquals(b.isBefore(b), false);
1156 
1157         assertEquals(a.isEqual(a), true);
1158         assertEquals(b.isEqual(b), true);
1159 
1160         assertEquals(a.isAfter(a), false);
1161         assertEquals(b.isAfter(b), false);
1162     }
1163 
1164     @Test(groups={"tck"})
1165     public void test_isBeforeIsAfterIsEqual2nanos() {
1166         OffsetTime a = OffsetTime.of(LocalTime.of(11, 30, 59, 4), ZoneOffset.ofTotalSeconds(OFFSET_PONE.getTotalSeconds() + 1));
1167         OffsetTime b = OffsetTime.of(LocalTime.of(11, 30, 59, 3), OFFSET_PONE);  // a is before b due to offset
1168         assertEquals(a.isBefore(b), true);
1169         assertEquals(a.isEqual(b), false);
1170         assertEquals(a.isAfter(b), false);
1171 
1172         assertEquals(b.isBefore(a), false);
1173         assertEquals(b.isEqual(a), false);
1174         assertEquals(b.isAfter(a), true);
1175 
1176         assertEquals(a.isBefore(a), false);
1177         assertEquals(b.isBefore(b), false);
1178 
1179         assertEquals(a.isEqual(a), true);
1180         assertEquals(b.isEqual(b), true);
1181 
1182         assertEquals(a.isAfter(a), false);
1183         assertEquals(b.isAfter(b), false);
1184     }
1185 
1186     @Test(groups={"tck"})
1187     public void test_isBeforeIsAfterIsEqual_instantComparison() {
1188         OffsetTime a = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PTWO);
1189         OffsetTime b = OffsetTime.of(LocalTime.of(10, 30, 59), OFFSET_PONE);  // a is same instant as b
1190         assertEquals(a.isBefore(b), false);
1191         assertEquals(a.isEqual(b), true);
1192         assertEquals(a.isAfter(b), false);
1193 
1194         assertEquals(b.isBefore(a), false);
1195         assertEquals(b.isEqual(a), true);
1196         assertEquals(b.isAfter(a), false);
1197 
1198         assertEquals(a.isBefore(a), false);
1199         assertEquals(b.isBefore(b), false);
1200 
1201         assertEquals(a.isEqual(a), true);
1202         assertEquals(b.isEqual(b), true);
1203 
1204         assertEquals(a.isAfter(a), false);
1205         assertEquals(b.isAfter(b), false);
1206     }
1207 
1208     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1209     public void test_isBefore_null() {
1210         OffsetTime a = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
1211         a.isBefore(null);
1212     }
1213 
1214     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1215     public void test_isAfter_null() {
1216         OffsetTime a = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
1217         a.isAfter(null);
1218     }
1219 
1220     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1221     public void test_isEqual_null() {
1222         OffsetTime a = OffsetTime.of(LocalTime.of(11, 30, 59), OFFSET_PONE);
1223         a.isEqual(null);
1224     }
1225 
1226     //-----------------------------------------------------------------------
1227     // equals() / hashCode()
1228     //-----------------------------------------------------------------------
1229     @Test(dataProvider="sampleTimes", groups={"tck"})
1230     public void test_equals_true(int h, int m, int s, int n, ZoneOffset ignored) {
1231         OffsetTime a = OffsetTime.of(LocalTime.of(h, m, s, n), OFFSET_PONE);
1232         OffsetTime b = OffsetTime.of(LocalTime.of(h, m, s, n), OFFSET_PONE);
1233         assertEquals(a.equals(b), true);
1234         assertEquals(a.hashCode() == b.hashCode(), true);
1235     }
1236     @Test(dataProvider="sampleTimes", groups={"tck"})
1237     public void test_equals_false_hour_differs(int h, int m, int s, int n, ZoneOffset ignored) {
1238         h = (h == 23 ? 22 : h);
1239         OffsetTime a = OffsetTime.of(LocalTime.of(h, m, s, n), OFFSET_PONE);
1240         OffsetTime b = OffsetTime.of(LocalTime.of(h + 1, m, s, n), OFFSET_PONE);
1241         assertEquals(a.equals(b), false);
1242     }
1243     @Test(dataProvider="sampleTimes", groups={"tck"})
1244     public void test_equals_false_minute_differs(int h, int m, int s, int n, ZoneOffset ignored) {
1245         m = (m == 59 ? 58 : m);
1246         OffsetTime a = OffsetTime.of(LocalTime.of(h, m, s, n), OFFSET_PONE);
1247         OffsetTime b = OffsetTime.of(LocalTime.of(h, m + 1, s, n), OFFSET_PONE);
1248         assertEquals(a.equals(b), false);
1249     }
1250     @Test(dataProvider="sampleTimes", groups={"tck"})
1251     public void test_equals_false_second_differs(int h, int m, int s, int n, ZoneOffset ignored) {
1252         s = (s == 59 ? 58 : s);
1253         OffsetTime a = OffsetTime.of(LocalTime.of(h, m, s, n), OFFSET_PONE);
1254         OffsetTime b = OffsetTime.of(LocalTime.of(h, m, s + 1, n), OFFSET_PONE);
1255         assertEquals(a.equals(b), false);
1256     }
1257     @Test(dataProvider="sampleTimes", groups={"tck"})
1258     public void test_equals_false_nano_differs(int h, int m, int s, int n, ZoneOffset ignored) {
1259         n = (n == 999999999 ? 999999998 : n);
1260         OffsetTime a = OffsetTime.of(LocalTime.of(h, m, s, n), OFFSET_PONE);
1261         OffsetTime b = OffsetTime.of(LocalTime.of(h, m, s, n + 1), OFFSET_PONE);
1262         assertEquals(a.equals(b), false);
1263     }
1264     @Test(dataProvider="sampleTimes", groups={"tck"})
1265     public void test_equals_false_offset_differs(int h, int m, int s, int n, ZoneOffset ignored) {
1266         OffsetTime a = OffsetTime.of(LocalTime.of(h, m, s, n), OFFSET_PONE);
1267         OffsetTime b = OffsetTime.of(LocalTime.of(h, m, s, n), OFFSET_PTWO);
1268         assertEquals(a.equals(b), false);
1269     }
1270 
1271     @Test(groups={"tck"})
1272     public void test_equals_itself_true() {
1273         assertEquals(TEST_11_30_59_500_PONE.equals(TEST_11_30_59_500_PONE), true);
1274     }
1275 
1276     @Test(groups={"tck"})
1277     public void test_equals_string_false() {
1278         assertEquals(TEST_11_30_59_500_PONE.equals("2007-07-15"), false);
1279     }
1280 
1281     @Test(groups={"tck"})
1282     public void test_equals_null_false() {
1283         assertEquals(TEST_11_30_59_500_PONE.equals(null), false);
1284     }
1285 
1286     //-----------------------------------------------------------------------
1287     // toString()
1288     //-----------------------------------------------------------------------
1289     @DataProvider(name="sampleToString")
1290     Object[][] provider_sampleToString() {
1291         return new Object[][] {
1292             {11, 30, 59, 0, "Z", "11:30:59Z"},
1293             {11, 30, 59, 0, "+01:00", "11:30:59+01:00"},
1294             {11, 30, 59, 999000000, "Z", "11:30:59.999Z"},
1295             {11, 30, 59, 999000000, "+01:00", "11:30:59.999+01:00"},
1296             {11, 30, 59, 999000, "Z", "11:30:59.000999Z"},
1297             {11, 30, 59, 999000, "+01:00", "11:30:59.000999+01:00"},
1298             {11, 30, 59, 999, "Z", "11:30:59.000000999Z"},
1299             {11, 30, 59, 999, "+01:00", "11:30:59.000000999+01:00"},
1300         };
1301     }
1302 
1303     @Test(dataProvider="sampleToString", groups={"tck"})
1304     public void test_toString(int h, int m, int s, int n, String offsetId, String expected) {
1305         OffsetTime t = OffsetTime.of(LocalTime.of(h, m, s, n), ZoneOffset.of(offsetId));
1306         String str = t.toString();
1307         assertEquals(str, expected);
1308     }
1309 
1310     //-----------------------------------------------------------------------
1311     // toString(DateTimeFormatter)
1312     //-----------------------------------------------------------------------
1313     @Test(groups={"tck"})
1314     public void test_toString_formatter() {
1315         DateTimeFormatter f = DateTimeFormatters.pattern("H m s");
1316         String t = OffsetTime.of(LocalTime.of(11, 30), OFFSET_PONE).toString(f);
1317         assertEquals(t, "11 30 0");
1318     }
1319 
1320     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1321     public void test_toString_formatter_null() {
1322         OffsetTime.of(LocalTime.of(11, 30), OFFSET_PONE).toString(null);
1323     }
1324 
1325 }


  40  *  * Redistributions in binary form must reproduce the above copyright notice,
  41  *    this list of conditions and the following disclaimer in the documentation
  42  *    and/or other materials provided with the distribution.
  43  *
  44  *  * Neither the name of JSR-310 nor the names of its contributors
  45  *    may be used to endorse or promote products derived from this software
  46  *    without specific prior written permission.
  47  *
  48  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  49  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  50  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  51  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  52  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  53  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  54  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  55  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  56  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  57  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59  */
  60 package tck.java.time;
  61 
  62 import static java.time.temporal.ChronoField.AMPM_OF_DAY;
  63 import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_AMPM;
  64 import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_DAY;
  65 import static java.time.temporal.ChronoField.HOUR_OF_AMPM;
  66 import static java.time.temporal.ChronoField.HOUR_OF_DAY;
  67 import static java.time.temporal.ChronoField.MICRO_OF_DAY;
  68 import static java.time.temporal.ChronoField.MICRO_OF_SECOND;
  69 import static java.time.temporal.ChronoField.MILLI_OF_DAY;
  70 import static java.time.temporal.ChronoField.MILLI_OF_SECOND;
  71 import static java.time.temporal.ChronoField.MINUTE_OF_DAY;
  72 import static java.time.temporal.ChronoField.MINUTE_OF_HOUR;
  73 import static java.time.temporal.ChronoField.NANO_OF_DAY;
  74 import static java.time.temporal.ChronoField.NANO_OF_SECOND;
  75 import static java.time.temporal.ChronoField.OFFSET_SECONDS;
  76 import static java.time.temporal.ChronoField.SECOND_OF_DAY;
  77 import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
  78 import static java.time.temporal.ChronoUnit.DAYS;
  79 import static java.time.temporal.ChronoUnit.NANOS;
  80 import static java.time.temporal.ChronoUnit.SECONDS;
  81 import static org.testng.Assert.assertEquals;
  82 import static org.testng.Assert.assertNotNull;
  83 import static org.testng.Assert.assertTrue;
  84 
  85 import java.io.ByteArrayOutputStream;
  86 import java.io.DataOutputStream;

  87 import java.lang.reflect.Constructor;
  88 import java.lang.reflect.InvocationTargetException;




  89 import java.time.Clock;
  90 import java.time.DateTimeException;
  91 import java.time.Instant;
  92 import java.time.LocalDate;
  93 import java.time.LocalDateTime;
  94 import java.time.LocalTime;
  95 import java.time.OffsetTime;
  96 import java.time.Period;
  97 import java.time.ZoneId;
  98 import java.time.ZoneOffset;
  99 import java.time.ZonedDateTime;
 100 import java.time.format.DateTimeFormatter;

 101 import java.time.format.DateTimeParseException;
 102 import java.time.temporal.ChronoField;
 103 import java.time.temporal.ChronoUnit;
 104 import java.time.temporal.JulianFields;



 105 import java.time.temporal.Queries;
 106 import java.time.temporal.Temporal;
 107 import java.time.temporal.TemporalAccessor;

 108 import java.time.temporal.TemporalAdjuster;
 109 import java.time.temporal.TemporalAmount;
 110 import java.time.temporal.TemporalField;
 111 import java.time.temporal.TemporalQuery;
 112 import java.util.ArrayList;
 113 import java.util.Arrays;
 114 import java.util.List;
 115 
 116 import org.testng.annotations.BeforeMethod;
 117 import org.testng.annotations.DataProvider;
 118 import org.testng.annotations.Test;

 119 import test.java.time.MockSimplePeriod;
 120 
 121 /**
 122  * Test OffsetTime.
 123  */
 124 @Test
 125 public class TCKOffsetTime extends AbstractDateTimeTest {
 126 
 127     private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1);
 128     private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2);
 129     private static final LocalDate DATE = LocalDate.of(2008, 12, 3);
 130     private OffsetTime TEST_11_30_59_500_PONE;
 131 
 132     @BeforeMethod(groups={"tck","implementation"})
 133     public void setUp() {
 134         TEST_11_30_59_500_PONE = OffsetTime.of(11, 30, 59, 500, OFFSET_PONE);
 135     }
 136 
 137     //-----------------------------------------------------------------------
 138     @Override
 139     protected List<TemporalAccessor> samples() {
 140         TemporalAccessor[] array = {TEST_11_30_59_500_PONE, OffsetTime.MIN, OffsetTime.MAX};
 141         return Arrays.asList(array);
 142     }
 143 
 144     @Override
 145     protected List<TemporalField> validFields() {
 146         TemporalField[] array = {
 147             NANO_OF_SECOND,
 148             NANO_OF_DAY,
 149             MICRO_OF_SECOND,
 150             MICRO_OF_DAY,
 151             MILLI_OF_SECOND,
 152             MILLI_OF_DAY,
 153             SECOND_OF_MINUTE,
 154             SECOND_OF_DAY,


 169         List<TemporalField> list = new ArrayList<>(Arrays.<TemporalField>asList(ChronoField.values()));
 170         list.removeAll(validFields());
 171         list.add(JulianFields.JULIAN_DAY);
 172         list.add(JulianFields.MODIFIED_JULIAN_DAY);
 173         list.add(JulianFields.RATA_DIE);
 174         return list;
 175     }
 176 
 177     //-----------------------------------------------------------------------
 178     @Test
 179     public void test_serialization() throws Exception {
 180         assertSerializable(TEST_11_30_59_500_PONE);
 181         assertSerializable(OffsetTime.MIN);
 182         assertSerializable(OffsetTime.MAX);
 183     }
 184 
 185     @Test
 186     public void test_serialization_format() throws Exception {
 187         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 188         try (DataOutputStream dos = new DataOutputStream(baos) ) {
 189             dos.writeByte(9);       // java.time.Ser.OFFSET_TIME_TYPE
 190         }
 191         byte[] bytes = baos.toByteArray();
 192         ByteArrayOutputStream baosTime = new ByteArrayOutputStream();
 193         try (DataOutputStream dos = new DataOutputStream(baosTime) ) {
 194             dos.writeByte(4);
 195             dos.writeByte(22);
 196             dos.writeByte(17);
 197             dos.writeByte(59);
 198             dos.writeInt(464_000_000);
 199         }
 200         byte[] bytesTime = baosTime.toByteArray();
 201         ByteArrayOutputStream baosOffset = new ByteArrayOutputStream();
 202         try (DataOutputStream dos = new DataOutputStream(baosOffset) ) {
 203             dos.writeByte(8);
 204             dos.writeByte(4);  // quarter hours stored: 3600 / 900
 205         }
 206         byte[] bytesOffset = baosOffset.toByteArray();
 207         assertSerializedBySer(OffsetTime.of(22, 17, 59, 464_000_000, ZoneOffset.ofHours(1)), bytes,
 208                 bytesTime, bytesOffset);
 209     }
 210 
 211     //-----------------------------------------------------------------------
 212     // constants
 213     //-----------------------------------------------------------------------
 214     @Test
 215     public void constant_MIN() {
 216         check(OffsetTime.MIN, 0, 0, 0, 0, ZoneOffset.MAX);
 217     }
 218 
 219     @Test
 220     public void constant_MAX() {
 221         check(OffsetTime.MAX, 23, 59, 59, 999999999, ZoneOffset.MIN);
 222     }
 223 
 224     //-----------------------------------------------------------------------
 225     // now()
 226     //-----------------------------------------------------------------------
 227     @Test(groups={"tck"})
 228     public void now() {
 229         ZonedDateTime nowDT = ZonedDateTime.now();
 230 
 231         OffsetTime expected = OffsetTime.now(Clock.systemDefaultZone());
 232         OffsetTime test = OffsetTime.now();
 233         long diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
 234         assertTrue(diff < 100000000);  // less than 0.1 secs
 235         assertEquals(test.getOffset(), nowDT.getOffset());
 236     }
 237 
 238     //-----------------------------------------------------------------------
 239     // now(Clock)
 240     //-----------------------------------------------------------------------
 241     @Test(groups={"tck"})
 242     public void now_Clock_allSecsInDay() {
 243         for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
 244             Instant instant = Instant.ofEpochSecond(i, 8);
 245             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 246             OffsetTime test = OffsetTime.now(clock);
 247             assertEquals(test.getHour(), (i / (60 * 60)) % 24);
 248             assertEquals(test.getMinute(), (i / 60) % 60);
 249             assertEquals(test.getSecond(), i % 60);
 250             assertEquals(test.getNano(), 8);
 251             assertEquals(test.getOffset(), ZoneOffset.UTC);
 252         }
 253     }


 278             assertEquals(test.getSecond(), 0);
 279             assertEquals(test.getNano(), 0);
 280             assertEquals(test.getOffset(), offset);
 281         }
 282     }
 283 
 284     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 285     public void now_Clock_nullZoneId() {
 286         OffsetTime.now((ZoneId) null);
 287     }
 288 
 289     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 290     public void now_Clock_nullClock() {
 291         OffsetTime.now((Clock) null);
 292     }
 293 
 294     //-----------------------------------------------------------------------
 295     // factories
 296     //-----------------------------------------------------------------------
 297     private void check(OffsetTime test, int h, int m, int s, int n, ZoneOffset offset) {
 298         assertEquals(test.toLocalTime(), LocalTime.of(h, m, s, n));
 299         assertEquals(test.getOffset(), offset);
 300 
 301         assertEquals(test.getHour(), h);
 302         assertEquals(test.getMinute(), m);
 303         assertEquals(test.getSecond(), s);
 304         assertEquals(test.getNano(), n);
 305 
 306         assertEquals(test, test);
 307         assertEquals(test.hashCode(), test.hashCode());
 308         assertEquals(OffsetTime.of(LocalTime.of(h, m, s, n), offset), test);
 309     }
 310 
 311     //-----------------------------------------------------------------------
 312     @Test(groups={"tck"})














 313     public void factory_intsHMSN() {
 314         OffsetTime test = OffsetTime.of(11, 30, 10, 500, OFFSET_PONE);
 315         check(test, 11, 30, 10, 500, OFFSET_PONE);
 316     }
 317 
 318     //-----------------------------------------------------------------------
 319     @Test(groups={"tck"})
 320     public void factory_LocalTimeZoneOffset() {
 321         LocalTime localTime = LocalTime.of(11, 30, 10, 500);
 322         OffsetTime test = OffsetTime.of(localTime, OFFSET_PONE);
 323         check(test, 11, 30, 10, 500, OFFSET_PONE);
 324     }
 325 
 326     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 327     public void factory_LocalTimeZoneOffset_nullTime() {
 328         OffsetTime.of((LocalTime) null, OFFSET_PONE);
 329     }
 330 
 331     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 332     public void factory_LocalTimeZoneOffset_nullOffset() {
 333         LocalTime localTime = LocalTime.of(11, 30, 10, 500);
 334         OffsetTime.of(localTime, (ZoneOffset) null);


 379         assertEquals(test.getHour(), 23);
 380         assertEquals(test.getMinute(), 59);
 381         assertEquals(test.getSecond(), 59);
 382         assertEquals(test.getNano(), 999_999_999);
 383     }
 384 
 385     @Test(groups={"tck"})
 386     public void factory_ofInstant_minYear() {
 387         OffsetTime test = OffsetTime.ofInstant(Instant.MIN, ZoneOffset.UTC);
 388         assertEquals(test.getHour(), 0);
 389         assertEquals(test.getMinute(), 0);
 390         assertEquals(test.getSecond(), 0);
 391         assertEquals(test.getNano(), 0);
 392     }
 393 
 394     //-----------------------------------------------------------------------
 395     // from(TemporalAccessor)
 396     //-----------------------------------------------------------------------
 397     @Test(groups={"tck"})
 398     public void factory_from_TemporalAccessor_OT() {
 399         assertEquals(OffsetTime.from(OffsetTime.of(17, 30, 0, 0, OFFSET_PONE)), OffsetTime.of(17, 30, 0, 0, OFFSET_PONE));
 400     }
 401 
 402     @Test(groups={"tck"})
 403     public void test_from_TemporalAccessor_ZDT() {
 404         ZonedDateTime base = LocalDateTime.of(2007, 7, 15, 11, 30, 59, 500).atZone(OFFSET_PONE);
 405         assertEquals(OffsetTime.from(base), TEST_11_30_59_500_PONE);
 406     }
 407 
 408     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 409     public void factory_from_TemporalAccessor_invalid_noDerive() {
 410         OffsetTime.from(LocalDate.of(2007, 7, 15));
 411     }
 412 
 413     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 414     public void factory_from_TemporalAccessor_null() {
 415         OffsetTime.from((TemporalAccessor) null);
 416     }
 417 
 418     //-----------------------------------------------------------------------
 419     // parse()


 449     @Test(expectedExceptions={DateTimeParseException.class}, groups={"tck"})
 450     public void factory_parse_illegalHour() {
 451         OffsetTime.parse("25:00+01:00");
 452     }
 453 
 454     @Test(expectedExceptions={DateTimeParseException.class}, groups={"tck"})
 455     public void factory_parse_illegalMinute() {
 456         OffsetTime.parse("12:60+01:00");
 457     }
 458 
 459     @Test(expectedExceptions={DateTimeParseException.class}, groups={"tck"})
 460     public void factory_parse_illegalSecond() {
 461         OffsetTime.parse("12:12:60+01:00");
 462     }
 463 
 464     //-----------------------------------------------------------------------
 465     // parse(DateTimeFormatter)
 466     //-----------------------------------------------------------------------
 467     @Test(groups={"tck"})
 468     public void factory_parse_formatter() {
 469         DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s XXX");
 470         OffsetTime test = OffsetTime.parse("11 30 0 +01:00", f);
 471         assertEquals(test, OffsetTime.of(11, 30, 0, 0, ZoneOffset.ofHours(1)));
 472     }
 473 
 474     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 475     public void factory_parse_formatter_nullText() {
 476         DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
 477         OffsetTime.parse((String) null, f);
 478     }
 479 
 480     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 481     public void factory_parse_formatter_nullFormatter() {
 482         OffsetTime.parse("ANY", null);
 483     }
 484 
 485     //-----------------------------------------------------------------------
 486     // constructor
 487     //-----------------------------------------------------------------------
 488     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 489     public void constructor_nullTime() throws Throwable  {
 490         Constructor<OffsetTime> con = OffsetTime.class.getDeclaredConstructor(LocalTime.class, ZoneOffset.class);
 491         con.setAccessible(true);
 492         try {
 493             con.newInstance(null, OFFSET_PONE);
 494         } catch (InvocationTargetException ex) {
 495             throw ex.getCause();
 496         }
 497     }
 498 
 499     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 500     public void constructor_nullOffset() throws Throwable  {
 501         Constructor<OffsetTime> con = OffsetTime.class.getDeclaredConstructor(LocalTime.class, ZoneOffset.class);
 502         con.setAccessible(true);
 503         try {
 504             con.newInstance(LocalTime.of(11, 30, 0, 0), null);
 505         } catch (InvocationTargetException ex) {
 506             throw ex.getCause();
 507         }
 508     }
 509 
 510     //-----------------------------------------------------------------------
 511     // basics
 512     //-----------------------------------------------------------------------
 513     @DataProvider(name="sampleTimes")
 514     Object[][] provider_sampleTimes() {
 515         return new Object[][] {
 516             {11, 30, 20, 500, OFFSET_PONE},
 517             {11, 0, 0, 0, OFFSET_PONE},
 518             {23, 59, 59, 999999999, OFFSET_PONE},
 519         };
 520     }
 521 
 522     @Test(dataProvider="sampleTimes", groups={"tck"})
 523     public void test_get(int h, int m, int s, int n, ZoneOffset offset) {
 524         LocalTime localTime = LocalTime.of(h, m, s, n);
 525         OffsetTime a = OffsetTime.of(localTime, offset);
 526 
 527         assertEquals(a.toLocalTime(), localTime);
 528         assertEquals(a.getOffset(), offset);
 529         assertEquals(a.toString(), localTime.toString() + offset.toString());
 530         assertEquals(a.getHour(), localTime.getHour());
 531         assertEquals(a.getMinute(), localTime.getMinute());
 532         assertEquals(a.getSecond(), localTime.getSecond());
 533         assertEquals(a.getNano(), localTime.getNano());
 534     }
 535 
 536     //-----------------------------------------------------------------------
 537     // get(TemporalField)
 538     //-----------------------------------------------------------------------
 539     @Test
 540     public void test_get_TemporalField() {
 541         OffsetTime test = OffsetTime.of(12, 30, 40, 987654321, OFFSET_PONE);
 542         assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12);
 543         assertEquals(test.get(ChronoField.MINUTE_OF_HOUR), 30);
 544         assertEquals(test.get(ChronoField.SECOND_OF_MINUTE), 40);
 545         assertEquals(test.get(ChronoField.NANO_OF_SECOND), 987654321);
 546         assertEquals(test.get(ChronoField.HOUR_OF_AMPM), 0);
 547         assertEquals(test.get(ChronoField.AMPM_OF_DAY), 1);
 548 
 549         assertEquals(test.get(ChronoField.OFFSET_SECONDS), 3600);
 550     }
 551 
 552     @Test
 553     public void test_getLong_TemporalField() {
 554         OffsetTime test = OffsetTime.of(12, 30, 40, 987654321, OFFSET_PONE);
 555         assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12);
 556         assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30);
 557         assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40);
 558         assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321);
 559         assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0);
 560         assertEquals(test.getLong(ChronoField.AMPM_OF_DAY), 1);
 561 
 562         assertEquals(test.getLong(ChronoField.OFFSET_SECONDS), 3600);
 563     }
 564 
 565     //-----------------------------------------------------------------------
 566     // query(TemporalQuery)
 567     //-----------------------------------------------------------------------
 568     @DataProvider(name="query")
 569     Object[][] data_query() {
 570         return new Object[][] {
 571                 {TEST_11_30_59_500_PONE, Queries.chronology(), null},
 572                 {TEST_11_30_59_500_PONE, Queries.zoneId(), null},
 573                 {TEST_11_30_59_500_PONE, Queries.precision(), ChronoUnit.NANOS},
 574                 {TEST_11_30_59_500_PONE, Queries.zone(), OFFSET_PONE},
 575                 {TEST_11_30_59_500_PONE, Queries.offset(), OFFSET_PONE},
 576                 {TEST_11_30_59_500_PONE, Queries.localDate(), null},
 577                 {TEST_11_30_59_500_PONE, Queries.localTime(), LocalTime.of(11, 30, 59, 500)},
 578         };





 579     }
 580 
 581     @Test(dataProvider="query")
 582     public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 583         assertEquals(temporal.query(query), expected);

 584     }
 585 
 586     @Test(dataProvider="query")
 587     public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 588         assertEquals(query.queryFrom(temporal), expected);

 589     }
 590 
 591     @Test(expectedExceptions=NullPointerException.class)
 592     public void test_query_null() {
 593         TEST_11_30_59_500_PONE.query(null);
 594     }
 595 
 596     //-----------------------------------------------------------------------
 597     // withOffsetSameLocal()
 598     //-----------------------------------------------------------------------
 599     @Test(groups={"tck"})
 600     public void test_withOffsetSameLocal() {
 601         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 602         OffsetTime test = base.withOffsetSameLocal(OFFSET_PTWO);
 603         assertEquals(test.toLocalTime(), base.toLocalTime());
 604         assertEquals(test.getOffset(), OFFSET_PTWO);
 605     }
 606 
 607     @Test(groups={"tck"})
 608     public void test_withOffsetSameLocal_noChange() {
 609         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 610         OffsetTime test = base.withOffsetSameLocal(OFFSET_PONE);
 611         assertEquals(test, base);
 612     }
 613 
 614     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 615     public void test_withOffsetSameLocal_null() {
 616         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 617         base.withOffsetSameLocal(null);
 618     }
 619 
 620     //-----------------------------------------------------------------------
 621     // withOffsetSameInstant()
 622     //-----------------------------------------------------------------------
 623     @Test(groups={"tck"})
 624     public void test_withOffsetSameInstant() {
 625         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 626         OffsetTime test = base.withOffsetSameInstant(OFFSET_PTWO);
 627         OffsetTime expected = OffsetTime.of(12, 30, 59, 0, OFFSET_PTWO);
 628         assertEquals(test, expected);
 629     }
 630 
 631     @Test(groups={"tck"})
 632     public void test_withOffsetSameInstant_noChange() {
 633         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 634         OffsetTime test = base.withOffsetSameInstant(OFFSET_PONE);
 635         assertEquals(test, base);
 636     }
 637 
 638     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 639     public void test_withOffsetSameInstant_null() {
 640         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 641         base.withOffsetSameInstant(null);
 642     }
 643 
 644     //-----------------------------------------------------------------------
 645     // with(WithAdjuster)
 646     //-----------------------------------------------------------------------
 647     @Test(groups={"tck"})
 648     public void test_with_adjustment() {
 649         final OffsetTime sample = OffsetTime.of(23, 5, 0, 0, OFFSET_PONE);
 650         TemporalAdjuster adjuster = new TemporalAdjuster() {
 651             @Override
 652             public Temporal adjustInto(Temporal dateTime) {
 653                 return sample;
 654             }
 655         };
 656         assertEquals(TEST_11_30_59_500_PONE.with(adjuster), sample);
 657     }
 658 
 659     @Test(groups={"tck"})
 660     public void test_with_adjustment_LocalTime() {
 661         OffsetTime test = TEST_11_30_59_500_PONE.with(LocalTime.of(13, 30));
 662         assertEquals(test, OffsetTime.of(13, 30, 0, 0, OFFSET_PONE));
 663     }
 664 
 665     @Test(groups={"tck"})
 666     public void test_with_adjustment_OffsetTime() {
 667         OffsetTime test = TEST_11_30_59_500_PONE.with(OffsetTime.of(13, 35, 0, 0, OFFSET_PTWO));
 668         assertEquals(test, OffsetTime.of(13, 35, 0, 0, OFFSET_PTWO));
 669     }
 670 
 671     @Test(groups={"tck"})
 672     public void test_with_adjustment_ZoneOffset() {
 673         OffsetTime test = TEST_11_30_59_500_PONE.with(OFFSET_PTWO);
 674         assertEquals(test, OffsetTime.of(11, 30, 59, 500, OFFSET_PTWO));
 675     }
 676 
 677     @Test(groups={"tck"})
 678     public void test_with_adjustment_AmPm() {
 679         OffsetTime test = TEST_11_30_59_500_PONE.with(new TemporalAdjuster() {
 680             @Override
 681             public Temporal adjustInto(Temporal dateTime) {
 682                 return dateTime.with(HOUR_OF_DAY, 23);
 683             }
 684         });
 685         assertEquals(test, OffsetTime.of(23, 30, 59, 500, OFFSET_PONE));
 686     }
 687 
 688     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 689     public void test_with_adjustment_null() {
 690         TEST_11_30_59_500_PONE.with((TemporalAdjuster) null);
 691     }
 692 
 693     //-----------------------------------------------------------------------
 694     // with(TemporalField, long)
 695     //-----------------------------------------------------------------------
 696     @Test(groups={"tck"})
 697     public void test_with_TemporalField() {
 698         OffsetTime test = OffsetTime.of(12, 30, 40, 987654321, OFFSET_PONE);
 699         assertEquals(test.with(ChronoField.HOUR_OF_DAY, 15), OffsetTime.of(15, 30, 40, 987654321, OFFSET_PONE));
 700         assertEquals(test.with(ChronoField.MINUTE_OF_HOUR, 50), OffsetTime.of(12, 50, 40, 987654321, OFFSET_PONE));
 701         assertEquals(test.with(ChronoField.SECOND_OF_MINUTE, 50), OffsetTime.of(12, 30, 50, 987654321, OFFSET_PONE));
 702         assertEquals(test.with(ChronoField.NANO_OF_SECOND, 12345), OffsetTime.of(12, 30, 40, 12345, OFFSET_PONE));
 703         assertEquals(test.with(ChronoField.HOUR_OF_AMPM, 6), OffsetTime.of(18, 30, 40, 987654321, OFFSET_PONE));
 704         assertEquals(test.with(ChronoField.AMPM_OF_DAY, 0), OffsetTime.of(0, 30, 40, 987654321, OFFSET_PONE));
 705 
 706         assertEquals(test.with(ChronoField.OFFSET_SECONDS, 7205), OffsetTime.of(12, 30, 40, 987654321, ZoneOffset.ofHoursMinutesSeconds(2, 0, 5)));
 707     }
 708 
 709     @Test(expectedExceptions=NullPointerException.class, groups={"tck"} )
 710     public void test_with_TemporalField_null() {
 711         TEST_11_30_59_500_PONE.with((TemporalField) null, 0);
 712     }
 713 
 714     @Test(expectedExceptions=DateTimeException.class, groups={"tck"} )
 715     public void test_with_TemporalField_invalidField() {
 716         TEST_11_30_59_500_PONE.with(ChronoField.YEAR, 0);
 717     }
 718 
 719     //-----------------------------------------------------------------------
 720     // withHour()
 721     //-----------------------------------------------------------------------
 722     @Test(groups={"tck"})
 723     public void test_withHour_normal() {
 724         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 725         OffsetTime test = base.withHour(15);
 726         assertEquals(test, OffsetTime.of(15, 30, 59, 0, OFFSET_PONE));
 727     }
 728 
 729     @Test(groups={"tck"})
 730     public void test_withHour_noChange() {
 731         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 732         OffsetTime test = base.withHour(11);
 733         assertEquals(test, base);
 734     }
 735 
 736     //-----------------------------------------------------------------------
 737     // withMinute()
 738     //-----------------------------------------------------------------------
 739     @Test(groups={"tck"})
 740     public void test_withMinute_normal() {
 741         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 742         OffsetTime test = base.withMinute(15);
 743         assertEquals(test, OffsetTime.of(11, 15, 59, 0, OFFSET_PONE));
 744     }
 745 
 746     @Test(groups={"tck"})
 747     public void test_withMinute_noChange() {
 748         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 749         OffsetTime test = base.withMinute(30);
 750         assertEquals(test, base);
 751     }
 752 
 753     //-----------------------------------------------------------------------
 754     // withSecond()
 755     //-----------------------------------------------------------------------
 756     @Test(groups={"tck"})
 757     public void test_withSecond_normal() {
 758         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 759         OffsetTime test = base.withSecond(15);
 760         assertEquals(test, OffsetTime.of(11, 30, 15, 0, OFFSET_PONE));
 761     }
 762 
 763     @Test(groups={"tck"})
 764     public void test_withSecond_noChange() {
 765         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 766         OffsetTime test = base.withSecond(59);
 767         assertEquals(test, base);
 768     }
 769 
 770     //-----------------------------------------------------------------------
 771     // withNano()
 772     //-----------------------------------------------------------------------
 773     @Test(groups={"tck"})
 774     public void test_withNanoOfSecond_normal() {
 775         OffsetTime base = OffsetTime.of(11, 30, 59, 1, OFFSET_PONE);
 776         OffsetTime test = base.withNano(15);
 777         assertEquals(test, OffsetTime.of(11, 30, 59, 15, OFFSET_PONE));
 778     }
 779 
 780     @Test(groups={"tck"})
 781     public void test_withNanoOfSecond_noChange() {
 782         OffsetTime base = OffsetTime.of(11, 30, 59, 1, OFFSET_PONE);
 783         OffsetTime test = base.withNano(1);
 784         assertEquals(test, base);
 785     }
 786 
 787     //-----------------------------------------------------------------------
 788     // truncatedTo(TemporalUnit)
 789     //-----------------------------------------------------------------------
 790     @Test(groups={"tck"})
 791     public void test_truncatedTo_normal() {
 792         assertEquals(TEST_11_30_59_500_PONE.truncatedTo(NANOS), TEST_11_30_59_500_PONE);
 793         assertEquals(TEST_11_30_59_500_PONE.truncatedTo(SECONDS), TEST_11_30_59_500_PONE.withNano(0));
 794         assertEquals(TEST_11_30_59_500_PONE.truncatedTo(DAYS), TEST_11_30_59_500_PONE.with(LocalTime.MIDNIGHT));
 795     }
 796 
 797     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 798     public void test_truncatedTo_null() {
 799         TEST_11_30_59_500_PONE.truncatedTo(null);
 800     }
 801 
 802     //-----------------------------------------------------------------------
 803     // plus(PlusAdjuster)
 804     //-----------------------------------------------------------------------
 805     @Test(groups={"tck"})
 806     public void test_plus_PlusAdjuster() {
 807         MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MINUTES);
 808         OffsetTime t = TEST_11_30_59_500_PONE.plus(period);
 809         assertEquals(t, OffsetTime.of(11, 37, 59, 500, OFFSET_PONE));
 810     }
 811 
 812     @Test(groups={"tck"})
 813     public void test_plus_PlusAdjuster_noChange() {
 814         OffsetTime t = TEST_11_30_59_500_PONE.plus(MockSimplePeriod.of(0, SECONDS));
 815         assertEquals(t, TEST_11_30_59_500_PONE);
 816     }
 817 
 818     @Test(groups={"tck"})
 819     public void test_plus_PlusAdjuster_zero() {
 820         OffsetTime t = TEST_11_30_59_500_PONE.plus(Period.ZERO);
 821         assertEquals(t, TEST_11_30_59_500_PONE);
 822     }
 823 
 824     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 825     public void test_plus_PlusAdjuster_null() {
 826         TEST_11_30_59_500_PONE.plus((TemporalAmount) null);
 827     }
 828 
 829     //-----------------------------------------------------------------------
 830     // plusHours()
 831     //-----------------------------------------------------------------------
 832     @Test(groups={"tck"})
 833     public void test_plusHours() {
 834         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 835         OffsetTime test = base.plusHours(13);
 836         assertEquals(test, OffsetTime.of(0, 30, 59, 0, OFFSET_PONE));
 837     }
 838 
 839     @Test(groups={"tck"})
 840     public void test_plusHours_zero() {
 841         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 842         OffsetTime test = base.plusHours(0);
 843         assertEquals(test, base);
 844     }
 845 
 846     //-----------------------------------------------------------------------
 847     // plusMinutes()
 848     //-----------------------------------------------------------------------
 849     @Test(groups={"tck"})
 850     public void test_plusMinutes() {
 851         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 852         OffsetTime test = base.plusMinutes(30);
 853         assertEquals(test, OffsetTime.of(12, 0, 59, 0, OFFSET_PONE));
 854     }
 855 
 856     @Test(groups={"tck"})
 857     public void test_plusMinutes_zero() {
 858         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 859         OffsetTime test = base.plusMinutes(0);
 860         assertEquals(test, base);
 861     }
 862 
 863     //-----------------------------------------------------------------------
 864     // plusSeconds()
 865     //-----------------------------------------------------------------------
 866     @Test(groups={"tck"})
 867     public void test_plusSeconds() {
 868         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 869         OffsetTime test = base.plusSeconds(1);
 870         assertEquals(test, OffsetTime.of(11, 31, 0, 0, OFFSET_PONE));
 871     }
 872 
 873     @Test(groups={"tck"})
 874     public void test_plusSeconds_zero() {
 875         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 876         OffsetTime test = base.plusSeconds(0);
 877         assertEquals(test, base);
 878     }
 879 
 880     //-----------------------------------------------------------------------
 881     // plusNanos()
 882     //-----------------------------------------------------------------------
 883     @Test(groups={"tck"})
 884     public void test_plusNanos() {
 885         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 886         OffsetTime test = base.plusNanos(1);
 887         assertEquals(test, OffsetTime.of(11, 30, 59, 1, OFFSET_PONE));
 888     }
 889 
 890     @Test(groups={"tck"})
 891     public void test_plusNanos_zero() {
 892         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 893         OffsetTime test = base.plusNanos(0);
 894         assertEquals(test, base);
 895     }
 896 
 897     //-----------------------------------------------------------------------
 898     // minus(MinusAdjuster)
 899     //-----------------------------------------------------------------------
 900     @Test(groups={"tck"})
 901     public void test_minus_MinusAdjuster() {
 902         MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MINUTES);
 903         OffsetTime t = TEST_11_30_59_500_PONE.minus(period);
 904         assertEquals(t, OffsetTime.of(11, 23, 59, 500, OFFSET_PONE));
 905     }
 906 
 907     @Test(groups={"tck"})
 908     public void test_minus_MinusAdjuster_noChange() {
 909         OffsetTime t = TEST_11_30_59_500_PONE.minus(MockSimplePeriod.of(0, SECONDS));
 910         assertEquals(t, TEST_11_30_59_500_PONE);
 911     }
 912 
 913     @Test(groups={"tck"})
 914     public void test_minus_MinusAdjuster_zero() {
 915         OffsetTime t = TEST_11_30_59_500_PONE.minus(Period.ZERO);
 916         assertEquals(t, TEST_11_30_59_500_PONE);
 917     }
 918 
 919     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 920     public void test_minus_MinusAdjuster_null() {
 921         TEST_11_30_59_500_PONE.minus((TemporalAmount) null);
 922     }
 923 
 924     //-----------------------------------------------------------------------
 925     // minusHours()
 926     //-----------------------------------------------------------------------
 927     @Test(groups={"tck"})
 928     public void test_minusHours() {
 929         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 930         OffsetTime test = base.minusHours(-13);
 931         assertEquals(test, OffsetTime.of(0, 30, 59, 0, OFFSET_PONE));
 932     }
 933 
 934     @Test(groups={"tck"})
 935     public void test_minusHours_zero() {
 936         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 937         OffsetTime test = base.minusHours(0);
 938         assertEquals(test, base);
 939     }
 940 
 941     //-----------------------------------------------------------------------
 942     // minusMinutes()
 943     //-----------------------------------------------------------------------
 944     @Test(groups={"tck"})
 945     public void test_minusMinutes() {
 946         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 947         OffsetTime test = base.minusMinutes(50);
 948         assertEquals(test, OffsetTime.of(10, 40, 59, 0, OFFSET_PONE));
 949     }
 950 
 951     @Test(groups={"tck"})
 952     public void test_minusMinutes_zero() {
 953         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 954         OffsetTime test = base.minusMinutes(0);
 955         assertEquals(test, base);
 956     }
 957 
 958     //-----------------------------------------------------------------------
 959     // minusSeconds()
 960     //-----------------------------------------------------------------------
 961     @Test(groups={"tck"})
 962     public void test_minusSeconds() {
 963         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 964         OffsetTime test = base.minusSeconds(60);
 965         assertEquals(test, OffsetTime.of(11, 29, 59, 0, OFFSET_PONE));
 966     }
 967 
 968     @Test(groups={"tck"})
 969     public void test_minusSeconds_zero() {
 970         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 971         OffsetTime test = base.minusSeconds(0);
 972         assertEquals(test, base);
 973     }
 974 
 975     //-----------------------------------------------------------------------
 976     // minusNanos()
 977     //-----------------------------------------------------------------------
 978     @Test(groups={"tck"})
 979     public void test_minusNanos() {
 980         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 981         OffsetTime test = base.minusNanos(1);
 982         assertEquals(test, OffsetTime.of(11, 30, 58, 999999999, OFFSET_PONE));
 983     }
 984 
 985     @Test(groups={"tck"})
 986     public void test_minusNanos_zero() {
 987         OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
 988         OffsetTime test = base.minusNanos(0);
 989         assertEquals(test, base);
 990     }
 991 
 992     //-----------------------------------------------------------------------
 993     // compareTo()
 994     //-----------------------------------------------------------------------
 995     @Test(groups={"tck"})
 996     public void test_compareTo_time() {
 997         OffsetTime a = OffsetTime.of(11, 29, 0, 0, OFFSET_PONE);
 998         OffsetTime b = OffsetTime.of(11, 30, 0, 0, OFFSET_PONE);  // a is before b due to time
 999         assertEquals(a.compareTo(b) < 0, true);
1000         assertEquals(b.compareTo(a) > 0, true);
1001         assertEquals(a.compareTo(a) == 0, true);
1002         assertEquals(b.compareTo(b) == 0, true);
1003         assertEquals(convertInstant(a).compareTo(convertInstant(b)) < 0, true);
1004     }
1005 
1006     @Test(groups={"tck"})
1007     public void test_compareTo_offset() {
1008         OffsetTime a = OffsetTime.of(11, 30, 0, 0, OFFSET_PTWO);
1009         OffsetTime b = OffsetTime.of(11, 30, 0, 0, OFFSET_PONE);  // a is before b due to offset
1010         assertEquals(a.compareTo(b) < 0, true);
1011         assertEquals(b.compareTo(a) > 0, true);
1012         assertEquals(a.compareTo(a) == 0, true);
1013         assertEquals(b.compareTo(b) == 0, true);
1014         assertEquals(convertInstant(a).compareTo(convertInstant(b)) < 0, true);
1015     }
1016 
1017     @Test(groups={"tck"})
1018     public void test_compareTo_both() {
1019         OffsetTime a = OffsetTime.of(11, 50, 0, 0, OFFSET_PTWO);
1020         OffsetTime b = OffsetTime.of(11, 20, 0, 0, OFFSET_PONE);  // a is before b on instant scale
1021         assertEquals(a.compareTo(b) < 0, true);
1022         assertEquals(b.compareTo(a) > 0, true);
1023         assertEquals(a.compareTo(a) == 0, true);
1024         assertEquals(b.compareTo(b) == 0, true);
1025         assertEquals(convertInstant(a).compareTo(convertInstant(b)) < 0, true);
1026     }
1027 
1028     @Test(groups={"tck"})
1029     public void test_compareTo_bothNearStartOfDay() {
1030         OffsetTime a = OffsetTime.of(0, 10, 0, 0, OFFSET_PONE);
1031         OffsetTime b = OffsetTime.of(2, 30, 0, 0, OFFSET_PTWO);  // a is before b on instant scale
1032         assertEquals(a.compareTo(b) < 0, true);
1033         assertEquals(b.compareTo(a) > 0, true);
1034         assertEquals(a.compareTo(a) == 0, true);
1035         assertEquals(b.compareTo(b) == 0, true);
1036         assertEquals(convertInstant(a).compareTo(convertInstant(b)) < 0, true);
1037     }
1038 
1039     @Test(groups={"tck"})
1040     public void test_compareTo_hourDifference() {
1041         OffsetTime a = OffsetTime.of(10, 0, 0, 0, OFFSET_PONE);
1042         OffsetTime b = OffsetTime.of(11, 0, 0, 0, OFFSET_PTWO);  // a is before b despite being same time-line time
1043         assertEquals(a.compareTo(b) < 0, true);
1044         assertEquals(b.compareTo(a) > 0, true);
1045         assertEquals(a.compareTo(a) == 0, true);
1046         assertEquals(b.compareTo(b) == 0, true);
1047         assertEquals(convertInstant(a).compareTo(convertInstant(b)) == 0, true);
1048     }
1049 
1050     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1051     public void test_compareTo_null() {
1052         OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
1053         a.compareTo(null);
1054     }
1055 
1056     @Test(expectedExceptions=ClassCastException.class, groups={"tck"})
1057     @SuppressWarnings({"unchecked", "rawtypes"})
1058     public void compareToNonOffsetTime() {
1059        Comparable c = TEST_11_30_59_500_PONE;
1060        c.compareTo(new Object());
1061     }
1062 
1063     private Instant convertInstant(OffsetTime ot) {
1064         return DATE.atTime(ot.toLocalTime()).toInstant(ot.getOffset());
1065     }
1066 
1067     //-----------------------------------------------------------------------
1068     // isAfter() / isBefore() / isEqual()
1069     //-----------------------------------------------------------------------
1070     @Test(groups={"tck"})
1071     public void test_isBeforeIsAfterIsEqual1() {
1072         OffsetTime a = OffsetTime.of(11, 30, 58, 0, OFFSET_PONE);
1073         OffsetTime b = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);  // a is before b due to time
1074         assertEquals(a.isBefore(b), true);
1075         assertEquals(a.isEqual(b), false);
1076         assertEquals(a.isAfter(b), false);
1077 
1078         assertEquals(b.isBefore(a), false);
1079         assertEquals(b.isEqual(a), false);
1080         assertEquals(b.isAfter(a), true);
1081 
1082         assertEquals(a.isBefore(a), false);
1083         assertEquals(b.isBefore(b), false);
1084 
1085         assertEquals(a.isEqual(a), true);
1086         assertEquals(b.isEqual(b), true);
1087 
1088         assertEquals(a.isAfter(a), false);
1089         assertEquals(b.isAfter(b), false);
1090     }
1091 
1092     @Test(groups={"tck"})
1093     public void test_isBeforeIsAfterIsEqual1nanos() {
1094         OffsetTime a = OffsetTime.of(11, 30, 59, 3, OFFSET_PONE);
1095         OffsetTime b = OffsetTime.of(11, 30, 59, 4, OFFSET_PONE);  // a is before b due to time
1096         assertEquals(a.isBefore(b), true);
1097         assertEquals(a.isEqual(b), false);
1098         assertEquals(a.isAfter(b), false);
1099 
1100         assertEquals(b.isBefore(a), false);
1101         assertEquals(b.isEqual(a), false);
1102         assertEquals(b.isAfter(a), true);
1103 
1104         assertEquals(a.isBefore(a), false);
1105         assertEquals(b.isBefore(b), false);
1106 
1107         assertEquals(a.isEqual(a), true);
1108         assertEquals(b.isEqual(b), true);
1109 
1110         assertEquals(a.isAfter(a), false);
1111         assertEquals(b.isAfter(b), false);
1112     }
1113 
1114     @Test(groups={"tck"})
1115     public void test_isBeforeIsAfterIsEqual2() {
1116         OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PTWO);
1117         OffsetTime b = OffsetTime.of(11, 30, 58, 0, OFFSET_PONE);  // a is before b due to offset
1118         assertEquals(a.isBefore(b), true);
1119         assertEquals(a.isEqual(b), false);
1120         assertEquals(a.isAfter(b), false);
1121 
1122         assertEquals(b.isBefore(a), false);
1123         assertEquals(b.isEqual(a), false);
1124         assertEquals(b.isAfter(a), true);
1125 
1126         assertEquals(a.isBefore(a), false);
1127         assertEquals(b.isBefore(b), false);
1128 
1129         assertEquals(a.isEqual(a), true);
1130         assertEquals(b.isEqual(b), true);
1131 
1132         assertEquals(a.isAfter(a), false);
1133         assertEquals(b.isAfter(b), false);
1134     }
1135 
1136     @Test(groups={"tck"})
1137     public void test_isBeforeIsAfterIsEqual2nanos() {
1138         OffsetTime a = OffsetTime.of(11, 30, 59, 4, ZoneOffset.ofTotalSeconds(OFFSET_PONE.getTotalSeconds() + 1));
1139         OffsetTime b = OffsetTime.of(11, 30, 59, 3, OFFSET_PONE);  // a is before b due to offset
1140         assertEquals(a.isBefore(b), true);
1141         assertEquals(a.isEqual(b), false);
1142         assertEquals(a.isAfter(b), false);
1143 
1144         assertEquals(b.isBefore(a), false);
1145         assertEquals(b.isEqual(a), false);
1146         assertEquals(b.isAfter(a), true);
1147 
1148         assertEquals(a.isBefore(a), false);
1149         assertEquals(b.isBefore(b), false);
1150 
1151         assertEquals(a.isEqual(a), true);
1152         assertEquals(b.isEqual(b), true);
1153 
1154         assertEquals(a.isAfter(a), false);
1155         assertEquals(b.isAfter(b), false);
1156     }
1157 
1158     @Test(groups={"tck"})
1159     public void test_isBeforeIsAfterIsEqual_instantComparison() {
1160         OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PTWO);
1161         OffsetTime b = OffsetTime.of(10, 30, 59, 0, OFFSET_PONE);  // a is same instant as b
1162         assertEquals(a.isBefore(b), false);
1163         assertEquals(a.isEqual(b), true);
1164         assertEquals(a.isAfter(b), false);
1165 
1166         assertEquals(b.isBefore(a), false);
1167         assertEquals(b.isEqual(a), true);
1168         assertEquals(b.isAfter(a), false);
1169 
1170         assertEquals(a.isBefore(a), false);
1171         assertEquals(b.isBefore(b), false);
1172 
1173         assertEquals(a.isEqual(a), true);
1174         assertEquals(b.isEqual(b), true);
1175 
1176         assertEquals(a.isAfter(a), false);
1177         assertEquals(b.isAfter(b), false);
1178     }
1179 
1180     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1181     public void test_isBefore_null() {
1182         OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
1183         a.isBefore(null);
1184     }
1185 
1186     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1187     public void test_isAfter_null() {
1188         OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
1189         a.isAfter(null);
1190     }
1191 
1192     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1193     public void test_isEqual_null() {
1194         OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
1195         a.isEqual(null);
1196     }
1197 
1198     //-----------------------------------------------------------------------
1199     // equals() / hashCode()
1200     //-----------------------------------------------------------------------
1201     @Test(dataProvider="sampleTimes", groups={"tck"})
1202     public void test_equals_true(int h, int m, int s, int n, ZoneOffset ignored) {
1203         OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE);
1204         OffsetTime b = OffsetTime.of(h, m, s, n, OFFSET_PONE);
1205         assertEquals(a.equals(b), true);
1206         assertEquals(a.hashCode() == b.hashCode(), true);
1207     }
1208     @Test(dataProvider="sampleTimes", groups={"tck"})
1209     public void test_equals_false_hour_differs(int h, int m, int s, int n, ZoneOffset ignored) {
1210         h = (h == 23 ? 22 : h);
1211         OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE);
1212         OffsetTime b = OffsetTime.of(h + 1, m, s, n, OFFSET_PONE);
1213         assertEquals(a.equals(b), false);
1214     }
1215     @Test(dataProvider="sampleTimes", groups={"tck"})
1216     public void test_equals_false_minute_differs(int h, int m, int s, int n, ZoneOffset ignored) {
1217         m = (m == 59 ? 58 : m);
1218         OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE);
1219         OffsetTime b = OffsetTime.of(h, m + 1, s, n, OFFSET_PONE);
1220         assertEquals(a.equals(b), false);
1221     }
1222     @Test(dataProvider="sampleTimes", groups={"tck"})
1223     public void test_equals_false_second_differs(int h, int m, int s, int n, ZoneOffset ignored) {
1224         s = (s == 59 ? 58 : s);
1225         OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE);
1226         OffsetTime b = OffsetTime.of(h, m, s + 1, n, OFFSET_PONE);
1227         assertEquals(a.equals(b), false);
1228     }
1229     @Test(dataProvider="sampleTimes", groups={"tck"})
1230     public void test_equals_false_nano_differs(int h, int m, int s, int n, ZoneOffset ignored) {
1231         n = (n == 999999999 ? 999999998 : n);
1232         OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE);
1233         OffsetTime b = OffsetTime.of(h, m, s, n + 1, OFFSET_PONE);
1234         assertEquals(a.equals(b), false);
1235     }
1236     @Test(dataProvider="sampleTimes", groups={"tck"})
1237     public void test_equals_false_offset_differs(int h, int m, int s, int n, ZoneOffset ignored) {
1238         OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE);
1239         OffsetTime b = OffsetTime.of(h, m, s, n, OFFSET_PTWO);
1240         assertEquals(a.equals(b), false);
1241     }
1242 
1243     @Test(groups={"tck"})
1244     public void test_equals_itself_true() {
1245         assertEquals(TEST_11_30_59_500_PONE.equals(TEST_11_30_59_500_PONE), true);
1246     }
1247 
1248     @Test(groups={"tck"})
1249     public void test_equals_string_false() {
1250         assertEquals(TEST_11_30_59_500_PONE.equals("2007-07-15"), false);
1251     }
1252 
1253     @Test(groups={"tck"})
1254     public void test_equals_null_false() {
1255         assertEquals(TEST_11_30_59_500_PONE.equals(null), false);
1256     }
1257 
1258     //-----------------------------------------------------------------------
1259     // toString()
1260     //-----------------------------------------------------------------------
1261     @DataProvider(name="sampleToString")
1262     Object[][] provider_sampleToString() {
1263         return new Object[][] {
1264             {11, 30, 59, 0, "Z", "11:30:59Z"},
1265             {11, 30, 59, 0, "+01:00", "11:30:59+01:00"},
1266             {11, 30, 59, 999000000, "Z", "11:30:59.999Z"},
1267             {11, 30, 59, 999000000, "+01:00", "11:30:59.999+01:00"},
1268             {11, 30, 59, 999000, "Z", "11:30:59.000999Z"},
1269             {11, 30, 59, 999000, "+01:00", "11:30:59.000999+01:00"},
1270             {11, 30, 59, 999, "Z", "11:30:59.000000999Z"},
1271             {11, 30, 59, 999, "+01:00", "11:30:59.000000999+01:00"},
1272         };
1273     }
1274 
1275     @Test(dataProvider="sampleToString", groups={"tck"})
1276     public void test_toString(int h, int m, int s, int n, String offsetId, String expected) {
1277         OffsetTime t = OffsetTime.of(h, m, s, n, ZoneOffset.of(offsetId));
1278         String str = t.toString();
1279         assertEquals(str, expected);
1280     }
1281 
1282     //-----------------------------------------------------------------------
1283     // toString(DateTimeFormatter)
1284     //-----------------------------------------------------------------------
1285     @Test(groups={"tck"})
1286     public void test_toString_formatter() {
1287         DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s");
1288         String t = OffsetTime.of(11, 30, 0, 0, OFFSET_PONE).toString(f);
1289         assertEquals(t, "11 30 0");
1290     }
1291 
1292     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1293     public void test_toString_formatter_null() {
1294         OffsetTime.of(11, 30, 0, 0, OFFSET_PONE).toString(null);
1295     }
1296 
1297 }