Search in sources :

Example 11 with ResolverStyle

use of java.time.format.ResolverStyle in project jdk8u_jdk by JetBrains.

the class TCKDateTimeParseResolver method test_resolveThreeToTime.

@Test(dataProvider = "resolveFourToTime")
public void test_resolveThreeToTime(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).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.minusNanos(nano), "ResolverStyle: " + s);
            assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), excessPeriod, "ResolverStyle: " + s);
        } else {
            try {
                f.withResolverStyle(style).parse("");
                fail();
            } catch (DateTimeParseException ex) {
            // expected
            }
        }
    }
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) TemporalAccessor(java.time.temporal.TemporalAccessor) ResolverStyle(java.time.format.ResolverStyle) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Aggregations

ResolverStyle (java.time.format.ResolverStyle)11 DateTimeFormatter (java.time.format.DateTimeFormatter)5 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)5 TemporalAccessor (java.time.temporal.TemporalAccessor)5 Test (org.testng.annotations.Test)5 DataProvider (org.testng.annotations.DataProvider)4 DateTimeException (java.time.DateTimeException)2 Instant (java.time.Instant)2 DateTimeParseException (java.time.format.DateTimeParseException)2 TemporalField (java.time.temporal.TemporalField)2 HashMap (java.util.HashMap)2 LocalDate (java.time.LocalDate)1 ChronoLocalDate (java.time.chrono.ChronoLocalDate)1 HijrahEra (java.time.chrono.HijrahEra)1 JapaneseEra (java.time.chrono.JapaneseEra)1