Search in sources :

Example 16 with DateTimeException

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

the class TCKJapaneseChronology method test_resolve_ymd_smart.

@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_smart(int y, int m, int d, JapaneseDate 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)) {
        JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else if (smart instanceof JapaneseDate) {
        JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
        assertEquals(date, smart);
    } else {
        try {
            JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
            fail("Should have failed");
        } catch (DateTimeException ex) {
        // expected
        }
    }
}
Also used : TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) HashMap(java.util.HashMap) JapaneseDate(java.time.chrono.JapaneseDate) Test(org.testng.annotations.Test)

Example 17 with DateTimeException

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

the class TCKIsoChronology method test_resolve_ymaa_smart.

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

Example 18 with DateTimeException

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

the class TCKIsoChronology method test_resolve_ymaa_strict.

@Test(dataProvider = "resolve_ymaa")
public void test_resolve_ymaa_strict(int y, int m, int w, int d, LocalDate 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 (strict) {
        LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
            fail("Should have failed");
        } catch (DateTimeException ex) {
        // expected
        }
    }
}
Also used : TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) HashMap(java.util.HashMap) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 19 with DateTimeException

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

the class AbstractDateTimeTest method basicTest_get_TemporalField_unsupported.

@Test()
public void basicTest_get_TemporalField_unsupported() {
    for (TemporalAccessor sample : samples()) {
        for (TemporalField field : invalidFields()) {
            try {
                sample.get(field);
                fail("Failed on " + sample + " " + field);
            } catch (DateTimeException ex) {
            // expected
            }
        }
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) Test(org.testng.annotations.Test)

Example 20 with DateTimeException

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

the class AbstractDateTimeTest method basicTest_range_TemporalField_unsupported.

@Test()
public void basicTest_range_TemporalField_unsupported() {
    for (TemporalAccessor sample : samples()) {
        for (TemporalField field : invalidFields()) {
            try {
                sample.range(field);
                fail("Failed on " + sample + " " + field);
            } catch (DateTimeException ex) {
            // expected
            }
        }
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) Test(org.testng.annotations.Test)

Aggregations

DateTimeException (java.time.DateTimeException)75 Test (org.testng.annotations.Test)58 TemporalField (java.time.temporal.TemporalField)48 HashMap (java.util.HashMap)34 LocalDate (java.time.LocalDate)18 TemporalAccessor (java.time.temporal.TemporalAccessor)13 DateTimeFormatter (java.time.format.DateTimeFormatter)11 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)10 MinguoDate (java.time.chrono.MinguoDate)7 ThaiBuddhistDate (java.time.chrono.ThaiBuddhistDate)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 WeekFields (java.time.temporal.WeekFields)3 AbstractTCKTest (tck.java.time.AbstractTCKTest)3 ResolverStyle (java.time.format.ResolverStyle)2 TemporalQuery (java.time.temporal.TemporalQuery)2