Search in sources :

Example 11 with MockFieldValue

use of test.java.time.temporal.MockFieldValue 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 12 with MockFieldValue

use of test.java.time.temporal.MockFieldValue 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)

Aggregations

Test (org.testng.annotations.Test)12 MockFieldValue (test.java.time.temporal.MockFieldValue)12 DateTimeException (java.time.DateTimeException)7