use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.
the class TestZoneOffsetParser method test_parse_exactMatch.
@Test(dataProvider = "offsets")
public void test_parse_exactMatch(String pattern, String parse, ZoneOffset expected) throws Exception {
ParsePosition pos = new ParsePosition(0);
TemporalAccessor parsed = getFormatter(pattern, "Z").parseUnresolved(parse, pos);
assertEquals(pos.getIndex(), parse.length());
assertParsed(parsed, expected);
}
use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.
the class TestDateTimeBuilderCombinations method test_derive.
@Test(dataProvider = "combine")
public void test_derive(final TemporalField field1, final Number value1, final TemporalField field2, final Number value2, final TemporalField field3, final Number value3, final TemporalField field4, final Number value4, Class<?> query, Object expectedVal) {
// mock for testing that does not fully comply with TemporalAccessor contract
TemporalAccessor test = new TemporalAccessor() {
@Override
public boolean isSupported(TemporalField field) {
return field == field1 || field == field2 || field == field3 || field == field4;
}
@Override
public long getLong(TemporalField field) {
if (field == field1) {
return value1.longValue();
}
if (field == field2) {
return value2.longValue();
}
if (field == field3) {
return value3.longValue();
}
if (field == field4) {
return value4.longValue();
}
throw new DateTimeException("Unsupported");
}
};
String str = "";
DateTimeFormatterBuilder dtfb = new DateTimeFormatterBuilder();
dtfb.appendValue(field1).appendLiteral('-');
str += value1 + "-";
if (field2 != null) {
dtfb.appendValue(field2).appendLiteral('-');
str += value2 + "-";
}
if (field3 != null) {
dtfb.appendValue(field3).appendLiteral('-');
str += value3 + "-";
}
if (field4 != null) {
dtfb.appendValue(field4).appendLiteral('-');
str += value4 + "-";
}
TemporalAccessor parsed = dtfb.toFormatter().parse(str);
if (query == LocalDate.class) {
if (expectedVal != null) {
assertEquals(parsed.query(LocalDate::from), expectedVal);
} else {
try {
parsed.query(LocalDate::from);
fail();
} catch (DateTimeException ex) {
// expected
}
}
} else {
throw new IllegalArgumentException();
}
}
use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.
the class TestZoneOffsetParser method test_parse_invalid.
@Test(dataProvider = "badOffsets")
public void test_parse_invalid(String pattern, String parse, int expectedPosition) throws Exception {
ParsePosition pos = new ParsePosition(0);
TemporalAccessor parsed = getFormatter(pattern, "Z").parseUnresolved(parse, pos);
assertEquals(pos.getErrorIndex(), expectedPosition);
assertEquals(parsed, null);
}
use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.
the class TestZoneOffsetParser method test_parse_exactMatch_EmptyUTC.
@Test(dataProvider = "offsets")
public void test_parse_exactMatch_EmptyUTC(String pattern, String parse, ZoneOffset expected) throws Exception {
ParsePosition pos = new ParsePosition(0);
TemporalAccessor parsed = getFormatter(pattern, "").parseUnresolved(parse, pos);
assertEquals(pos.getIndex(), parse.length());
assertParsed(parsed, expected);
}
use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.
the class TestZoneOffsetParser method test_parse_exactMatch_UTC.
//-----------------------------------------------------------------------
public void test_parse_exactMatch_UTC() throws Exception {
ParsePosition pos = new ParsePosition(0);
TemporalAccessor parsed = getFormatter("+HH:MM:ss", "Z").parseUnresolved("Z", pos);
assertEquals(pos.getIndex(), 1);
assertParsed(parsed, ZoneOffset.UTC);
}
Aggregations