java.time.format.SignStyle Java Examples

The following examples show how to use java.time.format.SignStyle. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: dragonwell8_jdk   Author: alibaba   File: TCKSignStyle.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "signStyle")
public void test_signStyle(LocalDate localDate, SignStyle style, Class<?> expectedEx, String expectedStr) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    DateTimeFormatter formatter = builder.appendValue(ChronoField.YEAR, 2, 4, style)
                                         .toFormatter();
    formatter = formatter.withZone(ZoneOffset.UTC);
    if (expectedEx == null) {
        String output = formatter.format(localDate);
        assertEquals(output, expectedStr);
    } else {
        try {
            formatter.format(localDate);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example #2
Source Project: dragonwell8_jdk   Author: alibaba   File: TestNumberPrinter.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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");
            return;  // unreachable
        }
        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);
    }
}
 
Example #3
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: TestNumberParser.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="parseData")
public void test_parse_textField(int minWidth, int maxWidth, SignStyle signStyle, int subsequentWidth, String text, int pos, int expectedPos, long expectedValue) {
    ParsePosition ppos = new ParsePosition(pos);
    DateTimeFormatter dtf = getFormatter(DAY_OF_WEEK, minWidth, maxWidth, signStyle);
    if (subsequentWidth > 0) {
        // hacky, to reserve space
        dtf = builder.appendValue(DAY_OF_YEAR, subsequentWidth).toFormatter(locale).withDecimalStyle(decimalStyle);
    }
    TemporalAccessor parsed = dtf.parseUnresolved(text, ppos);
    if (ppos.getErrorIndex() != -1) {
        assertEquals(ppos.getErrorIndex(), expectedPos);
    } else {
        assertTrue(subsequentWidth >= 0);
        assertEquals(ppos.getIndex(), expectedPos + subsequentWidth);
        assertEquals(parsed.getLong(DAY_OF_WEEK), expectedValue);
        assertEquals(parsed.query(TemporalQueries.chronology()), null);
        assertEquals(parsed.query(TemporalQueries.zoneId()), null);
    }
}
 
Example #4
Source Project: openjdk-8   Author: bpupadhyaya   File: TestNumberParser.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="parseDigitsAdjacentLenient")
public void test_parseDigitsAdjacentLenient(String input, int parseLen, Integer parseMonth, Integer parsedDay) throws Exception {
    setStrict(false);
    ParsePosition pos = new ParsePosition(0);
    DateTimeFormatter f = builder
            .appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL)
            .appendValue(DAY_OF_MONTH, 2).toFormatter(locale).withDecimalStyle(decimalStyle);
    TemporalAccessor parsed = f.parseUnresolved(input, pos);
    if (pos.getErrorIndex() != -1) {
        assertEquals(pos.getErrorIndex(), parseLen);
    } else {
        assertEquals(pos.getIndex(), parseLen);
        assertEquals(parsed.getLong(MONTH_OF_YEAR), (long) parseMonth);
        assertEquals(parsed.getLong(DAY_OF_MONTH), (long) parsedDay);
        assertEquals(parsed.query(TemporalQueries.chronology()), null);
        assertEquals(parsed.query(TemporalQueries.zoneId()), null);
    }
}
 
Example #5
Source Project: jdk8u_jdk   Author: JetBrains   File: TCKSignStyle.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "signStyle")
public void test_signStyle(LocalDate localDate, SignStyle style, Class<?> expectedEx, String expectedStr) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    DateTimeFormatter formatter = builder.appendValue(ChronoField.YEAR, 2, 4, style)
                                         .toFormatter();
    formatter = formatter.withZone(ZoneOffset.UTC);
    if (expectedEx == null) {
        String output = formatter.format(localDate);
        assertEquals(output, expectedStr);
    } else {
        try {
            formatter.format(localDate);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example #6
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: TestNumberParser.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="parseDigitsAdjacentLenient")
public void test_parseDigitsAdjacentLenient(String input, int parseLen, Integer parseMonth, Integer parsedDay) throws Exception {
    setStrict(false);
    ParsePosition pos = new ParsePosition(0);
    DateTimeFormatter f = builder
            .appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL)
            .appendValue(DAY_OF_MONTH, 2).toFormatter(locale).withDecimalStyle(decimalStyle);
    TemporalAccessor parsed = f.parseUnresolved(input, pos);
    if (pos.getErrorIndex() != -1) {
        assertEquals(pos.getErrorIndex(), parseLen);
    } else {
        assertEquals(pos.getIndex(), parseLen);
        assertEquals(parsed.getLong(MONTH_OF_YEAR), (long) parseMonth);
        assertEquals(parsed.getLong(DAY_OF_MONTH), (long) parsedDay);
        assertEquals(parsed.query(TemporalQueries.chronology()), null);
        assertEquals(parsed.query(TemporalQueries.zoneId()), null);
    }
}
 
Example #7
Source Project: dragonwell8_jdk   Author: alibaba   File: TestNumberParser.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="parseDigitsAdjacentLenient")
public void test_parseDigitsAdjacentLenient(String input, int parseLen, Integer parseMonth, Integer parsedDay) throws Exception {
    setStrict(false);
    ParsePosition pos = new ParsePosition(0);
    DateTimeFormatter f = builder
            .appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL)
            .appendValue(DAY_OF_MONTH, 2).toFormatter(locale).withDecimalStyle(decimalStyle);
    TemporalAccessor parsed = f.parseUnresolved(input, pos);
    if (pos.getErrorIndex() != -1) {
        assertEquals(pos.getErrorIndex(), parseLen);
    } else {
        assertEquals(pos.getIndex(), parseLen);
        assertEquals(parsed.getLong(MONTH_OF_YEAR), (long) parseMonth);
        assertEquals(parsed.getLong(DAY_OF_MONTH), (long) parsedDay);
        assertEquals(parsed.query(TemporalQueries.chronology()), null);
        assertEquals(parsed.query(TemporalQueries.zoneId()), null);
    }
}
 
Example #8
Source Project: jdk8u_jdk   Author: JetBrains   File: TestNumberParser.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="parseData")
public void test_parse_fresh(int minWidth, int maxWidth, SignStyle signStyle, int subsequentWidth, String text, int pos, int expectedPos, long expectedValue) {
    ParsePosition ppos = new ParsePosition(pos);
    DateTimeFormatter dtf = getFormatter(DAY_OF_MONTH, minWidth, maxWidth, signStyle);
    if (subsequentWidth > 0) {
        // hacky, to reserve space
        dtf = builder.appendValue(DAY_OF_YEAR, subsequentWidth).toFormatter(locale).withDecimalStyle(decimalStyle);
    }
    TemporalAccessor parsed = dtf.parseUnresolved(text, ppos);
    if (ppos.getErrorIndex() != -1) {
        assertEquals(ppos.getErrorIndex(), expectedPos);
    } else {
        assertTrue(subsequentWidth >= 0);
        assertEquals(ppos.getIndex(), expectedPos + subsequentWidth);
        assertEquals(parsed.getLong(DAY_OF_MONTH), expectedValue);
        assertEquals(parsed.query(TemporalQueries.chronology()), null);
        assertEquals(parsed.query(TemporalQueries.zoneId()), null);
    }
}
 
Example #9
Source Project: openjdk-8-source   Author: keerath   File: TCKPadPrinterParser.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="parseLenient")
public void test_parseLenient(String text, int expectedIndex, int expectedErrorIndex, Number expectedMonth) {
    builder.parseLenient().padNext(3, '#').appendValue(MONTH_OF_YEAR, 1, 3, SignStyle.NORMAL);
    TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text, pos);
    assertEquals(pos.getIndex(), expectedIndex);
    assertEquals(pos.getErrorIndex(), expectedErrorIndex);
    if (expectedMonth != null) {
        assertEquals(parsed.isSupported(MONTH_OF_YEAR), true);
        assertEquals(parsed.getLong(MONTH_OF_YEAR), expectedMonth.longValue());
    } else {
        assertEquals(parsed, null);
    }
}
 
Example #10
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: TCKPadPrinterParser.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_parse_decoratedStartsWithPad_number() {
    builder.padNext(3, '-').appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL);
    TemporalAccessor parsed = builder.toFormatter().parseUnresolved("--2", pos);
    assertEquals(pos.getIndex(), 3);
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(parsed.isSupported(MONTH_OF_YEAR), true);
    assertEquals(parsed.getLong(MONTH_OF_YEAR), 2L);  // +2, not -2
}
 
Example #11
Source Project: jdk8u-jdk   Author: frohoff   File: TestNumberPrinter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example #12
Source Project: jdk8u-jdk   Author: frohoff   File: TestNumberParser.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="error")
public void test_parse_error(TemporalField field, int min, int max, SignStyle style, String text, int pos, Class<?> expected) {
    try {
        getFormatter(field, min, max, style).parseUnresolved(text, new ParsePosition(pos));
        fail();
    } catch (RuntimeException ex) {
        assertTrue(expected.isInstance(ex));
    }
}
 
Example #13
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: TestDateTimeFormatterBuilder.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_appendValue_subsequent2_parse4() throws Exception {
    builder.appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL).appendValue(DAY_OF_MONTH, 2);
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(), "Value(MonthOfYear,1,2,NORMAL)Value(DayOfMonth,2)");
    TemporalAccessor parsed = f.parseUnresolved("0123", new ParsePosition(0));
    assertEquals(parsed.getLong(MONTH_OF_YEAR), 1L);
    assertEquals(parsed.getLong(DAY_OF_MONTH), 23L);
}
 
Example #14
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: TestNumberParser.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="parseDigitsLenient")
public void test_parseDigitsLenient(String input, int min, int max, SignStyle style, int parseLen, Integer parseVal) throws Exception {
    setStrict(false);
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = getFormatter(DAY_OF_MONTH, min, max, style).parseUnresolved(input, pos);
    if (pos.getErrorIndex() != -1) {
        assertEquals(pos.getErrorIndex(), parseLen);
    } else {
        assertEquals(pos.getIndex(), parseLen);
        assertEquals(parsed.getLong(DAY_OF_MONTH), (long)parseVal);
        assertEquals(parsed.query(TemporalQueries.chronology()), null);
        assertEquals(parsed.query(TemporalQueries.zoneId()), null);
    }
}
 
Example #15
Source Project: openjdk-8-source   Author: keerath   File: TestDateTimeFormatter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_withLocale_same() throws Exception {
    DateTimeFormatter base =
        new DateTimeFormatterBuilder().appendLiteral("ONE")
                                      .appendValue(DAY_OF_MONTH, 1, 2, SignStyle.NOT_NEGATIVE)
                                      .toFormatter(Locale.ENGLISH)
                                      .withDecimalStyle(DecimalStyle.STANDARD);
    DateTimeFormatter test = base.withLocale(Locale.ENGLISH);
    assertSame(test, base);
}
 
Example #16
Source Project: j2objc   Author: google   File: TestDateTimeFormatterBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test_appendValue_subsequent2_parse3() throws Exception {
    builder.appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL).appendValue(DAY_OF_MONTH, 2);
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(), "Value(MonthOfYear,1,2,NORMAL)Value(DayOfMonth,2)");
    TemporalAccessor parsed = f.parseUnresolved("123", new ParsePosition(0));
    assertEquals(parsed.getLong(MONTH_OF_YEAR), 1L);
    assertEquals(parsed.getLong(DAY_OF_MONTH), 23L);
}
 
Example #17
Source Project: jdk8u-jdk   Author: frohoff   File: TestDateTimeFormatterBuilder.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_appendValue_subsequent2_parse4() throws Exception {
    builder.appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL).appendValue(DAY_OF_MONTH, 2);
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(), "Value(MonthOfYear,1,2,NORMAL)Value(DayOfMonth,2)");
    TemporalAccessor parsed = f.parseUnresolved("0123", new ParsePosition(0));
    assertEquals(parsed.getLong(MONTH_OF_YEAR), 1L);
    assertEquals(parsed.getLong(DAY_OF_MONTH), 23L);
}
 
Example #18
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: TCKSignStyle.java    License: GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="signStyle")
Object[][] data_signStyle() {
    return new Object[][] {
            {LocalDate.of(0, 10, 2), SignStyle.ALWAYS, null, "+00"},
            {LocalDate.of(2001, 10, 2), SignStyle.ALWAYS, null, "+2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.ALWAYS, null, "-2001"},

            {LocalDate.of(2001, 10, 2), SignStyle.NORMAL, null, "2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.NORMAL, null, "-2001"},

            {LocalDate.of(2001, 10, 2), SignStyle.NEVER, null, "2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.NEVER, null, "2001"},

            {LocalDate.of(2001, 10, 2), SignStyle.NOT_NEGATIVE, null, "2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.NOT_NEGATIVE, DateTimeException.class, ""},

            {LocalDate.of(0, 10, 2), SignStyle.EXCEEDS_PAD, null, "00"},
            {LocalDate.of(1, 10, 2), SignStyle.EXCEEDS_PAD, null, "01"},
            {LocalDate.of(-1, 10, 2), SignStyle.EXCEEDS_PAD, null, "-01"},

            {LocalDate.of(20001, 10, 2), SignStyle.ALWAYS, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.NORMAL, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.NEVER, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.EXCEEDS_PAD, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.NOT_NEGATIVE, DateTimeException.class, ""},
    };
}
 
Example #19
Source Project: jdk8u-dev-jdk   Author: frohoff   File: TestNumberParser.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="error")
public void test_parse_error(TemporalField field, int min, int max, SignStyle style, String text, int pos, Class<?> expected) {
    try {
        getFormatter(field, min, max, style).parseUnresolved(text, new ParsePosition(pos));
        fail();
    } catch (RuntimeException ex) {
        assertTrue(expected.isInstance(ex));
    }
}
 
Example #20
Source Project: hottub   Author: dsrg-uoft   File: TestDateTimeFormatterBuilder.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_appendValue_subsequent2_parse3() throws Exception {
    builder.appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL).appendValue(DAY_OF_MONTH, 2);
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(), "Value(MonthOfYear,1,2,NORMAL)Value(DayOfMonth,2)");
    TemporalAccessor parsed = f.parseUnresolved("123", new ParsePosition(0));
    assertEquals(parsed.getLong(MONTH_OF_YEAR), 1L);
    assertEquals(parsed.getLong(DAY_OF_MONTH), 23L);
}
 
Example #21
Source Project: jdk8u-dev-jdk   Author: frohoff   File: TestNumberPrinter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example #22
Source Project: jdk8u-jdk   Author: frohoff   File: TestNumberParser.java    License: GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="error")
Object[][] data_error() {
    return new Object[][] {
        {DAY_OF_MONTH, 1, 2, SignStyle.NEVER, "12", -1, IndexOutOfBoundsException.class},
        {DAY_OF_MONTH, 1, 2, SignStyle.NEVER, "12", 3, IndexOutOfBoundsException.class},
    };
}
 
Example #23
Source Project: logparser   Author: nielsbasjes   File: StrfTimeToDateTimeFormatter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void enterPs(StrfTimeParser.PsContext ctx) {
    // %s   The number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
    // Based upon https://stackoverflow.com/questions/36066155/datetimeformatter-for-epoch-milliseconds#answer-36069732
    builder
        .appendValue(ChronoField.INSTANT_SECONDS, 1, 19, SignStyle.NEVER);
}
 
Example #24
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: TestNumberPrinter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example #25
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: TestDateTimeFormatterBuilder.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_appendValue_subsequent2_parse5() throws Exception {
    builder.appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL).appendValue(DAY_OF_MONTH, 2).appendLiteral('4');
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(), "Value(MonthOfYear,1,2,NORMAL)Value(DayOfMonth,2)'4'");
    TemporalAccessor parsed = f.parseUnresolved("01234", new ParsePosition(0));
    assertEquals(parsed.getLong(MONTH_OF_YEAR), 1L);
    assertEquals(parsed.getLong(DAY_OF_MONTH), 23L);
}
 
Example #26
Source Project: openjdk-8-source   Author: keerath   File: TestNumberParser.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="parseSignsStrict")
public void test_parseSignsStrict(String input, int min, int max, SignStyle style, int parseLen, Integer parseVal) throws Exception {
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = getFormatter(DAY_OF_MONTH, min, max, style).parseUnresolved(input, pos);
    if (pos.getErrorIndex() != -1) {
        assertEquals(pos.getErrorIndex(), parseLen);
    } else {
        assertEquals(pos.getIndex(), parseLen);
        assertEquals(parsed.getLong(DAY_OF_MONTH), (long)parseVal);
        assertEquals(parsed.query(TemporalQueries.chronology()), null);
        assertEquals(parsed.query(TemporalQueries.zoneId()), null);
    }
}
 
Example #27
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: TCKSignStyle.java    License: GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="signStyle")
Object[][] data_signStyle() {
    return new Object[][] {
            {LocalDate.of(0, 10, 2), SignStyle.ALWAYS, null, "+00"},
            {LocalDate.of(2001, 10, 2), SignStyle.ALWAYS, null, "+2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.ALWAYS, null, "-2001"},

            {LocalDate.of(2001, 10, 2), SignStyle.NORMAL, null, "2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.NORMAL, null, "-2001"},

            {LocalDate.of(2001, 10, 2), SignStyle.NEVER, null, "2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.NEVER, null, "2001"},

            {LocalDate.of(2001, 10, 2), SignStyle.NOT_NEGATIVE, null, "2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.NOT_NEGATIVE, DateTimeException.class, ""},

            {LocalDate.of(0, 10, 2), SignStyle.EXCEEDS_PAD, null, "00"},
            {LocalDate.of(1, 10, 2), SignStyle.EXCEEDS_PAD, null, "01"},
            {LocalDate.of(-1, 10, 2), SignStyle.EXCEEDS_PAD, null, "-01"},

            {LocalDate.of(20001, 10, 2), SignStyle.ALWAYS, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.NORMAL, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.NEVER, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.EXCEEDS_PAD, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.NOT_NEGATIVE, DateTimeException.class, ""},
    };
}
 
Example #28
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: TestDateTimeFormatterBuilder.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_appendValue_subsequent3_parse6() throws Exception {
    builder
        .appendValue(YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
        .appendValue(MONTH_OF_YEAR, 2)
        .appendValue(DAY_OF_MONTH, 2);
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(), "Value(Year,4,10,EXCEEDS_PAD)Value(MonthOfYear,2)Value(DayOfMonth,2)");
    TemporalAccessor parsed = f.parseUnresolved("20090630", new ParsePosition(0));
    assertEquals(parsed.getLong(YEAR), 2009L);
    assertEquals(parsed.getLong(MONTH_OF_YEAR), 6L);
    assertEquals(parsed.getLong(DAY_OF_MONTH), 30L);
}
 
Example #29
Source Project: jdk8u60   Author: chenghanpeng   File: TestNumberParser.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="parseSignsLenient")
public void test_parseSignsLenient(String input, int min, int max, SignStyle style, int parseLen, Integer parseVal) throws Exception {
    setStrict(false);
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = getFormatter(DAY_OF_MONTH, min, max, style).parseUnresolved(input, pos);
    if (pos.getErrorIndex() != -1) {
        assertEquals(pos.getErrorIndex(), parseLen);
    } else {
        assertEquals(pos.getIndex(), parseLen);
        assertEquals(parsed.getLong(DAY_OF_MONTH), (long)parseVal);
        assertEquals(parsed.query(TemporalQueries.chronology()), null);
        assertEquals(parsed.query(TemporalQueries.zoneId()), null);
    }
}
 
Example #30
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: TestDateTimeFormatterBuilder.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_appendValue_subsequent2_parse4() throws Exception {
    builder.appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL).appendValue(DAY_OF_MONTH, 2);
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(), "Value(MonthOfYear,1,2,NORMAL)Value(DayOfMonth,2)");
    TemporalAccessor parsed = f.parseUnresolved("0123", new ParsePosition(0));
    assertEquals(parsed.getLong(MONTH_OF_YEAR), 1L);
    assertEquals(parsed.getLong(DAY_OF_MONTH), 23L);
}