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) 2007-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;
  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.SECOND_OF_DAY;
  76 import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
  77 import static java.time.temporal.ChronoUnit.DAYS;
  78 import static java.time.temporal.ChronoUnit.FOREVER;
  79 import static java.time.temporal.ChronoUnit.HOURS;
  80 import static java.time.temporal.ChronoUnit.MICROS;
  81 import static java.time.temporal.ChronoUnit.MILLIS;
  82 import static java.time.temporal.ChronoUnit.MINUTES;
  83 import static java.time.temporal.ChronoUnit.MONTHS;
  84 import static java.time.temporal.ChronoUnit.NANOS;
  85 import static java.time.temporal.ChronoUnit.SECONDS;
  86 import static java.time.temporal.ChronoUnit.WEEKS;
  87 import static java.time.temporal.ChronoUnit.YEARS;
  88 import static org.testng.Assert.assertEquals;
  89 import static org.testng.Assert.assertNotNull;
  90 import static org.testng.Assert.assertTrue;
  91 import static org.testng.Assert.fail;
  92 
  93 import java.io.ByteArrayOutputStream;
  94 import java.io.DataOutputStream;
  95 import java.io.IOException;
  96 import java.util.ArrayList;
  97 import java.util.Arrays;
  98 import java.util.EnumSet;
  99 import java.util.Iterator;
 100 import java.util.List;
 101 
 102 import java.time.Clock;
 103 import java.time.DateTimeException;
 104 import java.time.Instant;
 105 import java.time.LocalDate;
 106 import java.time.LocalDateTime;
 107 import java.time.LocalTime;
 108 import java.time.Period;
 109 import java.time.ZoneId;
 110 import java.time.ZoneOffset;
 111 import java.time.format.DateTimeFormatter;
 112 import java.time.format.DateTimeFormatters;
 113 import java.time.format.DateTimeParseException;
 114 import java.time.temporal.ChronoField;
 115 import java.time.temporal.ChronoUnit;
 116 import java.time.temporal.JulianFields;
 117 import java.time.temporal.OffsetTime;
 118 import java.time.temporal.Queries;
 119 import java.time.temporal.Temporal;
 120 import java.time.temporal.TemporalAccessor;
 121 import java.time.temporal.TemporalAdder;
 122 import java.time.temporal.TemporalAdjuster;
 123 import java.time.temporal.TemporalField;
 124 import java.time.temporal.TemporalSubtractor;
 125 import java.time.temporal.TemporalUnit;
 126 
 127 import org.testng.annotations.BeforeMethod;
 128 import org.testng.annotations.DataProvider;
 129 import org.testng.annotations.Test;
 130 import test.java.time.MockSimplePeriod;
 131 
 132 /**
 133  * Test LocalTime.
 134  */
 135 @Test
 136 public class TCKLocalTime extends AbstractDateTimeTest {
 137 
 138     private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2);
 139 
 140     private LocalTime TEST_12_30_40_987654321;
 141 
 142     private static final TemporalUnit[] INVALID_UNITS;
 143     static {
 144         EnumSet<ChronoUnit> set = EnumSet.range(WEEKS, FOREVER);
 145         INVALID_UNITS = (TemporalUnit[]) set.toArray(new TemporalUnit[set.size()]);
 146     }
 147 
 148     @BeforeMethod(groups={"tck","implementation"})
 149     public void setUp() {
 150         TEST_12_30_40_987654321 = LocalTime.of(12, 30, 40, 987654321);
 151     }
 152 
 153     //-----------------------------------------------------------------------
 154     @Override
 155     protected List<TemporalAccessor> samples() {
 156         TemporalAccessor[] array = {TEST_12_30_40_987654321, LocalTime.MIN, LocalTime.MAX, LocalTime.MIDNIGHT, LocalTime.NOON};
 157         return Arrays.asList(array);
 158     }
 159 
 160     @Override
 161     protected List<TemporalField> validFields() {
 162         TemporalField[] array = {
 163             NANO_OF_SECOND,
 164             NANO_OF_DAY,
 165             MICRO_OF_SECOND,
 166             MICRO_OF_DAY,
 167             MILLI_OF_SECOND,
 168             MILLI_OF_DAY,
 169             SECOND_OF_MINUTE,
 170             SECOND_OF_DAY,
 171             MINUTE_OF_HOUR,
 172             MINUTE_OF_DAY,
 173             CLOCK_HOUR_OF_AMPM,
 174             HOUR_OF_AMPM,
 175             CLOCK_HOUR_OF_DAY,
 176             HOUR_OF_DAY,
 177             AMPM_OF_DAY,
 178         };
 179         return Arrays.asList(array);
 180     }
 181 
 182     @Override
 183     protected List<TemporalField> invalidFields() {
 184         List<TemporalField> list = new ArrayList<>(Arrays.<TemporalField>asList(ChronoField.values()));
 185         list.removeAll(validFields());
 186         list.add(JulianFields.JULIAN_DAY);
 187         list.add(JulianFields.MODIFIED_JULIAN_DAY);
 188         list.add(JulianFields.RATA_DIE);
 189         return list;
 190     }
 191 
 192     //-----------------------------------------------------------------------
 193     @Test
 194     public void test_serialization() throws Exception {
 195         assertSerializable(TEST_12_30_40_987654321);
 196         assertSerializable(LocalTime.MIN);
 197         assertSerializable(LocalTime.MAX);
 198     }
 199 
 200     @Test
 201     public void test_serialization_format_h() throws Exception {
 202         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 203         try (DataOutputStream dos = new DataOutputStream(baos) ) {
 204             dos.writeByte(4);
 205             dos.writeByte(-1 - 22);
 206         }
 207         byte[] bytes = baos.toByteArray();
 208         assertSerializedBySer(LocalTime.of(22, 0), bytes);
 209     }
 210 
 211     @Test
 212     public void test_serialization_format_hm() throws Exception {
 213         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 214         try (DataOutputStream dos = new DataOutputStream(baos) ) {
 215             dos.writeByte(4);
 216             dos.writeByte(22);
 217             dos.writeByte(-1 - 17);
 218         }
 219         byte[] bytes = baos.toByteArray();
 220         assertSerializedBySer(LocalTime.of(22, 17), bytes);
 221     }
 222 
 223     @Test
 224     public void test_serialization_format_hms() throws Exception {
 225         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 226         try (DataOutputStream dos = new DataOutputStream(baos) ) {
 227             dos.writeByte(4);
 228             dos.writeByte(22);
 229             dos.writeByte(17);
 230             dos.writeByte(-1 - 59);
 231         }
 232         byte[] bytes = baos.toByteArray();
 233         assertSerializedBySer(LocalTime.of(22, 17, 59), bytes);
 234     }
 235 
 236     @Test
 237     public void test_serialization_format_hmsn() throws Exception {
 238         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 239         try (DataOutputStream dos = new DataOutputStream(baos) ) {
 240             dos.writeByte(4);
 241             dos.writeByte(22);
 242             dos.writeByte(17);
 243             dos.writeByte(59);
 244             dos.writeInt(459_000_000);
 245         }
 246         byte[] bytes = baos.toByteArray();
 247         assertSerializedBySer(LocalTime.of(22, 17, 59, 459_000_000), bytes);
 248     }
 249 
 250     //-----------------------------------------------------------------------
 251     private void check(LocalTime test, int h, int m, int s, int n) {
 252         assertEquals(test.getHour(), h);
 253         assertEquals(test.getMinute(), m);
 254         assertEquals(test.getSecond(), s);
 255         assertEquals(test.getNano(), n);
 256         assertEquals(test, test);
 257         assertEquals(test.hashCode(), test.hashCode());
 258         assertEquals(LocalTime.of(h, m, s, n), test);
 259     }
 260 
 261     //-----------------------------------------------------------------------
 262     // constants
 263     //-----------------------------------------------------------------------
 264     @Test(groups={"tck","implementation"})
 265     public void constant_MIDNIGHT() {
 266         check(LocalTime.MIDNIGHT, 0, 0, 0, 0);
 267     }
 268 
 269     @Test
 270     public void constant_MIDDAY() {
 271         check(LocalTime.NOON, 12, 0, 0, 0);
 272     }
 273 
 274     @Test
 275     public void constant_MIN() {
 276         check(LocalTime.MIN, 0, 0, 0, 0);
 277     }
 278 
 279     @Test
 280     public void constant_MAX() {
 281         check(LocalTime.MAX, 23, 59, 59, 999999999);
 282     }
 283 
 284     //-----------------------------------------------------------------------
 285     // now()
 286     //-----------------------------------------------------------------------
 287     @Test(groups={"tck"})
 288     public void now() {
 289         LocalTime expected = LocalTime.now(Clock.systemDefaultZone());
 290         LocalTime test = LocalTime.now();
 291         long diff = Math.abs(test.toNanoOfDay() - expected.toNanoOfDay());
 292         assertTrue(diff < 100000000);  // less than 0.1 secs
 293     }
 294 
 295     //-----------------------------------------------------------------------
 296     // now(ZoneId)
 297     //-----------------------------------------------------------------------
 298     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 299     public void now_ZoneId_nullZoneId() {
 300         LocalTime.now((ZoneId) null);
 301     }
 302 
 303     @Test(groups={"tck"})
 304     public void now_ZoneId() {
 305         ZoneId zone = ZoneId.of("UTC+01:02:03");
 306         LocalTime expected = LocalTime.now(Clock.system(zone));
 307         LocalTime test = LocalTime.now(zone);
 308         for (int i = 0; i < 100; i++) {
 309             if (expected.equals(test)) {
 310                 return;
 311             }
 312             expected = LocalTime.now(Clock.system(zone));
 313             test = LocalTime.now(zone);
 314         }
 315         assertEquals(test, expected);
 316     }
 317 
 318     //-----------------------------------------------------------------------
 319     // now(Clock)
 320     //-----------------------------------------------------------------------
 321     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 322     public void now_Clock_nullClock() {
 323         LocalTime.now((Clock) null);
 324     }
 325 
 326     @Test(groups={"tck"})
 327     public void now_Clock_allSecsInDay() {
 328         for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
 329             Instant instant = Instant.ofEpochSecond(i, 8);
 330             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 331             LocalTime test = LocalTime.now(clock);
 332             assertEquals(test.getHour(), (i / (60 * 60)) % 24);
 333             assertEquals(test.getMinute(), (i / 60) % 60);
 334             assertEquals(test.getSecond(), i % 60);
 335             assertEquals(test.getNano(), 8);
 336         }
 337     }
 338 
 339     @Test(groups={"tck"})
 340     public void now_Clock_beforeEpoch() {
 341         for (int i =-1; i >= -(24 * 60 * 60); i--) {
 342             Instant instant = Instant.ofEpochSecond(i, 8);
 343             Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
 344             LocalTime test = LocalTime.now(clock);
 345             assertEquals(test.getHour(), ((i + 24 * 60 * 60) / (60 * 60)) % 24);
 346             assertEquals(test.getMinute(), ((i + 24 * 60 * 60) / 60) % 60);
 347             assertEquals(test.getSecond(), (i + 24 * 60 * 60) % 60);
 348             assertEquals(test.getNano(), 8);
 349         }
 350     }
 351 
 352     //-----------------------------------------------------------------------
 353     @Test(groups={"tck"})
 354     public void now_Clock_max() {
 355         Clock clock = Clock.fixed(Instant.MAX, ZoneOffset.UTC);
 356         LocalTime test = LocalTime.now(clock);
 357         assertEquals(test.getHour(), 23);
 358         assertEquals(test.getMinute(), 59);
 359         assertEquals(test.getSecond(), 59);
 360         assertEquals(test.getNano(), 999_999_999);
 361     }
 362 
 363     @Test(groups={"tck"})
 364     public void now_Clock_min() {
 365         Clock clock = Clock.fixed(Instant.MIN, ZoneOffset.UTC);
 366         LocalTime test = LocalTime.now(clock);
 367         assertEquals(test.getHour(), 0);
 368         assertEquals(test.getMinute(), 0);
 369         assertEquals(test.getSecond(), 0);
 370         assertEquals(test.getNano(), 0);
 371     }
 372 
 373     //-----------------------------------------------------------------------
 374     // of() factories
 375     //-----------------------------------------------------------------------
 376     @Test(groups={"tck"})
 377     public void factory_time_2ints() {
 378         LocalTime test = LocalTime.of(12, 30);
 379         check(test, 12, 30, 0, 0);
 380     }
 381 
 382     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 383     public void factory_time_2ints_hourTooLow() {
 384         LocalTime.of(-1, 0);
 385     }
 386 
 387     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 388     public void factory_time_2ints_hourTooHigh() {
 389         LocalTime.of(24, 0);
 390     }
 391 
 392     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 393     public void factory_time_2ints_minuteTooLow() {
 394         LocalTime.of(0, -1);
 395     }
 396 
 397     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 398     public void factory_time_2ints_minuteTooHigh() {
 399         LocalTime.of(0, 60);
 400     }
 401 
 402     //-----------------------------------------------------------------------
 403     @Test(groups={"tck"})
 404     public void factory_time_3ints() {
 405         LocalTime test = LocalTime.of(12, 30, 40);
 406         check(test, 12, 30, 40, 0);
 407     }
 408 
 409     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 410     public void factory_time_3ints_hourTooLow() {
 411         LocalTime.of(-1, 0, 0);
 412     }
 413 
 414     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 415     public void factory_time_3ints_hourTooHigh() {
 416         LocalTime.of(24, 0, 0);
 417     }
 418 
 419     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 420     public void factory_time_3ints_minuteTooLow() {
 421         LocalTime.of(0, -1, 0);
 422     }
 423 
 424     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 425     public void factory_time_3ints_minuteTooHigh() {
 426         LocalTime.of(0, 60, 0);
 427     }
 428 
 429     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 430     public void factory_time_3ints_secondTooLow() {
 431         LocalTime.of(0, 0, -1);
 432     }
 433 
 434     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 435     public void factory_time_3ints_secondTooHigh() {
 436         LocalTime.of(0, 0, 60);
 437     }
 438 
 439     //-----------------------------------------------------------------------
 440     @Test(groups={"tck"})
 441     public void factory_time_4ints() {
 442         LocalTime test = LocalTime.of(12, 30, 40, 987654321);
 443         check(test, 12, 30, 40, 987654321);
 444         test = LocalTime.of(12, 0, 40, 987654321);
 445         check(test, 12, 0, 40, 987654321);
 446     }
 447 
 448     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 449     public void factory_time_4ints_hourTooLow() {
 450         LocalTime.of(-1, 0, 0, 0);
 451     }
 452 
 453     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 454     public void factory_time_4ints_hourTooHigh() {
 455         LocalTime.of(24, 0, 0, 0);
 456     }
 457 
 458     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 459     public void factory_time_4ints_minuteTooLow() {
 460         LocalTime.of(0, -1, 0, 0);
 461     }
 462 
 463     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 464     public void factory_time_4ints_minuteTooHigh() {
 465         LocalTime.of(0, 60, 0, 0);
 466     }
 467 
 468     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 469     public void factory_time_4ints_secondTooLow() {
 470         LocalTime.of(0, 0, -1, 0);
 471     }
 472 
 473     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 474     public void factory_time_4ints_secondTooHigh() {
 475         LocalTime.of(0, 0, 60, 0);
 476     }
 477 
 478     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 479     public void factory_time_4ints_nanoTooLow() {
 480         LocalTime.of(0, 0, 0, -1);
 481     }
 482 
 483     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 484     public void factory_time_4ints_nanoTooHigh() {
 485         LocalTime.of(0, 0, 0, 1000000000);
 486     }
 487 
 488     //-----------------------------------------------------------------------
 489     // ofSecondOfDay(long)
 490     //-----------------------------------------------------------------------
 491     @Test(groups={"tck"})
 492     public void factory_ofSecondOfDay() {
 493         LocalTime localTime = LocalTime.ofSecondOfDay(2 * 60 * 60 + 17 * 60 + 23);
 494         check(localTime, 2, 17, 23, 0);
 495     }
 496 
 497     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 498     public void factory_ofSecondOfDay_tooLow() {
 499         LocalTime.ofSecondOfDay(-1);
 500     }
 501 
 502     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 503     public void factory_ofSecondOfDay_tooHigh() {
 504         LocalTime.ofSecondOfDay(24 * 60 * 60);
 505     }
 506 
 507     //-----------------------------------------------------------------------
 508     // ofSecondOfDay(long, int)
 509     //-----------------------------------------------------------------------
 510     @Test(groups={"tck"})
 511     public void factory_ofSecondOfDay_long_int() {
 512         LocalTime localTime = LocalTime.ofSecondOfDay(2 * 60 * 60 + 17 * 60 + 23, 987);
 513         check(localTime, 2, 17, 23, 987);
 514     }
 515 
 516     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 517     public void factory_ofSecondOfDay_long_int_tooLowSecs() {
 518         LocalTime.ofSecondOfDay(-1, 0);
 519     }
 520 
 521     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 522     public void factory_ofSecondOfDay_long_int_tooHighSecs() {
 523         LocalTime.ofSecondOfDay(24 * 60 * 60, 0);
 524     }
 525 
 526     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 527     public void factory_ofSecondOfDay_long_int_tooLowNanos() {
 528         LocalTime.ofSecondOfDay(0, -1);
 529     }
 530 
 531     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 532     public void factory_ofSecondOfDay_long_int_tooHighNanos() {
 533         LocalTime.ofSecondOfDay(0, 1000000000);
 534     }
 535 
 536     //-----------------------------------------------------------------------
 537     // ofNanoOfDay(long)
 538     //-----------------------------------------------------------------------
 539     @Test(groups={"tck"})
 540     public void factory_ofNanoOfDay() {
 541         LocalTime localTime = LocalTime.ofNanoOfDay(60 * 60 * 1000000000L + 17);
 542         check(localTime, 1, 0, 0, 17);
 543     }
 544 
 545     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 546     public void factory_ofNanoOfDay_tooLow() {
 547         LocalTime.ofNanoOfDay(-1);
 548     }
 549 
 550     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 551     public void factory_ofNanoOfDay_tooHigh() {
 552         LocalTime.ofNanoOfDay(24 * 60 * 60 * 1000000000L);
 553     }
 554 
 555     //-----------------------------------------------------------------------
 556     // from()
 557     //-----------------------------------------------------------------------
 558     @Test(groups={"tck"})
 559     public void factory_from_TemporalAccessor() {
 560         assertEquals(LocalTime.from(LocalTime.of(17, 30)), LocalTime.of(17, 30));
 561         assertEquals(LocalTime.from(LocalDateTime.of(2012, 5, 1, 17, 30)), LocalTime.of(17, 30));
 562     }
 563 
 564     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 565     public void factory_from_TemporalAccessor_invalid_noDerive() {
 566         LocalTime.from(LocalDate.of(2007, 7, 15));
 567     }
 568 
 569     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 570     public void factory_from_TemporalAccessor_null() {
 571         LocalTime.from((TemporalAccessor) null);
 572     }
 573 
 574     //-----------------------------------------------------------------------
 575     // parse()
 576     //-----------------------------------------------------------------------
 577     @Test(dataProvider = "sampleToString", groups={"tck"})
 578     public void factory_parse_validText(int h, int m, int s, int n, String parsable) {
 579         LocalTime t = LocalTime.parse(parsable);
 580         assertNotNull(t, parsable);
 581         assertEquals(t.getHour(), h);
 582         assertEquals(t.getMinute(), m);
 583         assertEquals(t.getSecond(), s);
 584         assertEquals(t.getNano(), n);
 585     }
 586 
 587     @DataProvider(name="sampleBadParse")
 588     Object[][] provider_sampleBadParse() {
 589         return new Object[][]{
 590                 {"00;00"},
 591                 {"12-00"},
 592                 {"-01:00"},
 593                 {"00:00:00-09"},
 594                 {"00:00:00,09"},
 595                 {"00:00:abs"},
 596                 {"11"},
 597                 {"11:30+01:00"},
 598                 {"11:30+01:00[Europe/Paris]"},
 599         };
 600     }
 601 
 602     @Test(dataProvider = "sampleBadParse", expectedExceptions={DateTimeParseException.class}, groups={"tck"})
 603     public void factory_parse_invalidText(String unparsable) {
 604         LocalTime.parse(unparsable);
 605     }
 606 
 607     //-----------------------------------------------------------------------s
 608     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 609     public void factory_parse_illegalHour() {
 610         LocalTime.parse("25:00");
 611     }
 612 
 613     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 614     public void factory_parse_illegalMinute() {
 615         LocalTime.parse("12:60");
 616     }
 617 
 618     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 619     public void factory_parse_illegalSecond() {
 620         LocalTime.parse("12:12:60");
 621     }
 622 
 623     //-----------------------------------------------------------------------s
 624     @Test(expectedExceptions = {NullPointerException.class}, groups={"tck"})
 625     public void factory_parse_nullTest() {
 626         LocalTime.parse((String) null);
 627     }
 628 
 629     //-----------------------------------------------------------------------
 630     // parse(DateTimeFormatter)
 631     //-----------------------------------------------------------------------
 632     @Test(groups={"tck"})
 633     public void factory_parse_formatter() {
 634         DateTimeFormatter f = DateTimeFormatters.pattern("H m s");
 635         LocalTime test = LocalTime.parse("14 30 40", f);
 636         assertEquals(test, LocalTime.of(14, 30, 40));
 637     }
 638 
 639     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 640     public void factory_parse_formatter_nullText() {
 641         DateTimeFormatter f = DateTimeFormatters.pattern("H m s");
 642         LocalTime.parse((String) null, f);
 643     }
 644 
 645     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 646     public void factory_parse_formatter_nullFormatter() {
 647         LocalTime.parse("ANY", null);
 648     }
 649 
 650     //-----------------------------------------------------------------------
 651     // get(TemporalField)
 652     //-----------------------------------------------------------------------
 653     @Test
 654     public void test_get_TemporalField() {
 655         LocalTime test = TEST_12_30_40_987654321;
 656         assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12);
 657         assertEquals(test.get(ChronoField.MINUTE_OF_HOUR), 30);
 658         assertEquals(test.get(ChronoField.SECOND_OF_MINUTE), 40);
 659         assertEquals(test.get(ChronoField.NANO_OF_SECOND), 987654321);
 660 
 661         assertEquals(test.get(ChronoField.SECOND_OF_DAY), 12 * 3600 + 30 * 60 + 40);
 662         assertEquals(test.get(ChronoField.MINUTE_OF_DAY), 12 * 60 + 30);
 663         assertEquals(test.get(ChronoField.HOUR_OF_AMPM), 0);
 664         assertEquals(test.get(ChronoField.CLOCK_HOUR_OF_AMPM), 12);
 665         assertEquals(test.get(ChronoField.CLOCK_HOUR_OF_DAY), 12);
 666         assertEquals(test.get(ChronoField.AMPM_OF_DAY), 1);
 667     }
 668 
 669     @Test
 670     public void test_getLong_TemporalField() {
 671         LocalTime test = TEST_12_30_40_987654321;
 672         assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12);
 673         assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30);
 674         assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40);
 675         assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321);
 676 
 677         assertEquals(test.getLong(ChronoField.SECOND_OF_DAY), 12 * 3600 + 30 * 60 + 40);
 678         assertEquals(test.getLong(ChronoField.MINUTE_OF_DAY), 12 * 60 + 30);
 679         assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0);
 680         assertEquals(test.getLong(ChronoField.CLOCK_HOUR_OF_AMPM), 12);
 681         assertEquals(test.getLong(ChronoField.CLOCK_HOUR_OF_DAY), 12);
 682         assertEquals(test.getLong(ChronoField.AMPM_OF_DAY), 1);
 683     }
 684 
 685     //-----------------------------------------------------------------------
 686     // query(TemporalQuery)
 687     //-----------------------------------------------------------------------
 688     @Test
 689     public void test_query_chrono() {
 690         assertEquals(TEST_12_30_40_987654321.query(Queries.chrono()), null);
 691         assertEquals(Queries.chrono().queryFrom(TEST_12_30_40_987654321), null);
 692     }
 693 
 694     @Test
 695     public void test_query_zoneId() {
 696         assertEquals(TEST_12_30_40_987654321.query(Queries.zoneId()), null);
 697         assertEquals(Queries.zoneId().queryFrom(TEST_12_30_40_987654321), null);
 698     }
 699 
 700     @Test
 701     public void test_query_precision() {
 702         assertEquals(TEST_12_30_40_987654321.query(Queries.precision()), NANOS);
 703         assertEquals(Queries.precision().queryFrom(TEST_12_30_40_987654321), NANOS);
 704     }
 705 
 706     @Test
 707     public void test_query_offset() {
 708         assertEquals(TEST_12_30_40_987654321.query(Queries.offset()), null);
 709         assertEquals(Queries.offset().queryFrom(TEST_12_30_40_987654321), null);
 710     }
 711 
 712     @Test
 713     public void test_query_zone() {
 714         assertEquals(TEST_12_30_40_987654321.query(Queries.zone()), null);
 715         assertEquals(Queries.zone().queryFrom(TEST_12_30_40_987654321), null);
 716     }
 717 
 718     @Test(expectedExceptions=NullPointerException.class)
 719     public void test_query_null() {
 720         TEST_12_30_40_987654321.query(null);
 721     }
 722 
 723     //-----------------------------------------------------------------------
 724     // get*()
 725     //-----------------------------------------------------------------------
 726     @DataProvider(name="sampleTimes")
 727     Object[][] provider_sampleTimes() {
 728         return new Object[][] {
 729             {0, 0, 0, 0},
 730             {0, 0, 0, 1},
 731             {0, 0, 1, 0},
 732             {0, 0, 1, 1},
 733             {0, 1, 0, 0},
 734             {0, 1, 0, 1},
 735             {0, 1, 1, 0},
 736             {0, 1, 1, 1},
 737             {1, 0, 0, 0},
 738             {1, 0, 0, 1},
 739             {1, 0, 1, 0},
 740             {1, 0, 1, 1},
 741             {1, 1, 0, 0},
 742             {1, 1, 0, 1},
 743             {1, 1, 1, 0},
 744             {1, 1, 1, 1},
 745         };
 746     }
 747 
 748     //-----------------------------------------------------------------------
 749     @Test(dataProvider="sampleTimes", groups={"tck"})
 750     public void test_get(int h, int m, int s, int ns) {
 751         LocalTime a = LocalTime.of(h, m, s, ns);
 752         assertEquals(a.getHour(), h);
 753         assertEquals(a.getMinute(), m);
 754         assertEquals(a.getSecond(), s);
 755         assertEquals(a.getNano(), ns);
 756     }
 757 
 758     //-----------------------------------------------------------------------
 759     // with()
 760     //-----------------------------------------------------------------------
 761     @Test(groups={"tck"})
 762     public void test_with_adjustment() {
 763         final LocalTime sample = LocalTime.of(23, 5);
 764         TemporalAdjuster adjuster = new TemporalAdjuster() {
 765             @Override
 766             public Temporal adjustInto(Temporal dateTime) {
 767                 return sample;
 768             }
 769         };
 770         assertEquals(TEST_12_30_40_987654321.with(adjuster), sample);
 771     }
 772 
 773     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 774     public void test_with_adjustment_null() {
 775         TEST_12_30_40_987654321.with((TemporalAdjuster) null);
 776     }
 777 
 778     //-----------------------------------------------------------------------
 779     // withHour()
 780     //-----------------------------------------------------------------------
 781     @Test(groups={"tck"})
 782     public void test_withHour_normal() {
 783         LocalTime t = TEST_12_30_40_987654321;
 784         for (int i = 0; i < 24; i++) {
 785             t = t.withHour(i);
 786             assertEquals(t.getHour(), i);
 787         }
 788     }
 789 
 790     @Test(groups={"tck"})
 791     public void test_withHour_noChange_equal() {
 792         LocalTime t = TEST_12_30_40_987654321.withHour(12);
 793         assertEquals(t, TEST_12_30_40_987654321);
 794     }
 795 
 796     @Test(groups={"tck"})
 797     public void test_withHour_toMidnight_equal() {
 798         LocalTime t = LocalTime.of(1, 0).withHour(0);
 799         assertEquals(t, LocalTime.MIDNIGHT);
 800     }
 801 
 802     @Test(groups={"tck"})
 803     public void test_withHour_toMidday_equal() {
 804         LocalTime t = LocalTime.of(1, 0).withHour(12);
 805         assertEquals(t, LocalTime.NOON);
 806     }
 807 
 808     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 809     public void test_withHour_hourTooLow() {
 810         TEST_12_30_40_987654321.withHour(-1);
 811     }
 812 
 813     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 814     public void test_withHour_hourTooHigh() {
 815         TEST_12_30_40_987654321.withHour(24);
 816     }
 817 
 818     //-----------------------------------------------------------------------
 819     // withMinute()
 820     //-----------------------------------------------------------------------
 821     @Test(groups={"tck"})
 822     public void test_withMinute_normal() {
 823         LocalTime t = TEST_12_30_40_987654321;
 824         for (int i = 0; i < 60; i++) {
 825             t = t.withMinute(i);
 826             assertEquals(t.getMinute(), i);
 827         }
 828     }
 829 
 830     @Test(groups={"tck"})
 831     public void test_withMinute_noChange_equal() {
 832         LocalTime t = TEST_12_30_40_987654321.withMinute(30);
 833         assertEquals(t, TEST_12_30_40_987654321);
 834     }
 835 
 836     @Test(groups={"tck"})
 837     public void test_withMinute_toMidnight_equal() {
 838         LocalTime t = LocalTime.of(0, 1).withMinute(0);
 839         assertEquals(t, LocalTime.MIDNIGHT);
 840     }
 841 
 842     @Test(groups={"tck"})
 843     public void test_withMinute_toMidday_equals() {
 844         LocalTime t = LocalTime.of(12, 1).withMinute(0);
 845         assertEquals(t, LocalTime.NOON);
 846     }
 847 
 848     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 849     public void test_withMinute_minuteTooLow() {
 850         TEST_12_30_40_987654321.withMinute(-1);
 851     }
 852 
 853     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 854     public void test_withMinute_minuteTooHigh() {
 855         TEST_12_30_40_987654321.withMinute(60);
 856     }
 857 
 858     //-----------------------------------------------------------------------
 859     // withSecond()
 860     //-----------------------------------------------------------------------
 861     @Test(groups={"tck"})
 862     public void test_withSecond_normal() {
 863         LocalTime t = TEST_12_30_40_987654321;
 864         for (int i = 0; i < 60; i++) {
 865             t = t.withSecond(i);
 866             assertEquals(t.getSecond(), i);
 867         }
 868     }
 869 
 870     @Test(groups={"tck"})
 871     public void test_withSecond_noChange_equal() {
 872         LocalTime t = TEST_12_30_40_987654321.withSecond(40);
 873         assertEquals(t, TEST_12_30_40_987654321);
 874     }
 875 
 876     @Test(groups={"tck"})
 877     public void test_withSecond_toMidnight_equal() {
 878         LocalTime t = LocalTime.of(0, 0, 1).withSecond(0);
 879         assertEquals(t, LocalTime.MIDNIGHT);
 880     }
 881 
 882     @Test(groups={"tck"})
 883     public void test_withSecond_toMidday_equal() {
 884         LocalTime t = LocalTime.of(12, 0, 1).withSecond(0);
 885         assertEquals(t, LocalTime.NOON);
 886     }
 887 
 888     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 889     public void test_withSecond_secondTooLow() {
 890         TEST_12_30_40_987654321.withSecond(-1);
 891     }
 892 
 893     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 894     public void test_withSecond_secondTooHigh() {
 895         TEST_12_30_40_987654321.withSecond(60);
 896     }
 897 
 898     //-----------------------------------------------------------------------
 899     // withNano()
 900     //-----------------------------------------------------------------------
 901     @Test(groups={"tck"})
 902     public void test_withNanoOfSecond_normal() {
 903         LocalTime t = TEST_12_30_40_987654321;
 904         t = t.withNano(1);
 905         assertEquals(t.getNano(), 1);
 906         t = t.withNano(10);
 907         assertEquals(t.getNano(), 10);
 908         t = t.withNano(100);
 909         assertEquals(t.getNano(), 100);
 910         t = t.withNano(999999999);
 911         assertEquals(t.getNano(), 999999999);
 912     }
 913 
 914     @Test(groups={"tck"})
 915     public void test_withNanoOfSecond_noChange_equal() {
 916         LocalTime t = TEST_12_30_40_987654321.withNano(987654321);
 917         assertEquals(t, TEST_12_30_40_987654321);
 918     }
 919 
 920     @Test(groups={"tck"})
 921     public void test_withNanoOfSecond_toMidnight_equal() {
 922         LocalTime t = LocalTime.of(0, 0, 0, 1).withNano(0);
 923         assertEquals(t, LocalTime.MIDNIGHT);
 924     }
 925 
 926     @Test(groups={"tck"})
 927     public void test_withNanoOfSecond_toMidday_equal() {
 928         LocalTime t = LocalTime.of(12, 0, 0, 1).withNano(0);
 929         assertEquals(t, LocalTime.NOON);
 930     }
 931 
 932     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 933     public void test_withNanoOfSecond_nanoTooLow() {
 934         TEST_12_30_40_987654321.withNano(-1);
 935     }
 936 
 937     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 938     public void test_withNanoOfSecond_nanoTooHigh() {
 939         TEST_12_30_40_987654321.withNano(1000000000);
 940     }
 941 
 942     //-----------------------------------------------------------------------
 943     // truncated(TemporalUnit)
 944     //-----------------------------------------------------------------------
 945     @DataProvider(name="truncatedToValid")
 946     Object[][] data_truncatedToValid() {
 947         return new Object[][] {
 948             {LocalTime.of(1, 2, 3, 123_456_789), NANOS, LocalTime.of(1, 2, 3, 123_456_789)},
 949             {LocalTime.of(1, 2, 3, 123_456_789), MICROS, LocalTime.of(1, 2, 3, 123_456_000)},
 950             {LocalTime.of(1, 2, 3, 123_456_789), MILLIS, LocalTime.of(1, 2, 3, 1230_00_000)},
 951             {LocalTime.of(1, 2, 3, 123_456_789), SECONDS, LocalTime.of(1, 2, 3)},
 952             {LocalTime.of(1, 2, 3, 123_456_789), MINUTES, LocalTime.of(1, 2)},
 953             {LocalTime.of(1, 2, 3, 123_456_789), HOURS, LocalTime.of(1, 0)},
 954             {LocalTime.of(1, 2, 3, 123_456_789), DAYS, LocalTime.MIDNIGHT},
 955         };
 956     }
 957 
 958     @Test(groups={"tck"}, dataProvider="truncatedToValid")
 959     public void test_truncatedTo_valid(LocalTime input, TemporalUnit unit, LocalTime expected) {
 960         assertEquals(input.truncatedTo(unit), expected);
 961     }
 962 
 963     @DataProvider(name="truncatedToInvalid")
 964     Object[][] data_truncatedToInvalid() {
 965         return new Object[][] {
 966             {LocalTime.of(1, 2, 3, 123_456_789), WEEKS},
 967             {LocalTime.of(1, 2, 3, 123_456_789), MONTHS},
 968             {LocalTime.of(1, 2, 3, 123_456_789), YEARS},
 969         };
 970     }
 971 
 972     @Test(groups={"tck"}, dataProvider="truncatedToInvalid", expectedExceptions=DateTimeException.class)
 973     public void test_truncatedTo_invalid(LocalTime input, TemporalUnit unit) {
 974         input.truncatedTo(unit);
 975     }
 976 
 977     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 978     public void test_truncatedTo_null() {
 979         TEST_12_30_40_987654321.truncatedTo(null);
 980     }
 981 
 982     //-----------------------------------------------------------------------
 983     // plus(PlusAdjuster)
 984     //-----------------------------------------------------------------------
 985     @Test(groups={"tck"})
 986     public void test_plus_Adjuster_positiveHours() {
 987         TemporalAdder period = MockSimplePeriod.of(7, ChronoUnit.HOURS);
 988         LocalTime t = TEST_12_30_40_987654321.plus(period);
 989         assertEquals(t, LocalTime.of(19, 30, 40, 987654321));
 990     }
 991 
 992     @Test(groups={"tck"})
 993     public void test_plus_Adjuster_negativeMinutes() {
 994         TemporalAdder period = MockSimplePeriod.of(-25, ChronoUnit.MINUTES);
 995         LocalTime t = TEST_12_30_40_987654321.plus(period);
 996         assertEquals(t, LocalTime.of(12, 5, 40, 987654321));
 997     }
 998 
 999     @Test(groups={"tck"})
1000     public void test_plus_Adjuster_zero() {
1001         TemporalAdder period = Period.ZERO;
1002         LocalTime t = TEST_12_30_40_987654321.plus(period);
1003         assertEquals(t, TEST_12_30_40_987654321);
1004     }
1005 
1006     @Test(groups={"tck"})
1007     public void test_plus_Adjuster_wrap() {
1008         TemporalAdder p = Period.ofTime(1, 0, 0);
1009         LocalTime t = LocalTime.of(23, 30).plus(p);
1010         assertEquals(t, LocalTime.of(0, 30));
1011     }
1012 
1013     @Test(groups={"tck"}, expectedExceptions=DateTimeException.class)
1014     public void test_plus_Adjuster_dateNotAllowed() {
1015         TemporalAdder period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
1016         TEST_12_30_40_987654321.plus(period);
1017     }
1018 
1019     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1020     public void test_plus_Adjuster_null() {
1021         TEST_12_30_40_987654321.plus((TemporalAdder) null);
1022     }
1023 
1024     //-----------------------------------------------------------------------
1025     // plus(long,TemporalUnit)
1026     //-----------------------------------------------------------------------
1027     @Test(groups={"tck"})
1028     public void test_plus_longTemporalUnit_positiveHours() {
1029         LocalTime t = TEST_12_30_40_987654321.plus(7, ChronoUnit.HOURS);
1030         assertEquals(t, LocalTime.of(19, 30, 40, 987654321));
1031     }
1032 
1033     @Test(groups={"tck"})
1034     public void test_plus_longTemporalUnit_negativeMinutes() {
1035         LocalTime t = TEST_12_30_40_987654321.plus(-25, ChronoUnit.MINUTES);
1036         assertEquals(t, LocalTime.of(12, 5, 40, 987654321));
1037     }
1038 
1039     @Test(groups={"tck"})
1040     public void test_plus_longTemporalUnit_zero() {
1041         LocalTime t = TEST_12_30_40_987654321.plus(0, ChronoUnit.MINUTES);
1042         assertEquals(t, TEST_12_30_40_987654321);
1043     }
1044 
1045     @Test(groups={"tck"})
1046     public void test_plus_longTemporalUnit_invalidUnit() {
1047         for (TemporalUnit unit : INVALID_UNITS) {
1048             try {
1049                 TEST_12_30_40_987654321.plus(1, unit);
1050                 fail("Unit should not be allowed " + unit);
1051             } catch (DateTimeException ex) {
1052                 // expected
1053             }
1054         }
1055     }
1056 
1057     @Test(groups={"tck"})
1058     public void test_plus_longTemporalUnit_multiples() {
1059         assertEquals(TEST_12_30_40_987654321.plus(0, DAYS), TEST_12_30_40_987654321);
1060         assertEquals(TEST_12_30_40_987654321.plus(1, DAYS), TEST_12_30_40_987654321);
1061         assertEquals(TEST_12_30_40_987654321.plus(2, DAYS), TEST_12_30_40_987654321);
1062         assertEquals(TEST_12_30_40_987654321.plus(-3, DAYS), TEST_12_30_40_987654321);
1063     }
1064 
1065     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1066     public void test_plus_longTemporalUnit_null() {
1067         TEST_12_30_40_987654321.plus(1, (TemporalUnit) null);
1068     }
1069 
1070     //-----------------------------------------------------------------------
1071     // plus(adjuster)
1072     //-----------------------------------------------------------------------
1073     @Test(groups={"tck"})
1074     public void test_plus_adjuster() {
1075         Period p = Period.ofTime(0, 0, 62, 3);
1076         LocalTime t = TEST_12_30_40_987654321.plus(p);
1077         assertEquals(t, LocalTime.of(12, 31, 42, 987654324));
1078     }
1079 
1080     @Test(groups={"tck"})
1081     public void test_plus_adjuster_big() {
1082         Period p = Period.ofTime(0, 0, 0, Long.MAX_VALUE);
1083         LocalTime t = TEST_12_30_40_987654321.plus(p);
1084         assertEquals(t, TEST_12_30_40_987654321.plusNanos(Long.MAX_VALUE));
1085     }
1086 
1087     @Test(groups={"tck"})
1088     public void test_plus_adjuster_zero_equal() {
1089         LocalTime t = TEST_12_30_40_987654321.plus(Period.ZERO);
1090         assertEquals(t, TEST_12_30_40_987654321);
1091     }
1092 
1093     @Test(groups={"tck"})
1094     public void test_plus_adjuster_wrap() {
1095         Period p = Period.ofTime(1, 0, 0);
1096         LocalTime t = LocalTime.of(23, 30).plus(p);
1097         assertEquals(t, LocalTime.of(0, 30));
1098     }
1099 
1100     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1101     public void test_plus_adjuster_null() {
1102         TEST_12_30_40_987654321.plus((TemporalAdder) null);
1103     }
1104 
1105     //-----------------------------------------------------------------------
1106     // plusHours()
1107     //-----------------------------------------------------------------------
1108     @Test(groups={"tck"})
1109     public void test_plusHours_one() {
1110         LocalTime t = LocalTime.MIDNIGHT;
1111         for (int i = 0; i < 50; i++) {
1112             t = t.plusHours(1);
1113             assertEquals(t.getHour(), (i + 1) % 24);
1114         }
1115     }
1116 
1117     @Test(groups={"tck"})
1118     public void test_plusHours_fromZero() {
1119         LocalTime base = LocalTime.MIDNIGHT;
1120         for (int i = -50; i < 50; i++) {
1121             LocalTime t = base.plusHours(i);
1122             assertEquals(t.getHour(), (i + 72) % 24);
1123         }
1124     }
1125 
1126     @Test(groups={"tck"})
1127     public void test_plusHours_fromOne() {
1128         LocalTime base = LocalTime.of(1, 0);
1129         for (int i = -50; i < 50; i++) {
1130             LocalTime t = base.plusHours(i);
1131             assertEquals(t.getHour(), (1 + i + 72) % 24);
1132         }
1133     }
1134 
1135     @Test(groups={"tck"})
1136     public void test_plusHours_noChange_equal() {
1137         LocalTime t = TEST_12_30_40_987654321.plusHours(0);
1138         assertEquals(t, TEST_12_30_40_987654321);
1139     }
1140 
1141     @Test(groups={"tck"})
1142     public void test_plusHours_toMidnight_equal() {
1143         LocalTime t = LocalTime.of(23, 0).plusHours(1);
1144         assertEquals(t, LocalTime.MIDNIGHT);
1145     }
1146 
1147     @Test(groups={"tck"})
1148     public void test_plusHours_toMidday_equal() {
1149         LocalTime t = LocalTime.of(11, 0).plusHours(1);
1150         assertEquals(t, LocalTime.NOON);
1151     }
1152 
1153     @Test(groups={"tck"})
1154     public void test_plusHours_big() {
1155         LocalTime t = LocalTime.of(2, 30).plusHours(Long.MAX_VALUE);
1156         int hours = (int) (Long.MAX_VALUE % 24L);
1157         assertEquals(t, LocalTime.of(2, 30).plusHours(hours));
1158     }
1159 
1160     //-----------------------------------------------------------------------
1161     // plusMinutes()
1162     //-----------------------------------------------------------------------
1163     @Test(groups={"tck"})
1164     public void test_plusMinutes_one() {
1165         LocalTime t = LocalTime.MIDNIGHT;
1166         int hour = 0;
1167         int min = 0;
1168         for (int i = 0; i < 70; i++) {
1169             t = t.plusMinutes(1);
1170             min++;
1171             if (min == 60) {
1172                 hour++;
1173                 min = 0;
1174             }
1175             assertEquals(t.getHour(), hour);
1176             assertEquals(t.getMinute(), min);
1177         }
1178     }
1179 
1180     @Test(groups={"tck"})
1181     public void test_plusMinutes_fromZero() {
1182         LocalTime base = LocalTime.MIDNIGHT;
1183         int hour;
1184         int min;
1185         for (int i = -70; i < 70; i++) {
1186             LocalTime t = base.plusMinutes(i);
1187             if (i < -60) {
1188                 hour = 22;
1189                 min = i + 120;
1190             } else if (i < 0) {
1191                 hour = 23;
1192                 min = i + 60;
1193             } else if (i >= 60) {
1194                 hour = 1;
1195                 min = i - 60;
1196             } else {
1197                 hour = 0;
1198                 min = i;
1199             }
1200             assertEquals(t.getHour(), hour);
1201             assertEquals(t.getMinute(), min);
1202         }
1203     }
1204 
1205     @Test(groups={"tck"})
1206     public void test_plusMinutes_noChange_equal() {
1207         LocalTime t = TEST_12_30_40_987654321.plusMinutes(0);
1208         assertEquals(t, TEST_12_30_40_987654321);
1209     }
1210 
1211     @Test(groups={"tck"})
1212     public void test_plusMinutes_noChange_oneDay_equal() {
1213         LocalTime t = TEST_12_30_40_987654321.plusMinutes(24 * 60);
1214         assertEquals(t, TEST_12_30_40_987654321);
1215     }
1216 
1217     @Test(groups={"tck"})
1218     public void test_plusMinutes_toMidnight_equal() {
1219         LocalTime t = LocalTime.of(23, 59).plusMinutes(1);
1220         assertEquals(t, LocalTime.MIDNIGHT);
1221     }
1222 
1223     @Test(groups={"tck"})
1224     public void test_plusMinutes_toMidday_equal() {
1225         LocalTime t = LocalTime.of(11, 59).plusMinutes(1);
1226         assertEquals(t, LocalTime.NOON);
1227     }
1228 
1229     @Test(groups={"tck"})
1230     public void test_plusMinutes_big() {
1231         LocalTime t = LocalTime.of(2, 30).plusMinutes(Long.MAX_VALUE);
1232         int mins = (int) (Long.MAX_VALUE % (24L * 60L));
1233         assertEquals(t, LocalTime.of(2, 30).plusMinutes(mins));
1234     }
1235 
1236     //-----------------------------------------------------------------------
1237     // plusSeconds()
1238     //-----------------------------------------------------------------------
1239     @Test(groups={"tck"})
1240     public void test_plusSeconds_one() {
1241         LocalTime t = LocalTime.MIDNIGHT;
1242         int hour = 0;
1243         int min = 0;
1244         int sec = 0;
1245         for (int i = 0; i < 3700; i++) {
1246             t = t.plusSeconds(1);
1247             sec++;
1248             if (sec == 60) {
1249                 min++;
1250                 sec = 0;
1251             }
1252             if (min == 60) {
1253                 hour++;
1254                 min = 0;
1255             }
1256             assertEquals(t.getHour(), hour);
1257             assertEquals(t.getMinute(), min);
1258             assertEquals(t.getSecond(), sec);
1259         }
1260     }
1261 
1262     @DataProvider(name="plusSeconds_fromZero")
1263     Iterator<Object[]> plusSeconds_fromZero() {
1264         return new Iterator<Object[]>() {
1265             int delta = 30;
1266             int i = -3660;
1267             int hour = 22;
1268             int min = 59;
1269             int sec = 0;
1270 
1271             public boolean hasNext() {
1272                 return i <= 3660;
1273             }
1274 
1275             public Object[] next() {
1276                 final Object[] ret = new Object[] {i, hour, min, sec};
1277                 i += delta;
1278                 sec += delta;
1279 
1280                 if (sec >= 60) {
1281                     min++;
1282                     sec -= 60;
1283 
1284                     if (min == 60) {
1285                         hour++;
1286                         min = 0;
1287 
1288                         if (hour == 24) {
1289                             hour = 0;
1290                         }
1291                     }
1292                 }
1293 
1294                 return ret;
1295             }
1296 
1297             public void remove() {
1298                 throw new UnsupportedOperationException();
1299             }
1300         };
1301     }
1302 
1303     @Test(dataProvider="plusSeconds_fromZero", groups={"tck"})
1304     public void test_plusSeconds_fromZero(int seconds, int hour, int min, int sec) {
1305         LocalTime base = LocalTime.MIDNIGHT;
1306         LocalTime t = base.plusSeconds(seconds);
1307 
1308         assertEquals(hour, t.getHour());
1309         assertEquals(min, t.getMinute());
1310         assertEquals(sec, t.getSecond());
1311     }
1312 
1313     @Test(groups={"tck"})
1314     public void test_plusSeconds_noChange_equal() {
1315         LocalTime t = TEST_12_30_40_987654321.plusSeconds(0);
1316         assertEquals(t, TEST_12_30_40_987654321);
1317     }
1318 
1319     @Test(groups={"tck"})
1320     public void test_plusSeconds_noChange_oneDay_equal() {
1321         LocalTime t = TEST_12_30_40_987654321.plusSeconds(24 * 60 * 60);
1322         assertEquals(t, TEST_12_30_40_987654321);
1323     }
1324 
1325     @Test(groups={"tck"})
1326     public void test_plusSeconds_toMidnight_equal() {
1327         LocalTime t = LocalTime.of(23, 59, 59).plusSeconds(1);
1328         assertEquals(t, LocalTime.MIDNIGHT);
1329     }
1330 
1331     @Test(groups={"tck"})
1332     public void test_plusSeconds_toMidday_equal() {
1333         LocalTime t = LocalTime.of(11, 59, 59).plusSeconds(1);
1334         assertEquals(t, LocalTime.NOON);
1335     }
1336 
1337     //-----------------------------------------------------------------------
1338     // plusNanos()
1339     //-----------------------------------------------------------------------
1340     @Test(groups={"tck"})
1341     public void test_plusNanos_halfABillion() {
1342         LocalTime t = LocalTime.MIDNIGHT;
1343         int hour = 0;
1344         int min = 0;
1345         int sec = 0;
1346         int nanos = 0;
1347         for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
1348             t = t.plusNanos(500000000);
1349             nanos += 500000000;
1350             if (nanos == 1000000000) {
1351                 sec++;
1352                 nanos = 0;
1353             }
1354             if (sec == 60) {
1355                 min++;
1356                 sec = 0;
1357             }
1358             if (min == 60) {
1359                 hour++;
1360                 min = 0;
1361             }
1362             assertEquals(t.getHour(), hour);
1363             assertEquals(t.getMinute(), min);
1364             assertEquals(t.getSecond(), sec);
1365             assertEquals(t.getNano(), nanos);
1366         }
1367     }
1368 
1369     @DataProvider(name="plusNanos_fromZero")
1370     Iterator<Object[]> plusNanos_fromZero() {
1371         return new Iterator<Object[]>() {
1372             long delta = 7500000000L;
1373             long i = -3660 * 1000000000L;
1374             int hour = 22;
1375             int min = 59;
1376             int sec = 0;
1377             long nanos = 0;
1378 
1379             public boolean hasNext() {
1380                 return i <= 3660 * 1000000000L;
1381             }
1382 
1383             public Object[] next() {
1384                 final Object[] ret = new Object[] {i, hour, min, sec, (int)nanos};
1385                 i += delta;
1386                 nanos += delta;
1387 
1388                 if (nanos >= 1000000000L) {
1389                     sec += nanos / 1000000000L;
1390                     nanos %= 1000000000L;
1391 
1392                     if (sec >= 60) {
1393                         min++;
1394                         sec %= 60;
1395 
1396                         if (min == 60) {
1397                             hour++;
1398                             min = 0;
1399 
1400                             if (hour == 24) {
1401                                 hour = 0;
1402                             }
1403                         }
1404                     }
1405                 }
1406 
1407                 return ret;
1408             }
1409 
1410             public void remove() {
1411                 throw new UnsupportedOperationException();
1412             }
1413         };
1414     }
1415 
1416     @Test(dataProvider="plusNanos_fromZero", groups={"tck"})
1417     public void test_plusNanos_fromZero(long nanoseconds, int hour, int min, int sec, int nanos) {
1418         LocalTime base = LocalTime.MIDNIGHT;
1419         LocalTime t = base.plusNanos(nanoseconds);
1420 
1421         assertEquals(hour, t.getHour());
1422         assertEquals(min, t.getMinute());
1423         assertEquals(sec, t.getSecond());
1424         assertEquals(nanos, t.getNano());
1425     }
1426 
1427     @Test(groups={"tck"})
1428     public void test_plusNanos_noChange_equal() {
1429         LocalTime t = TEST_12_30_40_987654321.plusNanos(0);
1430         assertEquals(t, TEST_12_30_40_987654321);
1431     }
1432 
1433     @Test(groups={"tck"})
1434     public void test_plusNanos_noChange_oneDay_equal() {
1435         LocalTime t = TEST_12_30_40_987654321.plusNanos(24 * 60 * 60 * 1000000000L);
1436         assertEquals(t, TEST_12_30_40_987654321);
1437     }
1438 
1439     @Test(groups={"tck"})
1440     public void test_plusNanos_toMidnight_equal() {
1441         LocalTime t = LocalTime.of(23, 59, 59, 999999999).plusNanos(1);
1442         assertEquals(t, LocalTime.MIDNIGHT);
1443     }
1444 
1445     @Test(groups={"tck"})
1446     public void test_plusNanos_toMidday_equal() {
1447         LocalTime t = LocalTime.of(11, 59, 59, 999999999).plusNanos(1);
1448         assertEquals(t, LocalTime.NOON);
1449     }
1450 
1451     //-----------------------------------------------------------------------
1452     // minus(MinusAdjuster)
1453     //-----------------------------------------------------------------------
1454     @Test(groups={"tck"})
1455     public void test_minus_Adjuster() {
1456         TemporalSubtractor p = Period.ofTime(0, 0, 62, 3);
1457         LocalTime t = TEST_12_30_40_987654321.minus(p);
1458         assertEquals(t, LocalTime.of(12, 29, 38, 987654318));
1459     }
1460 
1461     @Test(groups={"tck"})
1462     public void test_minus_Adjuster_positiveHours() {
1463         TemporalSubtractor period = MockSimplePeriod.of(7, ChronoUnit.HOURS);
1464         LocalTime t = TEST_12_30_40_987654321.minus(period);
1465         assertEquals(t, LocalTime.of(5, 30, 40, 987654321));
1466     }
1467 
1468     @Test(groups={"tck"})
1469     public void test_minus_Adjuster_negativeMinutes() {
1470         TemporalSubtractor period = MockSimplePeriod.of(-25, ChronoUnit.MINUTES);
1471         LocalTime t = TEST_12_30_40_987654321.minus(period);
1472         assertEquals(t, LocalTime.of(12, 55, 40, 987654321));
1473     }
1474 
1475     @Test(groups={"tck"})
1476     public void test_minus_Adjuster_big1() {
1477         TemporalSubtractor p = Period.ofTime(0, 0, 0, Long.MAX_VALUE);
1478         LocalTime t = TEST_12_30_40_987654321.minus(p);
1479         assertEquals(t, TEST_12_30_40_987654321.minusNanos(Long.MAX_VALUE));
1480     }
1481 
1482     @Test(groups={"tck"})
1483     public void test_minus_Adjuster_zero() {
1484         TemporalSubtractor p = Period.ZERO;
1485         LocalTime t = TEST_12_30_40_987654321.minus(p);
1486         assertEquals(t, TEST_12_30_40_987654321);
1487     }
1488 
1489     @Test(groups={"tck"})
1490     public void test_minus_Adjuster_wrap() {
1491         TemporalSubtractor p = Period.ofTime(1, 0, 0);
1492         LocalTime t = LocalTime.of(0, 30).minus(p);
1493         assertEquals(t, LocalTime.of(23, 30));
1494     }
1495 
1496     @Test(groups={"tck"}, expectedExceptions=DateTimeException.class)
1497     public void test_minus_Adjuster_dateNotAllowed() {
1498         TemporalSubtractor period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
1499         TEST_12_30_40_987654321.minus(period);
1500     }
1501 
1502     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1503     public void test_minus_Adjuster_null() {
1504         TEST_12_30_40_987654321.minus((TemporalSubtractor) null);
1505     }
1506 
1507     //-----------------------------------------------------------------------
1508     // minus(long,TemporalUnit)
1509     //-----------------------------------------------------------------------
1510     @Test(groups={"tck"})
1511     public void test_minus_longTemporalUnit_positiveHours() {
1512         LocalTime t = TEST_12_30_40_987654321.minus(7, ChronoUnit.HOURS);
1513         assertEquals(t, LocalTime.of(5, 30, 40, 987654321));
1514     }
1515 
1516     @Test(groups={"tck"})
1517     public void test_minus_longTemporalUnit_negativeMinutes() {
1518         LocalTime t = TEST_12_30_40_987654321.minus(-25, ChronoUnit.MINUTES);
1519         assertEquals(t, LocalTime.of(12, 55, 40, 987654321));
1520     }
1521 
1522     @Test(groups={"tck"})
1523     public void test_minus_longTemporalUnit_zero() {
1524         LocalTime t = TEST_12_30_40_987654321.minus(0, ChronoUnit.MINUTES);
1525         assertEquals(t, TEST_12_30_40_987654321);
1526     }
1527 
1528     @Test(groups={"tck"})
1529     public void test_minus_longTemporalUnit_invalidUnit() {
1530         for (TemporalUnit unit : INVALID_UNITS) {
1531             try {
1532                 TEST_12_30_40_987654321.minus(1, unit);
1533                 fail("Unit should not be allowed " + unit);
1534             } catch (DateTimeException ex) {
1535                 // expected
1536             }
1537         }
1538     }
1539 
1540     @Test(groups={"tck"})
1541     public void test_minus_longTemporalUnit_long_multiples() {
1542         assertEquals(TEST_12_30_40_987654321.minus(0, DAYS), TEST_12_30_40_987654321);
1543         assertEquals(TEST_12_30_40_987654321.minus(1, DAYS), TEST_12_30_40_987654321);
1544         assertEquals(TEST_12_30_40_987654321.minus(2, DAYS), TEST_12_30_40_987654321);
1545         assertEquals(TEST_12_30_40_987654321.minus(-3, DAYS), TEST_12_30_40_987654321);
1546     }
1547 
1548     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1549     public void test_minus_longTemporalUnit_null() {
1550         TEST_12_30_40_987654321.minus(1, (TemporalUnit) null);
1551     }
1552 
1553     //-----------------------------------------------------------------------
1554     // minusHours()
1555     //-----------------------------------------------------------------------
1556     @Test(groups={"tck"})
1557     public void test_minusHours_one() {
1558         LocalTime t = LocalTime.MIDNIGHT;
1559         for (int i = 0; i < 50; i++) {
1560             t = t.minusHours(1);
1561             assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24, String.valueOf(i));
1562         }
1563     }
1564 
1565     @Test(groups={"tck"})
1566     public void test_minusHours_fromZero() {
1567         LocalTime base = LocalTime.MIDNIGHT;
1568         for (int i = -50; i < 50; i++) {
1569             LocalTime t = base.minusHours(i);
1570             assertEquals(t.getHour(), ((-i % 24) + 24) % 24);
1571         }
1572     }
1573 
1574     @Test(groups={"tck"})
1575     public void test_minusHours_fromOne() {
1576         LocalTime base = LocalTime.of(1, 0);
1577         for (int i = -50; i < 50; i++) {
1578             LocalTime t = base.minusHours(i);
1579             assertEquals(t.getHour(), (1 + (-i % 24) + 24) % 24);
1580         }
1581     }
1582 
1583     @Test(groups={"tck"})
1584     public void test_minusHours_noChange_equal() {
1585         LocalTime t = TEST_12_30_40_987654321.minusHours(0);
1586         assertEquals(t, TEST_12_30_40_987654321);
1587     }
1588 
1589     @Test(groups={"tck"})
1590     public void test_minusHours_toMidnight_equal() {
1591         LocalTime t = LocalTime.of(1, 0).minusHours(1);
1592         assertEquals(t, LocalTime.MIDNIGHT);
1593     }
1594 
1595     @Test(groups={"tck"})
1596     public void test_minusHours_toMidday_equal() {
1597         LocalTime t = LocalTime.of(13, 0).minusHours(1);
1598         assertEquals(t, LocalTime.NOON);
1599     }
1600 
1601     @Test(groups={"tck"})
1602     public void test_minusHours_big() {
1603         LocalTime t = LocalTime.of(2, 30).minusHours(Long.MAX_VALUE);
1604         int hours = (int) (Long.MAX_VALUE % 24L);
1605         assertEquals(t, LocalTime.of(2, 30).minusHours(hours));
1606     }
1607 
1608     //-----------------------------------------------------------------------
1609     // minusMinutes()
1610     //-----------------------------------------------------------------------
1611     @Test(groups={"tck"})
1612     public void test_minusMinutes_one() {
1613         LocalTime t = LocalTime.MIDNIGHT;
1614         int hour = 0;
1615         int min = 0;
1616         for (int i = 0; i < 70; i++) {
1617             t = t.minusMinutes(1);
1618             min--;
1619             if (min == -1) {
1620                 hour--;
1621                 min = 59;
1622 
1623                 if (hour == -1) {
1624                     hour = 23;
1625                 }
1626             }
1627             assertEquals(t.getHour(), hour);
1628             assertEquals(t.getMinute(), min);
1629         }
1630     }
1631 
1632     @Test(groups={"tck"})
1633     public void test_minusMinutes_fromZero() {
1634         LocalTime base = LocalTime.MIDNIGHT;
1635         int hour = 22;
1636         int min = 49;
1637         for (int i = 70; i > -70; i--) {
1638             LocalTime t = base.minusMinutes(i);
1639             min++;
1640 
1641             if (min == 60) {
1642                 hour++;
1643                 min = 0;
1644 
1645                 if (hour == 24) {
1646                     hour = 0;
1647                 }
1648             }
1649 
1650             assertEquals(t.getHour(), hour);
1651             assertEquals(t.getMinute(), min);
1652         }
1653     }
1654 
1655     @Test(groups={"tck"})
1656     public void test_minusMinutes_noChange_equal() {
1657         LocalTime t = TEST_12_30_40_987654321.minusMinutes(0);
1658         assertEquals(t, TEST_12_30_40_987654321);
1659     }
1660 
1661     @Test(groups={"tck"})
1662     public void test_minusMinutes_noChange_oneDay_equal() {
1663         LocalTime t = TEST_12_30_40_987654321.minusMinutes(24 * 60);
1664         assertEquals(t, TEST_12_30_40_987654321);
1665     }
1666 
1667     @Test(groups={"tck"})
1668     public void test_minusMinutes_toMidnight_equal() {
1669         LocalTime t = LocalTime.of(0, 1).minusMinutes(1);
1670         assertEquals(t, LocalTime.MIDNIGHT);
1671     }
1672 
1673     @Test(groups={"tck"})
1674     public void test_minusMinutes_toMidday_equals() {
1675         LocalTime t = LocalTime.of(12, 1).minusMinutes(1);
1676         assertEquals(t, LocalTime.NOON);
1677     }
1678 
1679     @Test(groups={"tck"})
1680     public void test_minusMinutes_big() {
1681         LocalTime t = LocalTime.of(2, 30).minusMinutes(Long.MAX_VALUE);
1682         int mins = (int) (Long.MAX_VALUE % (24L * 60L));
1683         assertEquals(t, LocalTime.of(2, 30).minusMinutes(mins));
1684     }
1685 
1686     //-----------------------------------------------------------------------
1687     // minusSeconds()
1688     //-----------------------------------------------------------------------
1689     @Test(groups={"tck"})
1690     public void test_minusSeconds_one() {
1691         LocalTime t = LocalTime.MIDNIGHT;
1692         int hour = 0;
1693         int min = 0;
1694         int sec = 0;
1695         for (int i = 0; i < 3700; i++) {
1696             t = t.minusSeconds(1);
1697             sec--;
1698             if (sec == -1) {
1699                 min--;
1700                 sec = 59;
1701 
1702                 if (min == -1) {
1703                     hour--;
1704                     min = 59;
1705 
1706                     if (hour == -1) {
1707                         hour = 23;
1708                     }
1709                 }
1710             }
1711             assertEquals(t.getHour(), hour);
1712             assertEquals(t.getMinute(), min);
1713             assertEquals(t.getSecond(), sec);
1714         }
1715     }
1716 
1717     @DataProvider(name="minusSeconds_fromZero")
1718     Iterator<Object[]> minusSeconds_fromZero() {
1719         return new Iterator<Object[]>() {
1720             int delta = 30;
1721             int i = 3660;
1722             int hour = 22;
1723             int min = 59;
1724             int sec = 0;
1725 
1726             public boolean hasNext() {
1727                 return i >= -3660;
1728             }
1729 
1730             public Object[] next() {
1731                 final Object[] ret = new Object[] {i, hour, min, sec};
1732                 i -= delta;
1733                 sec += delta;
1734 
1735                 if (sec >= 60) {
1736                     min++;
1737                     sec -= 60;
1738 
1739                     if (min == 60) {
1740                         hour++;
1741                         min = 0;
1742 
1743                         if (hour == 24) {
1744                             hour = 0;
1745                         }
1746                     }
1747                 }
1748 
1749                 return ret;
1750             }
1751 
1752             public void remove() {
1753                 throw new UnsupportedOperationException();
1754             }
1755         };
1756     }
1757 
1758     @Test(dataProvider="minusSeconds_fromZero", groups={"tck"})
1759     public void test_minusSeconds_fromZero(int seconds, int hour, int min, int sec) {
1760         LocalTime base = LocalTime.MIDNIGHT;
1761         LocalTime t = base.minusSeconds(seconds);
1762 
1763         assertEquals(t.getHour(), hour);
1764         assertEquals(t.getMinute(), min);
1765         assertEquals(t.getSecond(), sec);
1766     }
1767 
1768     @Test(groups={"tck"})
1769     public void test_minusSeconds_noChange_equal() {
1770         LocalTime t = TEST_12_30_40_987654321.minusSeconds(0);
1771         assertEquals(t, TEST_12_30_40_987654321);
1772     }
1773 
1774     @Test(groups={"tck"})
1775     public void test_minusSeconds_noChange_oneDay_equal() {
1776         LocalTime t = TEST_12_30_40_987654321.minusSeconds(24 * 60 * 60);
1777         assertEquals(t, TEST_12_30_40_987654321);
1778     }
1779 
1780     @Test(groups={"tck"})
1781     public void test_minusSeconds_toMidnight_equal() {
1782         LocalTime t = LocalTime.of(0, 0, 1).minusSeconds(1);
1783         assertEquals(t, LocalTime.MIDNIGHT);
1784     }
1785 
1786     @Test(groups={"tck"})
1787     public void test_minusSeconds_toMidday_equal() {
1788         LocalTime t = LocalTime.of(12, 0, 1).minusSeconds(1);
1789         assertEquals(t, LocalTime.NOON);
1790     }
1791 
1792     @Test(groups={"tck"})
1793     public void test_minusSeconds_big() {
1794         LocalTime t = LocalTime.of(2, 30).minusSeconds(Long.MAX_VALUE);
1795         int secs = (int) (Long.MAX_VALUE % (24L * 60L * 60L));
1796         assertEquals(t, LocalTime.of(2, 30).minusSeconds(secs));
1797     }
1798 
1799     //-----------------------------------------------------------------------
1800     // minusNanos()
1801     //-----------------------------------------------------------------------
1802     @Test(groups={"tck"})
1803     public void test_minusNanos_halfABillion() {
1804         LocalTime t = LocalTime.MIDNIGHT;
1805         int hour = 0;
1806         int min = 0;
1807         int sec = 0;
1808         int nanos = 0;
1809         for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
1810             t = t.minusNanos(500000000);
1811             nanos -= 500000000;
1812 
1813             if (nanos < 0) {
1814                 sec--;
1815                 nanos += 1000000000;
1816 
1817                 if (sec == -1) {
1818                     min--;
1819                     sec += 60;
1820 
1821                     if (min == -1) {
1822                         hour--;
1823                         min += 60;
1824 
1825                         if (hour == -1) {
1826                             hour += 24;
1827                         }
1828                     }
1829                 }
1830             }
1831 
1832             assertEquals(t.getHour(), hour);
1833             assertEquals(t.getMinute(), min);
1834             assertEquals(t.getSecond(), sec);
1835             assertEquals(t.getNano(), nanos);
1836         }
1837     }
1838 
1839     @DataProvider(name="minusNanos_fromZero")
1840     Iterator<Object[]> minusNanos_fromZero() {
1841         return new Iterator<Object[]>() {
1842             long delta = 7500000000L;
1843             long i = 3660 * 1000000000L;
1844             int hour = 22;
1845             int min = 59;
1846             int sec = 0;
1847             long nanos = 0;
1848 
1849             public boolean hasNext() {
1850                 return i >= -3660 * 1000000000L;
1851             }
1852 
1853             public Object[] next() {
1854                 final Object[] ret = new Object[] {i, hour, min, sec, (int)nanos};
1855                 i -= delta;
1856                 nanos += delta;
1857 
1858                 if (nanos >= 1000000000L) {
1859                     sec += nanos / 1000000000L;
1860                     nanos %= 1000000000L;
1861 
1862                     if (sec >= 60) {
1863                         min++;
1864                         sec %= 60;
1865 
1866                         if (min == 60) {
1867                             hour++;
1868                             min = 0;
1869 
1870                             if (hour == 24) {
1871                                 hour = 0;
1872                             }
1873                         }
1874                     }
1875                 }
1876 
1877                 return ret;
1878             }
1879 
1880             public void remove() {
1881                 throw new UnsupportedOperationException();
1882             }
1883         };
1884     }
1885 
1886     @Test(dataProvider="minusNanos_fromZero", groups={"tck"})
1887     public void test_minusNanos_fromZero(long nanoseconds, int hour, int min, int sec, int nanos) {
1888         LocalTime base = LocalTime.MIDNIGHT;
1889         LocalTime t = base.minusNanos(nanoseconds);
1890 
1891         assertEquals(hour, t.getHour());
1892         assertEquals(min, t.getMinute());
1893         assertEquals(sec, t.getSecond());
1894         assertEquals(nanos, t.getNano());
1895     }
1896 
1897     @Test(groups={"tck"})
1898     public void test_minusNanos_noChange_equal() {
1899         LocalTime t = TEST_12_30_40_987654321.minusNanos(0);
1900         assertEquals(t, TEST_12_30_40_987654321);
1901     }
1902 
1903     @Test(groups={"tck"})
1904     public void test_minusNanos_noChange_oneDay_equal() {
1905         LocalTime t = TEST_12_30_40_987654321.minusNanos(24 * 60 * 60 * 1000000000L);
1906         assertEquals(t, TEST_12_30_40_987654321);
1907     }
1908 
1909     @Test(groups={"tck"})
1910     public void test_minusNanos_toMidnight_equal() {
1911         LocalTime t = LocalTime.of(0, 0, 0, 1).minusNanos(1);
1912         assertEquals(t, LocalTime.MIDNIGHT);
1913     }
1914 
1915     @Test(groups={"tck"})
1916     public void test_minusNanos_toMidday_equal() {
1917         LocalTime t = LocalTime.of(12, 0, 0, 1).minusNanos(1);
1918         assertEquals(t, LocalTime.NOON);
1919     }
1920 
1921     //-----------------------------------------------------------------------
1922     // atDate()
1923     //-----------------------------------------------------------------------
1924     @Test(groups={"tck"})
1925     public void test_atDate() {
1926         LocalTime t = LocalTime.of(11, 30);
1927         assertEquals(t.atDate(LocalDate.of(2012, 6, 30)), LocalDateTime.of(2012, 6, 30, 11, 30));
1928     }
1929 
1930     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1931     public void test_atDate_nullDate() {
1932         TEST_12_30_40_987654321.atDate((LocalDate) null);
1933     }
1934 
1935     //-----------------------------------------------------------------------
1936     // atOffset()
1937     //-----------------------------------------------------------------------
1938     @Test(groups={"tck"})
1939     public void test_atOffset() {
1940         LocalTime t = LocalTime.of(11, 30);
1941         assertEquals(t.atOffset(OFFSET_PTWO), OffsetTime.of(LocalTime.of(11, 30), OFFSET_PTWO));
1942     }
1943 
1944     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1945     public void test_atOffset_nullZoneOffset() {
1946         LocalTime t = LocalTime.of(11, 30);
1947         t.atOffset((ZoneOffset) null);
1948     }
1949 
1950     //-----------------------------------------------------------------------
1951     // toSecondOfDay()
1952     //-----------------------------------------------------------------------
1953     @Test(groups={"tck"})
1954     public void test_toSecondOfDay() {
1955         LocalTime t = LocalTime.of(0, 0);
1956         for (int i = 0; i < 24 * 60 * 60; i++) {
1957             assertEquals(t.toSecondOfDay(), i);
1958             t = t.plusSeconds(1);
1959         }
1960     }
1961 
1962     @Test(groups={"tck"})
1963     public void test_toSecondOfDay_fromNanoOfDay_symmetry() {
1964         LocalTime t = LocalTime.of(0, 0);
1965         for (int i = 0; i < 24 * 60 * 60; i++) {
1966             assertEquals(LocalTime.ofSecondOfDay(t.toSecondOfDay()), t);
1967             t = t.plusSeconds(1);
1968         }
1969     }
1970 
1971     //-----------------------------------------------------------------------
1972     // toNanoOfDay()
1973     //-----------------------------------------------------------------------
1974     @Test(groups={"tck"})
1975     public void test_toNanoOfDay() {
1976         LocalTime t = LocalTime.of(0, 0);
1977         for (int i = 0; i < 1000000; i++) {
1978             assertEquals(t.toNanoOfDay(), i);
1979             t = t.plusNanos(1);
1980         }
1981         t = LocalTime.of(0, 0);
1982         for (int i = 1; i <= 1000000; i++) {
1983             t = t.minusNanos(1);
1984             assertEquals(t.toNanoOfDay(), 24 * 60 * 60 * 1000000000L - i);
1985         }
1986     }
1987 
1988     @Test(groups={"tck"})
1989     public void test_toNanoOfDay_fromNanoOfDay_symmetry() {
1990         LocalTime t = LocalTime.of(0, 0);
1991         for (int i = 0; i < 1000000; i++) {
1992             assertEquals(LocalTime.ofNanoOfDay(t.toNanoOfDay()), t);
1993             t = t.plusNanos(1);
1994         }
1995         t = LocalTime.of(0, 0);
1996         for (int i = 1; i <= 1000000; i++) {
1997             t = t.minusNanos(1);
1998             assertEquals(LocalTime.ofNanoOfDay(t.toNanoOfDay()), t);
1999         }
2000     }
2001 
2002     //-----------------------------------------------------------------------
2003     // compareTo()
2004     //-----------------------------------------------------------------------
2005     @Test(groups={"tck"})
2006     public void test_comparisons() {
2007         doTest_comparisons_LocalTime(
2008             LocalTime.MIDNIGHT,
2009             LocalTime.of(0, 0, 0, 999999999),
2010             LocalTime.of(0, 0, 59, 0),
2011             LocalTime.of(0, 0, 59, 999999999),
2012             LocalTime.of(0, 59, 0, 0),
2013             LocalTime.of(0, 59, 0, 999999999),
2014             LocalTime.of(0, 59, 59, 0),
2015             LocalTime.of(0, 59, 59, 999999999),
2016             LocalTime.NOON,
2017             LocalTime.of(12, 0, 0, 999999999),
2018             LocalTime.of(12, 0, 59, 0),
2019             LocalTime.of(12, 0, 59, 999999999),
2020             LocalTime.of(12, 59, 0, 0),
2021             LocalTime.of(12, 59, 0, 999999999),
2022             LocalTime.of(12, 59, 59, 0),
2023             LocalTime.of(12, 59, 59, 999999999),
2024             LocalTime.of(23, 0, 0, 0),
2025             LocalTime.of(23, 0, 0, 999999999),
2026             LocalTime.of(23, 0, 59, 0),
2027             LocalTime.of(23, 0, 59, 999999999),
2028             LocalTime.of(23, 59, 0, 0),
2029             LocalTime.of(23, 59, 0, 999999999),
2030             LocalTime.of(23, 59, 59, 0),
2031             LocalTime.of(23, 59, 59, 999999999)
2032         );
2033     }
2034 
2035     void doTest_comparisons_LocalTime(LocalTime... localTimes) {
2036         for (int i = 0; i < localTimes.length; i++) {
2037             LocalTime a = localTimes[i];
2038             for (int j = 0; j < localTimes.length; j++) {
2039                 LocalTime b = localTimes[j];
2040                 if (i < j) {
2041                     assertTrue(a.compareTo(b) < 0, a + " <=> " + b);
2042                     assertEquals(a.isBefore(b), true, a + " <=> " + b);
2043                     assertEquals(a.isAfter(b), false, a + " <=> " + b);
2044                     assertEquals(a.equals(b), false, a + " <=> " + b);
2045                 } else if (i > j) {
2046                     assertTrue(a.compareTo(b) > 0, a + " <=> " + b);
2047                     assertEquals(a.isBefore(b), false, a + " <=> " + b);
2048                     assertEquals(a.isAfter(b), true, a + " <=> " + b);
2049                     assertEquals(a.equals(b), false, a + " <=> " + b);
2050                 } else {
2051                     assertEquals(a.compareTo(b), 0, a + " <=> " + b);
2052                     assertEquals(a.isBefore(b), false, a + " <=> " + b);
2053                     assertEquals(a.isAfter(b), false, a + " <=> " + b);
2054                     assertEquals(a.equals(b), true, a + " <=> " + b);
2055                 }
2056             }
2057         }
2058     }
2059 
2060     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2061     public void test_compareTo_ObjectNull() {
2062         TEST_12_30_40_987654321.compareTo(null);
2063     }
2064 
2065     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2066     public void test_isBefore_ObjectNull() {
2067         TEST_12_30_40_987654321.isBefore(null);
2068     }
2069 
2070     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2071     public void test_isAfter_ObjectNull() {
2072         TEST_12_30_40_987654321.isAfter(null);
2073     }
2074 
2075     @Test(expectedExceptions=ClassCastException.class, groups={"tck"})
2076     @SuppressWarnings({"unchecked", "rawtypes"})
2077     public void compareToNonLocalTime() {
2078        Comparable c = TEST_12_30_40_987654321;
2079        c.compareTo(new Object());
2080     }
2081 
2082     //-----------------------------------------------------------------------
2083     // equals()
2084     //-----------------------------------------------------------------------
2085     @Test(dataProvider="sampleTimes", groups={"tck"})
2086     public void test_equals_true(int h, int m, int s, int n) {
2087         LocalTime a = LocalTime.of(h, m, s, n);
2088         LocalTime b = LocalTime.of(h, m, s, n);
2089         assertEquals(a.equals(b), true);
2090     }
2091     @Test(dataProvider="sampleTimes", groups={"tck"})
2092     public void test_equals_false_hour_differs(int h, int m, int s, int n) {
2093         LocalTime a = LocalTime.of(h, m, s, n);
2094         LocalTime b = LocalTime.of(h + 1, m, s, n);
2095         assertEquals(a.equals(b), false);
2096     }
2097     @Test(dataProvider="sampleTimes", groups={"tck"})
2098     public void test_equals_false_minute_differs(int h, int m, int s, int n) {
2099         LocalTime a = LocalTime.of(h, m, s, n);
2100         LocalTime b = LocalTime.of(h, m + 1, s, n);
2101         assertEquals(a.equals(b), false);
2102     }
2103     @Test(dataProvider="sampleTimes", groups={"tck"})
2104     public void test_equals_false_second_differs(int h, int m, int s, int n) {
2105         LocalTime a = LocalTime.of(h, m, s, n);
2106         LocalTime b = LocalTime.of(h, m, s + 1, n);
2107         assertEquals(a.equals(b), false);
2108     }
2109     @Test(dataProvider="sampleTimes", groups={"tck"})
2110     public void test_equals_false_nano_differs(int h, int m, int s, int n) {
2111         LocalTime a = LocalTime.of(h, m, s, n);
2112         LocalTime b = LocalTime.of(h, m, s, n + 1);
2113         assertEquals(a.equals(b), false);
2114     }
2115 
2116     @Test(groups={"tck"})
2117     public void test_equals_itself_true() {
2118         assertEquals(TEST_12_30_40_987654321.equals(TEST_12_30_40_987654321), true);
2119     }
2120 
2121     @Test(groups={"tck"})
2122     public void test_equals_string_false() {
2123         assertEquals(TEST_12_30_40_987654321.equals("2007-07-15"), false);
2124     }
2125 
2126     @Test(groups={"tck"})
2127     public void test_equals_null_false() {
2128         assertEquals(TEST_12_30_40_987654321.equals(null), false);
2129     }
2130 
2131     //-----------------------------------------------------------------------
2132     // hashCode()
2133     //-----------------------------------------------------------------------
2134     @Test(dataProvider="sampleTimes", groups={"tck"})
2135     public void test_hashCode_same(int h, int m, int s, int n) {
2136         LocalTime a = LocalTime.of(h, m, s, n);
2137         LocalTime b = LocalTime.of(h, m, s, n);
2138         assertEquals(a.hashCode(), b.hashCode());
2139     }
2140 
2141     @Test(dataProvider="sampleTimes", groups={"tck"})
2142     public void test_hashCode_hour_differs(int h, int m, int s, int n) {
2143         LocalTime a = LocalTime.of(h, m, s, n);
2144         LocalTime b = LocalTime.of(h + 1, m, s, n);
2145         assertEquals(a.hashCode() == b.hashCode(), false);
2146     }
2147 
2148     @Test(dataProvider="sampleTimes", groups={"tck"})
2149     public void test_hashCode_minute_differs(int h, int m, int s, int n) {
2150         LocalTime a = LocalTime.of(h, m, s, n);
2151         LocalTime b = LocalTime.of(h, m + 1, s, n);
2152         assertEquals(a.hashCode() == b.hashCode(), false);
2153     }
2154 
2155     @Test(dataProvider="sampleTimes", groups={"tck"})
2156     public void test_hashCode_second_differs(int h, int m, int s, int n) {
2157         LocalTime a = LocalTime.of(h, m, s, n);
2158         LocalTime b = LocalTime.of(h, m, s + 1, n);
2159         assertEquals(a.hashCode() == b.hashCode(), false);
2160     }
2161 
2162     @Test(dataProvider="sampleTimes", groups={"tck"})
2163     public void test_hashCode_nano_differs(int h, int m, int s, int n) {
2164         LocalTime a = LocalTime.of(h, m, s, n);
2165         LocalTime b = LocalTime.of(h, m, s, n + 1);
2166         assertEquals(a.hashCode() == b.hashCode(), false);
2167     }
2168 
2169     //-----------------------------------------------------------------------
2170     // toString()
2171     //-----------------------------------------------------------------------
2172     @DataProvider(name="sampleToString")
2173     Object[][] provider_sampleToString() {
2174         return new Object[][] {
2175             {0, 0, 0, 0, "00:00"},
2176             {1, 0, 0, 0, "01:00"},
2177             {23, 0, 0, 0, "23:00"},
2178             {0, 1, 0, 0, "00:01"},
2179             {12, 30, 0, 0, "12:30"},
2180             {23, 59, 0, 0, "23:59"},
2181             {0, 0, 1, 0, "00:00:01"},
2182             {0, 0, 59, 0, "00:00:59"},
2183             {0, 0, 0, 100000000, "00:00:00.100"},
2184             {0, 0, 0, 10000000, "00:00:00.010"},
2185             {0, 0, 0, 1000000, "00:00:00.001"},
2186             {0, 0, 0, 100000, "00:00:00.000100"},
2187             {0, 0, 0, 10000, "00:00:00.000010"},
2188             {0, 0, 0, 1000, "00:00:00.000001"},
2189             {0, 0, 0, 100, "00:00:00.000000100"},
2190             {0, 0, 0, 10, "00:00:00.000000010"},
2191             {0, 0, 0, 1, "00:00:00.000000001"},
2192             {0, 0, 0, 999999999, "00:00:00.999999999"},
2193             {0, 0, 0, 99999999, "00:00:00.099999999"},
2194             {0, 0, 0, 9999999, "00:00:00.009999999"},
2195             {0, 0, 0, 999999, "00:00:00.000999999"},
2196             {0, 0, 0, 99999, "00:00:00.000099999"},
2197             {0, 0, 0, 9999, "00:00:00.000009999"},
2198             {0, 0, 0, 999, "00:00:00.000000999"},
2199             {0, 0, 0, 99, "00:00:00.000000099"},
2200             {0, 0, 0, 9, "00:00:00.000000009"},
2201         };
2202     }
2203 
2204     @Test(dataProvider="sampleToString", groups={"tck"})
2205     public void test_toString(int h, int m, int s, int n, String expected) {
2206         LocalTime t = LocalTime.of(h, m, s, n);
2207         String str = t.toString();
2208         assertEquals(str, expected);
2209     }
2210 
2211     //-----------------------------------------------------------------------
2212     // toString(DateTimeFormatter)
2213     //-----------------------------------------------------------------------
2214     @Test(groups={"tck"})
2215     public void test_toString_formatter() {
2216         DateTimeFormatter f = DateTimeFormatters.pattern("H m s");
2217         String t = LocalTime.of(11, 30, 45).toString(f);
2218         assertEquals(t, "11 30 45");
2219     }
2220 
2221     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2222     public void test_toString_formatter_null() {
2223         LocalTime.of(11, 30, 45).toString(null);
2224     }
2225 
2226 }