use of java.time.temporal.TemporalAmount in project jdk8u_jdk by JetBrains.
the class TCKChronoLocalDateTime method test_badMinusAdjusterChrono.
@Test(dataProvider = "calendars")
public void test_badMinusAdjusterChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
TemporalAmount adjuster = new FixedAdjuster(cdt2);
if (chrono != chrono2) {
try {
cdt.minus(adjuster);
Assert.fail("WithAdjuster should have thrown a ClassCastException, " + "required: " + cdt + ", supplied: " + cdt2);
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoLocalDateTime<?> result = cdt.minus(adjuster);
assertEquals(result, cdt2, "WithAdjuster failed to replace date");
}
}
}
use of java.time.temporal.TemporalAmount in project jdk8u_jdk by JetBrains.
the class TCKLocalTime method test_minus_TemporalAmount_positiveHours.
//-----------------------------------------------------------------------
// minus(TemporalAmount)
//-----------------------------------------------------------------------
@Test
public void test_minus_TemporalAmount_positiveHours() {
TemporalAmount period = MockSimplePeriod.of(7, ChronoUnit.HOURS);
LocalTime t = TEST_12_30_40_987654321.minus(period);
assertEquals(t, LocalTime.of(5, 30, 40, 987654321));
}
use of java.time.temporal.TemporalAmount in project jdk8u_jdk by JetBrains.
the class TCKLocalTime method test_minus_TemporalAmount_zero.
@Test
public void test_minus_TemporalAmount_zero() {
TemporalAmount period = Period.ZERO;
LocalTime t = TEST_12_30_40_987654321.minus(period);
assertEquals(t, TEST_12_30_40_987654321);
}
use of java.time.temporal.TemporalAmount 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.TemporalAmount in project jdk8u_jdk by JetBrains.
the class TCKDuration method factory_from_TemporalAmount_DaysNanos.
@Test
public void factory_from_TemporalAmount_DaysNanos() {
TemporalAmount amount = new TemporalAmount() {
@Override
public long get(TemporalUnit unit) {
if (unit == DAYS) {
return 23;
} else {
return 45;
}
}
@Override
public List<TemporalUnit> getUnits() {
List<TemporalUnit> list = new ArrayList<>();
list.add(DAYS);
list.add(NANOS);
return list;
}
@Override
public Temporal addTo(Temporal temporal) {
throw new UnsupportedOperationException();
}
@Override
public Temporal subtractFrom(Temporal temporal) {
throw new UnsupportedOperationException();
}
};
Duration t = Duration.from(amount);
assertEquals(t.getSeconds(), 23 * 86400);
assertEquals(t.getNano(), 45);
}
Aggregations