test/java/time/tck/java/time/TCKLocalTime.java

Print this page




  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);


 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()


 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);


 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},


 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);


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 


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);


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 }


  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.time.Clock;
  96 import java.time.DateTimeException;
  97 import java.time.Duration;
  98 import java.time.Instant;
  99 import java.time.LocalDate;
 100 import java.time.LocalDateTime;
 101 import java.time.LocalTime;
 102 import java.time.OffsetTime;
 103 import java.time.Period;
 104 import java.time.ZoneId;
 105 import java.time.ZoneOffset;
 106 import java.time.format.DateTimeFormatter;

 107 import java.time.format.DateTimeParseException;
 108 import java.time.temporal.ChronoField;
 109 import java.time.temporal.ChronoUnit;
 110 import java.time.temporal.JulianFields;

 111 import java.time.temporal.Queries;
 112 import java.time.temporal.Temporal;
 113 import java.time.temporal.TemporalAccessor;

 114 import java.time.temporal.TemporalAdjuster;
 115 import java.time.temporal.TemporalAmount;
 116 import java.time.temporal.TemporalField;
 117 import java.time.temporal.TemporalQuery;
 118 import java.time.temporal.TemporalUnit;
 119 import java.util.ArrayList;
 120 import java.util.Arrays;
 121 import java.util.EnumSet;
 122 import java.util.Iterator;
 123 import java.util.List;
 124 
 125 import org.testng.annotations.BeforeMethod;
 126 import org.testng.annotations.DataProvider;
 127 import org.testng.annotations.Test;

 128 
 129 /**
 130  * Test LocalTime.
 131  */
 132 @Test
 133 public class TCKLocalTime extends AbstractDateTimeTest {
 134 
 135     private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2);
 136 
 137     private LocalTime TEST_12_30_40_987654321;
 138 
 139     private static final TemporalUnit[] INVALID_UNITS;
 140     static {
 141         EnumSet<ChronoUnit> set = EnumSet.range(WEEKS, FOREVER);
 142         INVALID_UNITS = (TemporalUnit[]) set.toArray(new TemporalUnit[set.size()]);
 143     }
 144 
 145     @BeforeMethod(groups={"tck","implementation"})
 146     public void setUp() {
 147         TEST_12_30_40_987654321 = LocalTime.of(12, 30, 40, 987654321);


 485     //-----------------------------------------------------------------------
 486     // ofSecondOfDay(long)
 487     //-----------------------------------------------------------------------
 488     @Test(groups={"tck"})
 489     public void factory_ofSecondOfDay() {
 490         LocalTime localTime = LocalTime.ofSecondOfDay(2 * 60 * 60 + 17 * 60 + 23);
 491         check(localTime, 2, 17, 23, 0);
 492     }
 493 
 494     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 495     public void factory_ofSecondOfDay_tooLow() {
 496         LocalTime.ofSecondOfDay(-1);
 497     }
 498 
 499     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 500     public void factory_ofSecondOfDay_tooHigh() {
 501         LocalTime.ofSecondOfDay(24 * 60 * 60);
 502     }
 503 
 504     //-----------------------------------------------------------------------





























 505     // ofNanoOfDay(long)
 506     //-----------------------------------------------------------------------
 507     @Test(groups={"tck"})
 508     public void factory_ofNanoOfDay() {
 509         LocalTime localTime = LocalTime.ofNanoOfDay(60 * 60 * 1000000000L + 17);
 510         check(localTime, 1, 0, 0, 17);
 511     }
 512 
 513     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 514     public void factory_ofNanoOfDay_tooLow() {
 515         LocalTime.ofNanoOfDay(-1);
 516     }
 517 
 518     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 519     public void factory_ofNanoOfDay_tooHigh() {
 520         LocalTime.ofNanoOfDay(24 * 60 * 60 * 1000000000L);
 521     }
 522 
 523     //-----------------------------------------------------------------------
 524     // from()


 582     public void factory_parse_illegalMinute() {
 583         LocalTime.parse("12:60");
 584     }
 585 
 586     @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"})
 587     public void factory_parse_illegalSecond() {
 588         LocalTime.parse("12:12:60");
 589     }
 590 
 591     //-----------------------------------------------------------------------s
 592     @Test(expectedExceptions = {NullPointerException.class}, groups={"tck"})
 593     public void factory_parse_nullTest() {
 594         LocalTime.parse((String) null);
 595     }
 596 
 597     //-----------------------------------------------------------------------
 598     // parse(DateTimeFormatter)
 599     //-----------------------------------------------------------------------
 600     @Test(groups={"tck"})
 601     public void factory_parse_formatter() {
 602         DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s");
 603         LocalTime test = LocalTime.parse("14 30 40", f);
 604         assertEquals(test, LocalTime.of(14, 30, 40));
 605     }
 606 
 607     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 608     public void factory_parse_formatter_nullText() {
 609         DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s");
 610         LocalTime.parse((String) null, f);
 611     }
 612 
 613     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 614     public void factory_parse_formatter_nullFormatter() {
 615         LocalTime.parse("ANY", null);
 616     }
 617 
 618     //-----------------------------------------------------------------------
 619     // get(TemporalField)
 620     //-----------------------------------------------------------------------
 621     @Test
 622     public void test_get_TemporalField() {
 623         LocalTime test = TEST_12_30_40_987654321;
 624         assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12);
 625         assertEquals(test.get(ChronoField.MINUTE_OF_HOUR), 30);
 626         assertEquals(test.get(ChronoField.SECOND_OF_MINUTE), 40);
 627         assertEquals(test.get(ChronoField.NANO_OF_SECOND), 987654321);
 628 
 629         assertEquals(test.get(ChronoField.SECOND_OF_DAY), 12 * 3600 + 30 * 60 + 40);


 636 
 637     @Test
 638     public void test_getLong_TemporalField() {
 639         LocalTime test = TEST_12_30_40_987654321;
 640         assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12);
 641         assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30);
 642         assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40);
 643         assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321);
 644 
 645         assertEquals(test.getLong(ChronoField.SECOND_OF_DAY), 12 * 3600 + 30 * 60 + 40);
 646         assertEquals(test.getLong(ChronoField.MINUTE_OF_DAY), 12 * 60 + 30);
 647         assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0);
 648         assertEquals(test.getLong(ChronoField.CLOCK_HOUR_OF_AMPM), 12);
 649         assertEquals(test.getLong(ChronoField.CLOCK_HOUR_OF_DAY), 12);
 650         assertEquals(test.getLong(ChronoField.AMPM_OF_DAY), 1);
 651     }
 652 
 653     //-----------------------------------------------------------------------
 654     // query(TemporalQuery)
 655     //-----------------------------------------------------------------------
 656     @DataProvider(name="query")
 657     Object[][] data_query() {
 658         return new Object[][] {
 659                 {TEST_12_30_40_987654321, Queries.chronology(), null},
 660                 {TEST_12_30_40_987654321, Queries.zoneId(), null},
 661                 {TEST_12_30_40_987654321, Queries.precision(), ChronoUnit.NANOS},
 662                 {TEST_12_30_40_987654321, Queries.zone(), null},
 663                 {TEST_12_30_40_987654321, Queries.offset(), null},
 664                 {TEST_12_30_40_987654321, Queries.localDate(), null},
 665                 {TEST_12_30_40_987654321, Queries.localTime(), TEST_12_30_40_987654321},
 666         };
 667     }
 668 
 669     @Test(dataProvider="query")
 670     public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 671         assertEquals(temporal.query(query), expected);

 672     }
 673 
 674     @Test(dataProvider="query")
 675     public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 676         assertEquals(query.queryFrom(temporal), expected);







 677     }
 678 
 679     @Test(expectedExceptions=NullPointerException.class)
 680     public void test_query_null() {
 681         TEST_12_30_40_987654321.query(null);
 682     }
 683 
 684     //-----------------------------------------------------------------------
 685     // get*()
 686     //-----------------------------------------------------------------------
 687     @DataProvider(name="sampleTimes")
 688     Object[][] provider_sampleTimes() {
 689         return new Object[][] {
 690             {0, 0, 0, 0},
 691             {0, 0, 0, 1},
 692             {0, 0, 1, 0},
 693             {0, 0, 1, 1},
 694             {0, 1, 0, 0},
 695             {0, 1, 0, 1},
 696             {0, 1, 1, 0},


 886 
 887     @Test(groups={"tck"})
 888     public void test_withNanoOfSecond_toMidday_equal() {
 889         LocalTime t = LocalTime.of(12, 0, 0, 1).withNano(0);
 890         assertEquals(t, LocalTime.NOON);
 891     }
 892 
 893     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 894     public void test_withNanoOfSecond_nanoTooLow() {
 895         TEST_12_30_40_987654321.withNano(-1);
 896     }
 897 
 898     @Test(expectedExceptions=DateTimeException.class, groups={"tck"})
 899     public void test_withNanoOfSecond_nanoTooHigh() {
 900         TEST_12_30_40_987654321.withNano(1000000000);
 901     }
 902 
 903     //-----------------------------------------------------------------------
 904     // truncated(TemporalUnit)
 905     //-----------------------------------------------------------------------
 906     TemporalUnit NINETY_MINS = new TemporalUnit() {
 907         @Override
 908         public String getName() {
 909             return "NinetyMins";
 910         }
 911         @Override
 912         public Duration getDuration() {
 913             return Duration.ofMinutes(90);
 914         }
 915         @Override
 916         public boolean isDurationEstimated() {
 917             return false;
 918         }
 919         @Override
 920         public boolean isSupportedBy(Temporal temporal) {
 921             return false;
 922         }
 923         @Override
 924         public <R extends Temporal> R addTo(R temporal, long amount) {
 925             throw new UnsupportedOperationException();
 926         }
 927         @Override
 928         public long between(Temporal temporal1, Temporal temporal2) {
 929             throw new UnsupportedOperationException();
 930         }
 931     };
 932 
 933     TemporalUnit NINETY_FIVE_MINS = new TemporalUnit() {
 934         @Override
 935         public String getName() {
 936             return "NinetyFiveMins";
 937         }
 938         @Override
 939         public Duration getDuration() {
 940             return Duration.ofMinutes(95);
 941         }
 942         @Override
 943         public boolean isDurationEstimated() {
 944             return false;
 945         }
 946         @Override
 947         public boolean isSupportedBy(Temporal temporal) {
 948             return false;
 949         }
 950         @Override
 951         public <R extends Temporal> R addTo(R temporal, long amount) {
 952             throw new UnsupportedOperationException();
 953         }
 954         @Override
 955         public long between(Temporal temporal1, Temporal temporal2) {
 956             throw new UnsupportedOperationException();
 957         }
 958     };
 959 
 960     @DataProvider(name="truncatedToValid")
 961     Object[][] data_truncatedToValid() {
 962         return new Object[][] {
 963             {LocalTime.of(1, 2, 3, 123_456_789), NANOS, LocalTime.of(1, 2, 3, 123_456_789)},
 964             {LocalTime.of(1, 2, 3, 123_456_789), MICROS, LocalTime.of(1, 2, 3, 123_456_000)},
 965             {LocalTime.of(1, 2, 3, 123_456_789), MILLIS, LocalTime.of(1, 2, 3, 1230_00_000)},
 966             {LocalTime.of(1, 2, 3, 123_456_789), SECONDS, LocalTime.of(1, 2, 3)},
 967             {LocalTime.of(1, 2, 3, 123_456_789), MINUTES, LocalTime.of(1, 2)},
 968             {LocalTime.of(1, 2, 3, 123_456_789), HOURS, LocalTime.of(1, 0)},
 969             {LocalTime.of(1, 2, 3, 123_456_789), DAYS, LocalTime.MIDNIGHT},
 970 
 971             {LocalTime.of(1, 1, 1, 123_456_789), NINETY_MINS, LocalTime.of(0, 0)},
 972             {LocalTime.of(2, 1, 1, 123_456_789), NINETY_MINS, LocalTime.of(1, 30)},
 973             {LocalTime.of(3, 1, 1, 123_456_789), NINETY_MINS, LocalTime.of(3, 0)},
 974         };
 975     }
 976 
 977     @Test(groups={"tck"}, dataProvider="truncatedToValid")
 978     public void test_truncatedTo_valid(LocalTime input, TemporalUnit unit, LocalTime expected) {
 979         assertEquals(input.truncatedTo(unit), expected);
 980     }
 981 
 982     @DataProvider(name="truncatedToInvalid")
 983     Object[][] data_truncatedToInvalid() {
 984         return new Object[][] {
 985             {LocalTime.of(1, 2, 3, 123_456_789), NINETY_FIVE_MINS},
 986             {LocalTime.of(1, 2, 3, 123_456_789), WEEKS},
 987             {LocalTime.of(1, 2, 3, 123_456_789), MONTHS},
 988             {LocalTime.of(1, 2, 3, 123_456_789), YEARS},
 989         };
 990     }
 991 
 992     @Test(groups={"tck"}, dataProvider="truncatedToInvalid", expectedExceptions=DateTimeException.class)
 993     public void test_truncatedTo_invalid(LocalTime input, TemporalUnit unit) {
 994         input.truncatedTo(unit);
 995     }
 996 
 997     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
 998     public void test_truncatedTo_null() {
 999         TEST_12_30_40_987654321.truncatedTo(null);
1000     }
1001 
1002     //-----------------------------------------------------------------------
1003     // plus(TemporalAmount)
1004     //-----------------------------------------------------------------------
1005     @Test
1006     public void test_plus_TemporalAmount_positiveHours() {
1007         TemporalAmount period = MockSimplePeriod.of(7, ChronoUnit.HOURS);
1008         LocalTime t = TEST_12_30_40_987654321.plus(period);
1009         assertEquals(t, LocalTime.of(19, 30, 40, 987654321));
1010     }
1011 
1012     @Test
1013     public void test_plus_TemporalAmount_negativeMinutes() {
1014         TemporalAmount period = MockSimplePeriod.of(-25, ChronoUnit.MINUTES);
1015         LocalTime t = TEST_12_30_40_987654321.plus(period);
1016         assertEquals(t, LocalTime.of(12, 5, 40, 987654321));
1017     }
1018 
1019     @Test
1020     public void test_plus_TemporalAmount_zero() {
1021         TemporalAmount period = Period.ZERO;
1022         LocalTime t = TEST_12_30_40_987654321.plus(period);
1023         assertEquals(t, TEST_12_30_40_987654321);
1024     }
1025 
1026     @Test
1027     public void test_plus_TemporalAmount_wrap() {
1028         TemporalAmount p = MockSimplePeriod.of(1, HOURS);
1029         LocalTime t = LocalTime.of(23, 30).plus(p);
1030         assertEquals(t, LocalTime.of(0, 30));
1031     }
1032 
1033     @Test(expectedExceptions=DateTimeException.class)
1034     public void test_plus_TemporalAmount_dateNotAllowed() {
1035         TemporalAmount period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
1036         TEST_12_30_40_987654321.plus(period);
1037     }
1038 
1039     @Test(expectedExceptions=NullPointerException.class)
1040     public void test_plus_TemporalAmount_null() {
1041         TEST_12_30_40_987654321.plus((TemporalAmount) null);
1042     }
1043 
1044     //-----------------------------------------------------------------------
1045     // plus(long,TemporalUnit)
1046     //-----------------------------------------------------------------------
1047     @Test(groups={"tck"})
1048     public void test_plus_longTemporalUnit_positiveHours() {
1049         LocalTime t = TEST_12_30_40_987654321.plus(7, ChronoUnit.HOURS);
1050         assertEquals(t, LocalTime.of(19, 30, 40, 987654321));
1051     }
1052 
1053     @Test(groups={"tck"})
1054     public void test_plus_longTemporalUnit_negativeMinutes() {
1055         LocalTime t = TEST_12_30_40_987654321.plus(-25, ChronoUnit.MINUTES);
1056         assertEquals(t, LocalTime.of(12, 5, 40, 987654321));
1057     }
1058 
1059     @Test(groups={"tck"})
1060     public void test_plus_longTemporalUnit_zero() {
1061         LocalTime t = TEST_12_30_40_987654321.plus(0, ChronoUnit.MINUTES);


1071             } catch (DateTimeException ex) {
1072                 // expected
1073             }
1074         }
1075     }
1076 
1077     @Test(groups={"tck"})
1078     public void test_plus_longTemporalUnit_multiples() {
1079         assertEquals(TEST_12_30_40_987654321.plus(0, DAYS), TEST_12_30_40_987654321);
1080         assertEquals(TEST_12_30_40_987654321.plus(1, DAYS), TEST_12_30_40_987654321);
1081         assertEquals(TEST_12_30_40_987654321.plus(2, DAYS), TEST_12_30_40_987654321);
1082         assertEquals(TEST_12_30_40_987654321.plus(-3, DAYS), TEST_12_30_40_987654321);
1083     }
1084 
1085     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
1086     public void test_plus_longTemporalUnit_null() {
1087         TEST_12_30_40_987654321.plus(1, (TemporalUnit) null);
1088     }
1089 
1090     //-----------------------------------------------------------------------



































1091     // plusHours()
1092     //-----------------------------------------------------------------------
1093     @Test(groups={"tck"})
1094     public void test_plusHours_one() {
1095         LocalTime t = LocalTime.MIDNIGHT;
1096         for (int i = 0; i < 50; i++) {
1097             t = t.plusHours(1);
1098             assertEquals(t.getHour(), (i + 1) % 24);
1099         }
1100     }
1101 
1102     @Test(groups={"tck"})
1103     public void test_plusHours_fromZero() {
1104         LocalTime base = LocalTime.MIDNIGHT;
1105         for (int i = -50; i < 50; i++) {
1106             LocalTime t = base.plusHours(i);
1107             assertEquals(t.getHour(), (i + 72) % 24);
1108         }
1109     }
1110 


1417 
1418     @Test(groups={"tck"})
1419     public void test_plusNanos_noChange_oneDay_equal() {
1420         LocalTime t = TEST_12_30_40_987654321.plusNanos(24 * 60 * 60 * 1000000000L);
1421         assertEquals(t, TEST_12_30_40_987654321);
1422     }
1423 
1424     @Test(groups={"tck"})
1425     public void test_plusNanos_toMidnight_equal() {
1426         LocalTime t = LocalTime.of(23, 59, 59, 999999999).plusNanos(1);
1427         assertEquals(t, LocalTime.MIDNIGHT);
1428     }
1429 
1430     @Test(groups={"tck"})
1431     public void test_plusNanos_toMidday_equal() {
1432         LocalTime t = LocalTime.of(11, 59, 59, 999999999).plusNanos(1);
1433         assertEquals(t, LocalTime.NOON);
1434     }
1435 
1436     //-----------------------------------------------------------------------
1437     // minus(TemporalAmount)
1438     //-----------------------------------------------------------------------
1439     @Test
1440     public void test_minus_TemporalAmount_positiveHours() {
1441         TemporalAmount period = MockSimplePeriod.of(7, ChronoUnit.HOURS);







1442         LocalTime t = TEST_12_30_40_987654321.minus(period);
1443         assertEquals(t, LocalTime.of(5, 30, 40, 987654321));
1444     }
1445 
1446     @Test
1447     public void test_minus_TemporalAmount_negativeMinutes() {
1448         TemporalAmount period = MockSimplePeriod.of(-25, ChronoUnit.MINUTES);
1449         LocalTime t = TEST_12_30_40_987654321.minus(period);
1450         assertEquals(t, LocalTime.of(12, 55, 40, 987654321));
1451     }
1452 
1453     @Test
1454     public void test_minus_TemporalAmount_zero() {
1455         TemporalAmount period = Period.ZERO;
1456         LocalTime t = TEST_12_30_40_987654321.minus(period);







1457         assertEquals(t, TEST_12_30_40_987654321);
1458     }
1459 
1460     @Test
1461     public void test_minus_TemporalAmount_wrap() {
1462         TemporalAmount p = MockSimplePeriod.of(1, HOURS);
1463         LocalTime t = LocalTime.of(0, 30).minus(p);
1464         assertEquals(t, LocalTime.of(23, 30));
1465     }
1466 
1467     @Test(expectedExceptions=DateTimeException.class)
1468     public void test_minus_TemporalAmount_dateNotAllowed() {
1469         TemporalAmount period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
1470         TEST_12_30_40_987654321.minus(period);
1471     }
1472 
1473     @Test(expectedExceptions=NullPointerException.class)
1474     public void test_minus_TemporalAmount_null() {
1475         TEST_12_30_40_987654321.minus((TemporalAmount) null);
1476     }
1477 
1478     //-----------------------------------------------------------------------
1479     // minus(long,TemporalUnit)
1480     //-----------------------------------------------------------------------
1481     @Test(groups={"tck"})
1482     public void test_minus_longTemporalUnit_positiveHours() {
1483         LocalTime t = TEST_12_30_40_987654321.minus(7, ChronoUnit.HOURS);
1484         assertEquals(t, LocalTime.of(5, 30, 40, 987654321));
1485     }
1486 
1487     @Test(groups={"tck"})
1488     public void test_minus_longTemporalUnit_negativeMinutes() {
1489         LocalTime t = TEST_12_30_40_987654321.minus(-25, ChronoUnit.MINUTES);
1490         assertEquals(t, LocalTime.of(12, 55, 40, 987654321));
1491     }
1492 
1493     @Test(groups={"tck"})
1494     public void test_minus_longTemporalUnit_zero() {
1495         LocalTime t = TEST_12_30_40_987654321.minus(0, ChronoUnit.MINUTES);


2167             {0, 0, 0, 99999, "00:00:00.000099999"},
2168             {0, 0, 0, 9999, "00:00:00.000009999"},
2169             {0, 0, 0, 999, "00:00:00.000000999"},
2170             {0, 0, 0, 99, "00:00:00.000000099"},
2171             {0, 0, 0, 9, "00:00:00.000000009"},
2172         };
2173     }
2174 
2175     @Test(dataProvider="sampleToString", groups={"tck"})
2176     public void test_toString(int h, int m, int s, int n, String expected) {
2177         LocalTime t = LocalTime.of(h, m, s, n);
2178         String str = t.toString();
2179         assertEquals(str, expected);
2180     }
2181 
2182     //-----------------------------------------------------------------------
2183     // toString(DateTimeFormatter)
2184     //-----------------------------------------------------------------------
2185     @Test(groups={"tck"})
2186     public void test_toString_formatter() {
2187         DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s");
2188         String t = LocalTime.of(11, 30, 45).toString(f);
2189         assertEquals(t, "11 30 45");
2190     }
2191 
2192     @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
2193     public void test_toString_formatter_null() {
2194         LocalTime.of(11, 30, 45).toString(null);
2195     }
2196 
2197 }