use of java.time.temporal.TemporalUnit in project jdk8u_jdk by JetBrains.
the class TCKPeriod method factory_from_TemporalAmount_DaysHours.
@Test(expectedExceptions = DateTimeException.class)
public void factory_from_TemporalAmount_DaysHours() {
TemporalAmount amount = new TemporalAmount() {
@Override
public long get(TemporalUnit unit) {
if (unit == DAYS) {
return 1;
} else {
return 2;
}
}
@Override
public List<TemporalUnit> getUnits() {
List<TemporalUnit> list = new ArrayList<>();
list.add(DAYS);
list.add(HOURS);
return list;
}
@Override
public Temporal addTo(Temporal temporal) {
throw new UnsupportedOperationException();
}
@Override
public Temporal subtractFrom(Temporal temporal) {
throw new UnsupportedOperationException();
}
};
Period.from(amount);
}
use of java.time.temporal.TemporalUnit in project jdk8u_jdk by JetBrains.
the class TCKLocalTime method test_plus_longTemporalUnit_invalidUnit.
@Test
public void test_plus_longTemporalUnit_invalidUnit() {
for (TemporalUnit unit : INVALID_UNITS) {
try {
TEST_12_30_40_987654321.plus(1, unit);
fail("Unit should not be allowed " + unit);
} catch (DateTimeException ex) {
// expected
}
}
}
use of java.time.temporal.TemporalUnit in project jdk8u_jdk by JetBrains.
the class TCKDuration method test_duration_getUnits.
//-----------------------------------------------------------------------
@Test(groups = "{tck}")
public void test_duration_getUnits() {
Duration duration = Duration.ofSeconds(5000, 1000);
List<TemporalUnit> units = duration.getUnits();
assertEquals(units.size(), 2, "Period.getUnits length");
assertTrue(units.contains(ChronoUnit.SECONDS), "Period.getUnits contains ChronoUnit.SECONDS");
assertTrue(units.contains(ChronoUnit.NANOS), "contains ChronoUnit.NANOS");
}
use of java.time.temporal.TemporalUnit in project jdk8u_jdk by JetBrains.
the class TCKPeriod method test_Period_getUnits.
//-----------------------------------------------------------------------
// get units
//-----------------------------------------------------------------------
@Test
public void test_Period_getUnits() {
Period period = Period.of(2012, 1, 1);
List<TemporalUnit> units = period.getUnits();
assertEquals(units.size(), 3, "Period.getUnits should return 3 units");
assertEquals(units.get(0), ChronoUnit.YEARS, "Period.getUnits contains ChronoUnit.YEARS");
assertEquals(units.get(1), ChronoUnit.MONTHS, "Period.getUnits contains ChronoUnit.MONTHS");
assertEquals(units.get(2), ChronoUnit.DAYS, "Period.getUnits contains ChronoUnit.DAYS");
}
use of java.time.temporal.TemporalUnit in project jdk8u_jdk by JetBrains.
the class TCKChronoZonedDateTime method test_badMinusTemporalUnitChrono.
@Test(dataProvider = "calendars")
public void test_badMinusTemporalUnitChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
TemporalUnit adjuster = new FixedTemporalUnit(czdt2);
if (chrono != chrono2) {
try {
czdt.minus(1, adjuster);
Assert.fail("TemporalUnit.doPlus minus should have thrown a ClassCastException, " + czdt.getClass() + " can not be cast to " + czdt2.getClass());
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoZonedDateTime<?> result = czdt.minus(1, adjuster);
assertEquals(result, czdt2, "WithAdjuster failed to replace date");
}
}
}
Aggregations