use of java.time.format.ResolverStyle in project jdk8u_jdk by JetBrains.
the class TCKHijrahChronology method data_resolve_styles.
@DataProvider(name = "resolve_styles")
Object[][] data_resolve_styles() {
Object[][] result = new Object[ResolverStyle.values().length][];
int i = 0;
for (ResolverStyle style : ResolverStyle.values()) {
result[i++] = new Object[] { style };
}
return result;
}
use of java.time.format.ResolverStyle in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_resolveFourToTime.
@Test(dataProvider = "resolveFourToTime")
public void test_resolveFourToTime(ResolverStyle style, long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) {
DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(HOUR_OF_DAY, hour).parseDefaulting(MINUTE_OF_HOUR, min).parseDefaulting(SECOND_OF_MINUTE, sec).parseDefaulting(NANO_OF_SECOND, nano).toFormatter();
ResolverStyle[] styles = (style != null ? new ResolverStyle[] { style } : ResolverStyle.values());
for (ResolverStyle s : styles) {
if (expectedTime != null) {
TemporalAccessor accessor = f.withResolverStyle(s).parse("");
assertEquals(accessor.query(TemporalQueries.localDate()), null, "ResolverStyle: " + s);
assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime, "ResolverStyle: " + s);
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), excessPeriod, "ResolverStyle: " + s);
} else {
try {
f.withResolverStyle(style).parse("");
fail();
} catch (DateTimeParseException ex) {
// expected
}
}
}
}
use of java.time.format.ResolverStyle in project jdk8u_jdk by JetBrains.
the class TCKJapaneseChronology method test_resolve_yearOfEra_eraOnly_invalidTooLarge.
public void test_resolve_yearOfEra_eraOnly_invalidTooLarge() {
for (ResolverStyle style : ResolverStyle.values()) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.ERA, JapaneseEra.values()[JapaneseEra.values().length - 1].getValue() + 1L);
try {
JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
fail("Should have failed: " + style);
} catch (DateTimeException ex) {
// expected
}
}
}
use of java.time.format.ResolverStyle in project jdk8u_jdk by JetBrains.
the class TCKJapaneseChronology method test_resolve_yearOfEra_eraOnly_invalidTooSmall.
public void test_resolve_yearOfEra_eraOnly_invalidTooSmall() {
for (ResolverStyle style : ResolverStyle.values()) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.ERA, JapaneseEra.MEIJI.getValue() - 1L);
try {
JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
fail("Should have failed: " + style);
} catch (DateTimeException ex) {
// expected
}
}
}
use of java.time.format.ResolverStyle in project jdk8u_jdk by JetBrains.
the class TCKInstantPrinterParser method test_parse_leapSecond.
@Test
public void test_parse_leapSecond() {
Instant expected = OffsetDateTime.of(1970, 2, 3, 23, 59, 59, 123456789, ZoneOffset.UTC).toInstant();
DateTimeFormatter f = new DateTimeFormatterBuilder().appendInstant(-1).toFormatter();
for (ResolverStyle style : ResolverStyle.values()) {
TemporalAccessor parsed = f.withResolverStyle(style).parse("1970-02-03T23:59:60.123456789Z");
assertEquals(parsed.query(Instant::from), expected);
assertEquals(parsed.query(DateTimeFormatter.parsedExcessDays()), Period.ZERO);
assertEquals(parsed.query(DateTimeFormatter.parsedLeapSecond()), Boolean.TRUE);
}
}
Aggregations