use of java.time.temporal.TemporalUnit in project jdk8u_jdk by JetBrains.
the class TCKPeriod method test_minus_TemporalAmount_DaysHours.
@Test(expectedExceptions = DateTimeException.class)
public void test_minus_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();
}
};
pymd(4, 5, 6).minus(amount);
}
use of java.time.temporal.TemporalUnit in project jdk8u_jdk by JetBrains.
the class TCKLocalTime method test_minus_longTemporalUnit_invalidUnit.
@Test
public void test_minus_longTemporalUnit_invalidUnit() {
for (TemporalUnit unit : INVALID_UNITS) {
try {
TEST_12_30_40_987654321.minus(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 TCKPeriod method factory_from_TemporalAmount_Years_tooBig.
@Test(expectedExceptions = ArithmeticException.class)
public void factory_from_TemporalAmount_Years_tooBig() {
TemporalAmount amount = new TemporalAmount() {
@Override
public long get(TemporalUnit unit) {
return ((long) (Integer.MAX_VALUE)) + 1;
}
@Override
public List<TemporalUnit> getUnits() {
return Collections.<TemporalUnit>singletonList(YEARS);
}
@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 TCKPeriod method factory_from_TemporalAmount_YearsDays.
@Test
public void factory_from_TemporalAmount_YearsDays() {
TemporalAmount amount = new TemporalAmount() {
@Override
public long get(TemporalUnit unit) {
if (unit == YEARS) {
return 23;
} else {
return 45;
}
}
@Override
public List<TemporalUnit> getUnits() {
List<TemporalUnit> list = new ArrayList<>();
list.add(YEARS);
list.add(DAYS);
return list;
}
@Override
public Temporal addTo(Temporal temporal) {
throw new UnsupportedOperationException();
}
@Override
public Temporal subtractFrom(Temporal temporal) {
throw new UnsupportedOperationException();
}
};
assertPeriod(Period.from(amount), 23, 0, 45);
}
use of java.time.temporal.TemporalUnit in project jdk8u_jdk by JetBrains.
the class TCKPeriod method test_plus_TemporalAmount_DaysHours.
@Test(expectedExceptions = DateTimeException.class)
public void test_plus_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();
}
};
pymd(4, 5, 6).plus(amount);
}
Aggregations