1 /*
   2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * This file is available under and governed by the GNU General Public
  26  * License version 2 only, as published by the Free Software Foundation.
  27  * However, the following notice accompanied the original version of this
  28  * file:
  29  *
  30  * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos
  31  *
  32  * All rights reserved.
  33  *
  34  * Redistribution and use in source and binary forms, with or without
  35  * modification, are permitted provided that the following conditions are met:
  36  *
  37  *  * Redistributions of source code must retain the above copyright notice,
  38  *    this list of conditions and the following disclaimer.
  39  *
  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,
 162             MINUTE_OF_HOUR,
 163             MINUTE_OF_DAY,
 164             CLOCK_HOUR_OF_AMPM,
 165             HOUR_OF_AMPM,
 166             CLOCK_HOUR_OF_DAY,
 167             HOUR_OF_DAY,
 168             AMPM_OF_DAY,
 169             OFFSET_SECONDS,
 170         };
 171         return Arrays.asList(array);
 172     }
 173 
 174     @Override
 175     protected List<TemporalField> invalidFields() {
 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     }
 261 
 262     @Test(groups={"tck"})
 263     public void now_Clock_beforeEpoch() {
 264         for (int i =-1; i >= -(24 * 60 * 60); i--) {
 265             Instant instant = Instant.ofEpochSecond(i, 8);
 266             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 267             OffsetTime test = OffsetTime.now(clock);
 268             assertEquals(test.getHour(), ((i + 24 * 60 * 60) / (60 * 60)) % 24);
 269             assertEquals(test.getMinute(), ((i + 24 * 60 * 60) / 60) % 60);
 270             assertEquals(test.getSecond(), (i + 24 * 60 * 60) % 60);
 271             assertEquals(test.getNano(), 8);
 272             assertEquals(test.getOffset(), ZoneOffset.UTC);
 273         }
 274     }
 275 
 276     @Test(groups={"tck"})
 277     public void now_Clock_offsets() {
 278         Instant base = LocalDateTime.of(1970, 1, 1, 12, 0).toInstant(ZoneOffset.UTC);
 279         for (int i = -9; i < 15; i++) {
 280             ZoneOffset offset = ZoneOffset.ofHours(i);
 281             Clock clock = Clock.fixed(base, offset);
 282             OffsetTime test = OffsetTime.now(clock);
 283             assertEquals(test.getHour(), (12 + i) % 24);
 284             assertEquals(test.getMinute(), 0);
 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);
 356     }
 357 
 358     //-----------------------------------------------------------------------
 359     // ofInstant()
 360     //-----------------------------------------------------------------------
 361     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 362     public void factory_ofInstant_nullInstant() {
 363         OffsetTime.ofInstant((Instant) null, ZoneOffset.UTC);
 364     }
 365 
 366     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 367     public void factory_ofInstant_nullOffset() {
 368         Instant instant = Instant.ofEpochSecond(0L);
 369         OffsetTime.ofInstant(instant, (ZoneOffset) null);
 370     }
 371 
 372     @Test(groups={"tck"})
 373     public void factory_ofInstant_allSecsInDay() {
 374         for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
 375             Instant instant = Instant.ofEpochSecond(i, 8);
 376             OffsetTime test = OffsetTime.ofInstant(instant, ZoneOffset.UTC);
 377             assertEquals(test.getHour(), (i / (60 * 60)) % 24);
 378             assertEquals(test.getMinute(), (i / 60) % 60);
 379             assertEquals(test.getSecond(), i % 60);
 380             assertEquals(test.getNano(), 8);
 381         }
 382     }
 383 
 384     @Test(groups={"tck"})
 385     public void factory_ofInstant_beforeEpoch() {
 386         for (int i =-1; i >= -(24 * 60 * 60); i--) {
 387             Instant instant = Instant.ofEpochSecond(i, 8);
 388             OffsetTime test = OffsetTime.ofInstant(instant, ZoneOffset.UTC);
 389             assertEquals(test.getHour(), ((i + 24 * 60 * 60) / (60 * 60)) % 24);
 390             assertEquals(test.getMinute(), ((i + 24 * 60 * 60) / 60) % 60);
 391             assertEquals(test.getSecond(), (i + 24 * 60 * 60) % 60);
 392             assertEquals(test.getNano(), 8);
 393         }
 394     }
 395 
 396     //-----------------------------------------------------------------------
 397     @Test(groups={"tck"})
 398     public void factory_ofInstant_maxYear() {
 399         OffsetTime test = OffsetTime.ofInstant(Instant.MAX, ZoneOffset.UTC);
 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()
 441     //-----------------------------------------------------------------------
 442     @Test(dataProvider = "sampleToString", groups={"tck"})
 443     public void factory_parse_validText(int h, int m, int s, int n, String offsetId, String parsable) {
 444         OffsetTime t = OffsetTime.parse(parsable);
 445         assertNotNull(t, parsable);
 446         check(t, h, m, s, n, ZoneOffset.of(offsetId));
 447     }
 448 
 449     @DataProvider(name="sampleBadParse")
 450     Object[][] provider_sampleBadParse() {
 451         return new Object[][]{
 452                 {"00;00"},
 453                 {"12-00"},
 454                 {"-01:00"},
 455                 {"00:00:00-09"},
 456                 {"00:00:00,09"},
 457                 {"00:00:abs"},
 458                 {"11"},
 459                 {"11:30"},
 460                 {"11:30+01:00[Europe/Paris]"},
 461         };
 462     }
 463 
 464     @Test(dataProvider = "sampleBadParse", expectedExceptions={DateTimeParseException.class}, groups={"tck"})
 465     public void factory_parse_invalidText(String unparsable) {
 466         OffsetTime.parse(unparsable);
 467     }
 468 
 469     //-----------------------------------------------------------------------s
 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 }