use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.
the class AbstractDateTimeTest method basicTest_getLong_TemporalField_null.
@Test()
public void basicTest_getLong_TemporalField_null() {
for (TemporalAccessor sample : samples()) {
try {
sample.getLong(null);
fail("Failed on " + sample);
} catch (NullPointerException ex) {
// expected
}
}
}
use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.
the class TestNumberParser method test_parseDigitsLenient.
@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);
}
}
use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.
the class TestNumberParser method test_parseSignsLenient.
@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);
}
}
use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.
the class TestReducedParser method test_reducedWithLateChronoChange.
@Test
public void test_reducedWithLateChronoChange() {
ThaiBuddhistDate date = ThaiBuddhistDate.of(2543, 1, 1);
DateTimeFormatter df = new DateTimeFormatterBuilder().appendValueReduced(YEAR, 2, 2, LocalDate.of(2000, 1, 1)).appendLiteral(" ").appendChronologyId().toFormatter();
int expected = date.get(YEAR);
String input = df.format(date);
ParsePosition pos = new ParsePosition(0);
TemporalAccessor parsed = df.parseUnresolved(input, pos);
assertEquals(pos.getIndex(), input.length(), "Input not parsed completely");
assertEquals(pos.getErrorIndex(), -1, "Error index should be -1 (no-error)");
int actual = parsed.get(YEAR);
assertEquals(actual, expected, String.format("Wrong date parsed, chrono: %s, input: %s", parsed.query(TemporalQueries.chronology()), input));
}
use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.
the class TestReducedParser method test_reducedWithChronoYearOfEra.
@Test(dataProvider = "ReducedWithChrono")
public void test_reducedWithChronoYearOfEra(ChronoLocalDate date) {
Chronology chrono = date.getChronology();
DateTimeFormatter df = new DateTimeFormatterBuilder().appendValueReduced(YEAR_OF_ERA, 2, 2, LocalDate.of(2000, 1, 1)).toFormatter().withChronology(chrono);
int expected = date.get(YEAR_OF_ERA);
String input = df.format(date);
ParsePosition pos = new ParsePosition(0);
TemporalAccessor parsed = df.parseUnresolved(input, pos);
int actual = parsed.get(YEAR_OF_ERA);
assertEquals(actual, expected, String.format("Wrong date parsed, chrono: %s, input: %s", chrono, input));
}
Aggregations