use of java.time.DateTimeException 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.DateTimeException in project jdk8u_jdk by JetBrains.
the class TCKZoneId method factory_from_TemporalAccessor_zoneId.
//-----------------------------------------------------------------------
// from(TemporalAccessor)
//-----------------------------------------------------------------------
@Test
public void factory_from_TemporalAccessor_zoneId() {
TemporalAccessor mock = new TemporalAccessor() {
@Override
public boolean isSupported(TemporalField field) {
return false;
}
@Override
public long getLong(TemporalField field) {
throw new DateTimeException("Mock");
}
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQueries.zoneId()) {
return (R) ZoneId.of("Europe/Paris");
}
return TemporalAccessor.super.query(query);
}
};
assertEquals(ZoneId.from(mock), ZoneId.of("Europe/Paris"));
}
use of java.time.DateTimeException in project jdk8u_jdk by JetBrains.
the class TestDateTimeBuilderCombinations method test_derive.
@Test(dataProvider = "combine")
public void test_derive(final TemporalField field1, final Number value1, final TemporalField field2, final Number value2, final TemporalField field3, final Number value3, final TemporalField field4, final Number value4, Class<?> query, Object expectedVal) {
// mock for testing that does not fully comply with TemporalAccessor contract
TemporalAccessor test = new TemporalAccessor() {
@Override
public boolean isSupported(TemporalField field) {
return field == field1 || field == field2 || field == field3 || field == field4;
}
@Override
public long getLong(TemporalField field) {
if (field == field1) {
return value1.longValue();
}
if (field == field2) {
return value2.longValue();
}
if (field == field3) {
return value3.longValue();
}
if (field == field4) {
return value4.longValue();
}
throw new DateTimeException("Unsupported");
}
};
String str = "";
DateTimeFormatterBuilder dtfb = new DateTimeFormatterBuilder();
dtfb.appendValue(field1).appendLiteral('-');
str += value1 + "-";
if (field2 != null) {
dtfb.appendValue(field2).appendLiteral('-');
str += value2 + "-";
}
if (field3 != null) {
dtfb.appendValue(field3).appendLiteral('-');
str += value3 + "-";
}
if (field4 != null) {
dtfb.appendValue(field4).appendLiteral('-');
str += value4 + "-";
}
TemporalAccessor parsed = dtfb.toFormatter().parse(str);
if (query == LocalDate.class) {
if (expectedVal != null) {
assertEquals(parsed.query(LocalDate::from), expectedVal);
} else {
try {
parsed.query(LocalDate::from);
fail();
} catch (DateTimeException ex) {
// expected
}
}
} else {
throw new IllegalArgumentException();
}
}
use of java.time.DateTimeException in project jdk8u_jdk by JetBrains.
the class TCKInstantPrinterParser method test_parse_digitsNine.
@Test(dataProvider = "parseDigits")
public void test_parse_digitsNine(long instantSecs, int nano, String input) {
DateTimeFormatter f = new DateTimeFormatterBuilder().appendInstant(9).toFormatter();
if (input.charAt(input.length() - 11) == '.') {
Instant expected = Instant.ofEpochSecond(instantSecs, nano);
assertEquals(f.parse(input, Instant::from), expected);
assertEquals(f.parse(input).query(DateTimeFormatter.parsedExcessDays()), Period.ZERO);
assertEquals(f.parse(input).query(DateTimeFormatter.parsedLeapSecond()), Boolean.FALSE);
} else {
try {
f.parse(input, Instant::from);
fail();
} catch (DateTimeException ex) {
// expected
}
}
}
use of java.time.DateTimeException in project jdk8u_jdk by JetBrains.
the class TCKHijrahChronology method test_resolve_ymd_smart.
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_smart(int y, int m, int d, HijrahDate expected, Object smart, boolean strict) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.YEAR, (long) y);
fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
if (Boolean.TRUE.equals(smart)) {
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
assertEquals(date, expected);
assertEquals(fieldValues.size(), 0);
} else if (smart instanceof HijrahDate) {
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
assertEquals(date, smart);
} else {
try {
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
fail("Should have failed, returned: " + date);
} catch (DateTimeException ex) {
// expected
}
}
}
Aggregations