Search in sources :

Example 61 with DateTimeException

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

the class TestNumberPrinter method test_pad_NEVER.

@Test(dataProvider = "Pad")
public void test_pad_NEVER(int minPad, int maxPad, long value, String result) throws Exception {
    try {
        getFormatter(DAY_OF_MONTH, minPad, maxPad, SignStyle.NEVER).formatTo(new MockFieldValue(DAY_OF_MONTH, value), buf);
        if (result == null) {
            fail("Expected exception");
        }
        assertEquals(buf.toString(), 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 62 with DateTimeException

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

the class TestNumberPrinter method test_pad_EXCEEDS_PAD.

@Test(dataProvider = "Pad")
public void test_pad_EXCEEDS_PAD(int minPad, int maxPad, long value, String result) throws Exception {
    try {
        getFormatter(DAY_OF_MONTH, minPad, maxPad, SignStyle.EXCEEDS_PAD).formatTo(new MockFieldValue(DAY_OF_MONTH, value), buf);
        if (result == null) {
            fail("Expected exception");
            // unreachable
            return;
        }
        if (result.length() > minPad || value < 0) {
            result = (value < 0 ? "-" + result : "+" + result);
        }
        assertEquals(buf.toString(), 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 63 with DateTimeException

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

the class TestNumberPrinter method test_pad_NOT_NEGATIVE.

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

Example 64 with DateTimeException

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

the class Parsed method crossCheck.

private void crossCheck(TemporalAccessor target) {
    for (Iterator<Entry<TemporalField, Long>> it = fieldValues.entrySet().iterator(); it.hasNext(); ) {
        Entry<TemporalField, Long> entry = it.next();
        TemporalField field = entry.getKey();
        if (target.isSupported(field)) {
            long val1;
            try {
                val1 = target.getLong(field);
            } catch (RuntimeException ex) {
                continue;
            }
            long val2 = entry.getValue();
            if (val1 != val2) {
                throw new DateTimeException("Conflict found: Field " + field + " " + val1 + " differs from " + field + " " + val2 + " derived from " + target);
            }
            it.remove();
        }
    }
}
Also used : Entry(java.util.Map.Entry) TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException)

Example 65 with DateTimeException

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

the class TCKLocalTime method test_minus_longTemporalUnit_invalidUnit.

@Test
public void test_minus_longTemporalUnit_invalidUnit() {
    for (TemporalUnit unit : INVALID_UNITS) {
        try {
            TEST_12_30_40_987654321.minus(1, unit);
            fail("Unit should not be allowed " + unit);
        } catch (DateTimeException ex) {
        // expected
        }
    }
}
Also used : DateTimeException(java.time.DateTimeException) TemporalUnit(java.time.temporal.TemporalUnit) Test(org.testng.annotations.Test)

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