use of java.time.temporal.TemporalField in project jdk8u_jdk by JetBrains.
the class TCKThaiBuddhistChronology method test_resolve_yd_lenient.
@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_lenient(int y, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.YEAR, (long) y);
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
assertEquals(date, expected);
assertEquals(fieldValues.size(), 0);
}
use of java.time.temporal.TemporalField in project jdk8u_jdk by JetBrains.
the class TCKDateTimeFormatters method assertParseMatch.
private void assertParseMatch(TemporalAccessor parsed, Expected expected) {
for (TemporalField field : expected.fieldValues.keySet()) {
assertEquals(parsed.isSupported(field), true);
parsed.getLong(field);
}
assertEquals(parsed.query(TemporalQueries.chronology()), expected.chrono);
assertEquals(parsed.query(TemporalQueries.zoneId()), expected.zone);
}
use of java.time.temporal.TemporalField in project jdk8u_jdk by JetBrains.
the class TCKLocalTime method test_with_longTemporalField_notChronoField.
// If the field is not a {@code ChronoField}, then the result of this method
// is obtained by invoking {@code TemporalField.adjustInto(Temporal, long)}
// passing {@code this} as the argument.
@Test
public void test_with_longTemporalField_notChronoField() {
final LocalTime result = LocalTime.of(12, 30);
final LocalTime base = LocalTime.of(15, 45);
TemporalField field = new TemporalField() {
public ValueRange rangeRefinedBy(TemporalAccessor temporal) {
throw new UnsupportedOperationException();
}
public ValueRange range() {
return null;
}
public boolean isTimeBased() {
throw new UnsupportedOperationException();
}
public boolean isSupportedBy(TemporalAccessor temporal) {
throw new UnsupportedOperationException();
}
public boolean isDateBased() {
throw new UnsupportedOperationException();
}
public TemporalUnit getRangeUnit() {
throw new UnsupportedOperationException();
}
public long getFrom(TemporalAccessor temporal) {
throw new UnsupportedOperationException();
}
public TemporalUnit getBaseUnit() {
throw new UnsupportedOperationException();
}
public <R extends Temporal> R adjustInto(R temporal, long newValue) {
assertEquals(temporal, base);
assertEquals(newValue, 12L);
@SuppressWarnings("unchecked") R r = (R) result;
return r;
}
};
LocalTime test = base.with(field, 12L);
assertSame(test, result);
}
use of java.time.temporal.TemporalField in project jdk8u_jdk by JetBrains.
the class TCKZoneId method factory_from_TemporalAccessor_zoneId.
//-----------------------------------------------------------------------
// from(TemporalAccessor)
//-----------------------------------------------------------------------
@Test
public void factory_from_TemporalAccessor_zoneId() {
TemporalAccessor mock = new TemporalAccessor() {
@Override
public boolean isSupported(TemporalField field) {
return false;
}
@Override
public long getLong(TemporalField field) {
throw new DateTimeException("Mock");
}
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQueries.zoneId()) {
return (R) ZoneId.of("Europe/Paris");
}
return TemporalAccessor.super.query(query);
}
};
assertEquals(ZoneId.from(mock), ZoneId.of("Europe/Paris"));
}
use of java.time.temporal.TemporalField 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();
}
}
Aggregations