Search in sources :

Example 6 with DateTimeException

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

the class TestNumberPrinter method test_pad_NORMAL.

@Test(dataProvider = "Pad")
public void test_pad_NORMAL(int minPad, int maxPad, long value, String result) throws Exception {
    try {
        getFormatter(DAY_OF_MONTH, minPad, maxPad, SignStyle.NORMAL).formatTo(new MockFieldValue(DAY_OF_MONTH, value), buf);
        if (result == null) {
            fail("Expected exception");
        }
        assertEquals(buf.toString(), (value < 0 ? "-" + result : result));
    } catch (DateTimeException ex) {
        if (result != null) {
            throw ex;
        }
        assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
    }
}
Also used : DateTimeException(java.time.DateTimeException) MockFieldValue(test.java.time.temporal.MockFieldValue) Test(org.testng.annotations.Test)

Example 7 with DateTimeException

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

the class TestNumberPrinter method test_pad_ALWAYS.

@Test(dataProvider = "Pad")
public void test_pad_ALWAYS(int minPad, int maxPad, long value, String result) throws Exception {
    try {
        getFormatter(DAY_OF_MONTH, minPad, maxPad, SignStyle.ALWAYS).formatTo(new MockFieldValue(DAY_OF_MONTH, value), buf);
        if (result == null) {
            fail("Expected exception");
        }
        assertEquals(buf.toString(), (value < 0 ? "-" + result : "+" + result));
    } catch (DateTimeException ex) {
        if (result != null) {
            throw ex;
        }
        assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
    }
}
Also used : DateTimeException(java.time.DateTimeException) MockFieldValue(test.java.time.temporal.MockFieldValue) Test(org.testng.annotations.Test)

Example 8 with DateTimeException

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

the class TestReducedPrinter method test_pivot.

@Test(dataProvider = "Pivot")
public void test_pivot(int minWidth, int maxWidth, int baseValue, int value, String result) throws Exception {
    try {
        getFormatter0(YEAR, minWidth, maxWidth, baseValue).formatTo(new MockFieldValue(YEAR, value), buf);
        if (result == null) {
            fail("Expected exception");
        }
        assertEquals(buf.toString(), result);
    } catch (DateTimeException ex) {
        if (result == null || value < 0) {
            assertEquals(ex.getMessage().contains(YEAR.toString()), true);
        } else {
            throw ex;
        }
    }
}
Also used : DateTimeException(java.time.DateTimeException) MockFieldValue(test.java.time.temporal.MockFieldValue) Test(org.testng.annotations.Test)

Example 9 with DateTimeException

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

the class TestReducedPrinter method test_pivot_baseDate.

@Test(dataProvider = "Pivot")
public void test_pivot_baseDate(int minWidth, int maxWidth, int baseValue, int value, String result) throws Exception {
    try {
        getFormatterBaseDate(YEAR, minWidth, maxWidth, baseValue).formatTo(new MockFieldValue(YEAR, value), buf);
        if (result == null) {
            fail("Expected exception");
        }
        assertEquals(buf.toString(), result);
    } catch (DateTimeException ex) {
        if (result == null || value < 0) {
            assertEquals(ex.getMessage().contains(YEAR.toString()), true);
        } else {
            throw ex;
        }
    }
}
Also used : DateTimeException(java.time.DateTimeException) MockFieldValue(test.java.time.temporal.MockFieldValue) Test(org.testng.annotations.Test)

Example 10 with DateTimeException

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

the class TCKDateTimeFormatter method test_resolverFields_selectOneDateResolveYD.

@Test
public void test_resolverFields_selectOneDateResolveYD() throws Exception {
    DateTimeFormatter base = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral('-').appendValue(MONTH_OF_YEAR).appendLiteral('-').appendValue(DAY_OF_MONTH).appendLiteral('-').appendValue(DAY_OF_YEAR).toFormatter();
    DateTimeFormatter f = base.withResolverFields(YEAR, DAY_OF_YEAR);
    Set<TemporalField> expected = new HashSet<>(Arrays.asList(YEAR, DAY_OF_YEAR));
    // Use set.equals();  testNG comparison of Collections is ordered
    assertTrue(f.getResolverFields().equals(expected), "ResolveFields: " + f.getResolverFields());
    try {
        // wrong month/day-of-month
        base.parse("2012-6-30-321", LocalDate::from);
        fail();
    } catch (DateTimeException ex) {
    // expected, fails as it produces two different dates
    }
    // ignored month/day-of-month
    LocalDate parsed = f.parse("2012-6-30-321", LocalDate::from);
    assertEquals(parsed, LocalDate.of(2012, 11, 16));
}
Also used : TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) DateTimeFormatter(java.time.format.DateTimeFormatter) LocalDate(java.time.LocalDate) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) HashSet(java.util.HashSet) 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