use of java.time.temporal.TemporalField in project jdk8u_jdk by JetBrains.
the class TCKJapaneseChronology method test_resolve_yd_strict.
@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_strict(int y, int d, JapaneseDate 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);
if (strict) {
JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
assertEquals(date, expected);
assertEquals(fieldValues.size(), 0);
} else {
try {
JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
fail("Should have failed");
} catch (DateTimeException ex) {
// expected
}
}
}
use of java.time.temporal.TemporalField in project jdk8u_jdk by JetBrains.
the class TCKMinguoChronology method test_resolve_yd_lenient.
@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_lenient(int y, int d, MinguoDate 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);
MinguoDate date = MinguoChronology.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 TCKJapaneseChronology method test_resolve_yearOfEra_eraOnly_invalidTooSmall.
public void test_resolve_yearOfEra_eraOnly_invalidTooSmall() {
for (ResolverStyle style : ResolverStyle.values()) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.ERA, JapaneseEra.MEIJI.getValue() - 1L);
try {
JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
fail("Should have failed: " + style);
} catch (DateTimeException ex) {
// expected
}
}
}
use of java.time.temporal.TemporalField in project jdk8u_jdk by JetBrains.
the class TCKDateTimeFormatter method test_format_withChronology_nonChronoFieldMapLink.
@Test
public void test_format_withChronology_nonChronoFieldMapLink() {
TemporalAccessor temporal = new TemporalAccessor() {
@Override
public boolean isSupported(TemporalField field) {
return field == IsoFields.WEEK_BASED_YEAR;
}
@Override
public long getLong(TemporalField field) {
if (field == IsoFields.WEEK_BASED_YEAR) {
return 2345;
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
};
DateTimeFormatter test = new DateTimeFormatterBuilder().appendValue(IsoFields.WEEK_BASED_YEAR, 4).toFormatter(Locale.ENGLISH).withChronology(IsoChronology.INSTANCE);
String result = test.format(temporal);
assertEquals(result, "2345");
}
use of java.time.temporal.TemporalField in project jdk8u_jdk by JetBrains.
the class TCKLocalizedFieldParser method test_parse_textField.
@Test(dataProvider = "FieldPatterns")
public void test_parse_textField(String pattern, String text, int pos, int expectedPos, long expectedValue) {
WeekFields weekDef = WeekFields.of(locale);
TemporalField field = null;
switch(pattern.charAt(0)) {
case 'e':
field = weekDef.dayOfWeek();
break;
case 'w':
field = weekDef.weekOfWeekBasedYear();
break;
case 'W':
field = weekDef.weekOfMonth();
break;
case 'Y':
field = weekDef.weekBasedYear();
break;
default:
throw new IllegalStateException("bad format letter from pattern");
}
ParsePosition ppos = new ParsePosition(pos);
DateTimeFormatterBuilder b = new DateTimeFormatterBuilder().appendPattern(pattern);
DateTimeFormatter dtf = b.toFormatter(locale);
TemporalAccessor parsed = dtf.parseUnresolved(text, ppos);
if (ppos.getErrorIndex() != -1) {
assertEquals(ppos.getErrorIndex(), expectedPos);
} else {
assertEquals(ppos.getIndex(), expectedPos, "Incorrect ending parse position");
long value = parsed.getLong(field);
assertEquals(value, expectedValue, "Value incorrect for " + field);
}
}
Aggregations