541 assertEquals(a.getSecond(), localTime.getSecond()); |
541 assertEquals(a.getSecond(), localTime.getSecond()); |
542 assertEquals(a.getNano(), localTime.getNano()); |
542 assertEquals(a.getNano(), localTime.getNano()); |
543 } |
543 } |
544 |
544 |
545 //----------------------------------------------------------------------- |
545 //----------------------------------------------------------------------- |
|
546 // isSupported(TemporalField) |
|
547 //----------------------------------------------------------------------- |
|
548 @Test |
|
549 public void test_isSupported_TemporalField() { |
|
550 assertEquals(TEST_11_30_59_500_PONE.isSupported((TemporalField) null), false); |
|
551 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.NANO_OF_SECOND), true); |
|
552 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.NANO_OF_DAY), true); |
|
553 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MICRO_OF_SECOND), true); |
|
554 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MICRO_OF_DAY), true); |
|
555 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MILLI_OF_SECOND), true); |
|
556 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MILLI_OF_DAY), true); |
|
557 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.SECOND_OF_MINUTE), true); |
|
558 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.SECOND_OF_DAY), true); |
|
559 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MINUTE_OF_HOUR), true); |
|
560 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MINUTE_OF_DAY), true); |
|
561 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.HOUR_OF_AMPM), true); |
|
562 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), true); |
|
563 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.HOUR_OF_DAY), true); |
|
564 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), true); |
|
565 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.AMPM_OF_DAY), true); |
|
566 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.DAY_OF_WEEK), false); |
|
567 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false); |
|
568 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false); |
|
569 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.DAY_OF_MONTH), false); |
|
570 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.DAY_OF_YEAR), false); |
|
571 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.EPOCH_DAY), false); |
|
572 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false); |
|
573 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false); |
|
574 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MONTH_OF_YEAR), false); |
|
575 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.PROLEPTIC_MONTH), false); |
|
576 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.YEAR), false); |
|
577 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.YEAR_OF_ERA), false); |
|
578 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ERA), false); |
|
579 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.INSTANT_SECONDS), false); |
|
580 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.OFFSET_SECONDS), true); |
|
581 } |
|
582 |
|
583 //----------------------------------------------------------------------- |
|
584 // isSupported(TemporalUnit) |
|
585 //----------------------------------------------------------------------- |
|
586 @Test |
|
587 public void test_isSupported_TemporalUnit() { |
|
588 assertEquals(TEST_11_30_59_500_PONE.isSupported((TemporalUnit) null), false); |
|
589 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.NANOS), true); |
|
590 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MICROS), true); |
|
591 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MILLIS), true); |
|
592 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.SECONDS), true); |
|
593 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MINUTES), true); |
|
594 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.HOURS), true); |
|
595 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.HALF_DAYS), true); |
|
596 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.DAYS), false); |
|
597 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.WEEKS), false); |
|
598 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MONTHS), false); |
|
599 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.YEARS), false); |
|
600 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.DECADES), false); |
|
601 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.CENTURIES), false); |
|
602 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MILLENNIA), false); |
|
603 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.ERAS), false); |
|
604 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.FOREVER), false); |
|
605 } |
|
606 |
|
607 //----------------------------------------------------------------------- |
546 // get(TemporalField) |
608 // get(TemporalField) |
547 //----------------------------------------------------------------------- |
609 //----------------------------------------------------------------------- |
548 @Test |
610 @Test |
549 public void test_get_TemporalField() { |
611 public void test_get_TemporalField() { |
550 OffsetTime test = OffsetTime.of(12, 30, 40, 987654321, OFFSET_PONE); |
612 OffsetTime test = OffsetTime.of(12, 30, 40, 987654321, OFFSET_PONE); |
1036 OffsetTime test = base.minusNanos(0); |
1098 OffsetTime test = base.minusNanos(0); |
1037 assertEquals(test, base); |
1099 assertEquals(test, base); |
1038 } |
1100 } |
1039 |
1101 |
1040 //----------------------------------------------------------------------- |
1102 //----------------------------------------------------------------------- |
1041 // periodUntil(Temporal, TemporalUnit) |
1103 // until(Temporal, TemporalUnit) |
1042 //----------------------------------------------------------------------- |
1104 //----------------------------------------------------------------------- |
1043 @DataProvider(name="periodUntilUnit") |
1105 @DataProvider(name="periodUntilUnit") |
1044 Object[][] data_periodUntilUnit() { |
1106 Object[][] data_periodUntilUnit() { |
1045 return new Object[][] { |
1107 return new Object[][] { |
1046 {OffsetTime.of(LocalTime.of(1, 1, 1), ZoneOffset.ofHours(1)), OffsetTime.of(LocalTime.of(13, 1, 1), ZoneOffset.ofHours(1)), HALF_DAYS, 1}, |
1108 {OffsetTime.of(LocalTime.of(1, 1, 1), ZoneOffset.ofHours(1)), OffsetTime.of(LocalTime.of(13, 1, 1), ZoneOffset.ofHours(1)), HALF_DAYS, 1}, |
1061 }; |
1123 }; |
1062 } |
1124 } |
1063 |
1125 |
1064 @Test(dataProvider="periodUntilUnit") |
1126 @Test(dataProvider="periodUntilUnit") |
1065 public void test_periodUntil_TemporalUnit(OffsetTime offsetTime1, OffsetTime offsetTime2, TemporalUnit unit, long expected) { |
1127 public void test_periodUntil_TemporalUnit(OffsetTime offsetTime1, OffsetTime offsetTime2, TemporalUnit unit, long expected) { |
1066 long amount = offsetTime1.periodUntil(offsetTime2, unit); |
1128 long amount = offsetTime1.until(offsetTime2, unit); |
1067 assertEquals(amount, expected); |
1129 assertEquals(amount, expected); |
1068 } |
1130 } |
1069 |
1131 |
1070 @Test(dataProvider="periodUntilUnit") |
1132 @Test(dataProvider="periodUntilUnit") |
1071 public void test_periodUntil_TemporalUnit_negated(OffsetTime offsetTime1, OffsetTime offsetTime2, TemporalUnit unit, long expected) { |
1133 public void test_periodUntil_TemporalUnit_negated(OffsetTime offsetTime1, OffsetTime offsetTime2, TemporalUnit unit, long expected) { |
1072 long amount = offsetTime2.periodUntil(offsetTime1, unit); |
1134 long amount = offsetTime2.until(offsetTime1, unit); |
1073 assertEquals(amount, -expected); |
1135 assertEquals(amount, -expected); |
1074 } |
1136 } |
1075 |
1137 |
1076 @Test(expectedExceptions=DateTimeException.class) |
1138 @Test(expectedExceptions=DateTimeException.class) |
1077 public void test_periodUntil_InvalidType() { |
1139 public void test_periodUntil_InvalidType() { |
1078 OffsetTime offsetTime = OffsetTime.of(LocalTime.of(1, 1, 1), ZoneOffset.ofHours(1)); |
1140 OffsetTime offsetTime = OffsetTime.of(LocalTime.of(1, 1, 1), ZoneOffset.ofHours(1)); |
1079 OffsetDateTime offsetDateTime = offsetTime.atDate(LocalDate.of(1980, 2, 10)); |
1141 OffsetDateTime offsetDateTime = offsetTime.atDate(LocalDate.of(1980, 2, 10)); |
1080 offsetTime.periodUntil(offsetDateTime, SECONDS); |
1142 offsetTime.until(offsetDateTime, SECONDS); |
1081 } |
1143 } |
1082 |
1144 |
1083 @Test(expectedExceptions=DateTimeException.class) |
1145 @Test(expectedExceptions=DateTimeException.class) |
1084 public void test_periodUntil_InvalidTemporalUnit() { |
1146 public void test_periodUntil_InvalidTemporalUnit() { |
1085 OffsetTime offsetTime1 = OffsetTime.of(LocalTime.of(1, 1, 1), ZoneOffset.ofHours(1)); |
1147 OffsetTime offsetTime1 = OffsetTime.of(LocalTime.of(1, 1, 1), ZoneOffset.ofHours(1)); |
1086 OffsetTime offsetTime2 = OffsetTime.of(LocalTime.of(2, 1, 1), ZoneOffset.ofHours(1)); |
1148 OffsetTime offsetTime2 = OffsetTime.of(LocalTime.of(2, 1, 1), ZoneOffset.ofHours(1)); |
1087 offsetTime1.periodUntil(offsetTime2, MONTHS); |
1149 offsetTime1.until(offsetTime2, MONTHS); |
1088 } |
1150 } |
1089 |
1151 |
1090 //----------------------------------------------------------------------- |
1152 //----------------------------------------------------------------------- |
1091 // format(DateTimeFormatter) |
1153 // format(DateTimeFormatter) |
1092 //----------------------------------------------------------------------- |
1154 //----------------------------------------------------------------------- |