Search in sources :

Example 56 with DateTimeException

use of java.time.DateTimeException in project jdk8u_jdk by JetBrains.

the class TCKThaiBuddhistChronology method test_resolve_ymaa_smart.

@Test(dataProvider = "resolve_ymaa")
public void test_resolve_ymaa_smart(int y, int m, int w, int d, ThaiBuddhistDate expected, boolean 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.ALIGNED_WEEK_OF_MONTH, (long) w);
    fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
    if (smart) {
        ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
            fail("Should have failed");
        } catch (DateTimeException ex) {
        // expected
        }
    }
}
Also used : ThaiBuddhistDate(java.time.chrono.ThaiBuddhistDate) TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 57 with DateTimeException

use of java.time.DateTimeException in project jdk8u_jdk by JetBrains.

the class TCKThaiBuddhistChronology method test_resolve_yd_strict.

@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_strict(int y, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
    if (strict) {
        ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
            fail("Should have failed");
        } catch (DateTimeException ex) {
        // expected
        }
    }
}
Also used : ThaiBuddhistDate(java.time.chrono.ThaiBuddhistDate) TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 58 with DateTimeException

use of java.time.DateTimeException in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatters method test_print_isoOrdinalDate_fields.

@Test
public void test_print_isoOrdinalDate_fields() {
    // mock for testing that does not fully comply with TemporalAccessor contract
    TemporalAccessor test = new TemporalAccessor() {

        @Override
        public boolean isSupported(TemporalField field) {
            return field == YEAR || field == DAY_OF_YEAR;
        }

        @Override
        public long getLong(TemporalField field) {
            if (field == YEAR) {
                return 2008;
            }
            if (field == DAY_OF_YEAR) {
                return 231;
            }
            throw new DateTimeException("Unsupported");
        }
    };
    assertEquals(DateTimeFormatter.ISO_ORDINAL_DATE.format(test), "2008-231");
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) Test(org.testng.annotations.Test)

Example 59 with DateTimeException

use of java.time.DateTimeException in project jdk8u_jdk by JetBrains.

the class TCKWeekFields method test_parse_resolve_localizedWom_strict.

@Test(dataProvider = "weekFields")
public void test_parse_resolve_localizedWom_strict(DayOfWeek firstDayOfWeek, int minDays) {
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField womField = week.weekOfMonth();
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral(':').appendValue(MONTH_OF_YEAR).appendLiteral(':').appendValue(womField).appendLiteral(':').appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(STRICT);
    String str = "2012:1:0:1";
    try {
        LocalDate date = LocalDate.parse(str, f);
        assertEquals(date.getYear(), 2012);
        assertEquals(date.getMonthValue(), 1);
        assertEquals(date.get(womField), 0);
        assertEquals(date.get(DAY_OF_WEEK), 1);
    } catch (DateTimeException ex) {
    // expected
    }
}
Also used : TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) WeekFields(java.time.temporal.WeekFields) DateTimeFormatter(java.time.format.DateTimeFormatter) LocalDate(java.time.LocalDate) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 60 with DateTimeException

use of java.time.DateTimeException in project jdk8u_jdk by JetBrains.

the class TestDateTimeFormatter method assertGoodErrorDate.

private void assertGoodErrorDate(Function<TemporalAccessor, Object> function, String expectedText) {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-mm-dd");
    TemporalAccessor temporal = f.parse("2010-06-30");
    try {
        function.apply(temporal);
        fail("Should have failed");
    } catch (DateTimeException ex) {
        String msg = ex.getMessage();
        assertTrue(msg.contains(expectedText), msg);
        assertTrue(msg.contains("Year"), msg);
        assertTrue(msg.contains("MinuteOfHour"), msg);
        assertTrue(msg.contains("DayOfMonth"), msg);
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeException(java.time.DateTimeException) DateTimeFormatter(java.time.format.DateTimeFormatter)

Aggregations

DateTimeException (java.time.DateTimeException)88 Test (org.testng.annotations.Test)58 TemporalField (java.time.temporal.TemporalField)48 HashMap (java.util.HashMap)34 LocalDate (java.time.LocalDate)20 TemporalAccessor (java.time.temporal.TemporalAccessor)20 DateTimeFormatter (java.time.format.DateTimeFormatter)13 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)10 MinguoDate (java.time.chrono.MinguoDate)7 ThaiBuddhistDate (java.time.chrono.ThaiBuddhistDate)7 InvalidParametersEvent (org.kie.dmn.feel.runtime.events.InvalidParametersEvent)7 MockFieldValue (test.java.time.temporal.MockFieldValue)7 HijrahDate (java.time.chrono.HijrahDate)6 ChronoLocalDate (java.time.chrono.ChronoLocalDate)5 JapaneseDate (java.time.chrono.JapaneseDate)5 Chronology (java.time.chrono.Chronology)4 IOException (java.io.IOException)3 LocalTime (java.time.LocalTime)3 WeekFields (java.time.temporal.WeekFields)3 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)3