use of java.time.temporal.TemporalField in project jdk8u_jdk by JetBrains.
the class TCKDateTimeFormatter method test_resolverFields_selectOneDateResolveYD.
@Test
public void test_resolverFields_selectOneDateResolveYD() throws Exception {
DateTimeFormatter base = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral('-').appendValue(MONTH_OF_YEAR).appendLiteral('-').appendValue(DAY_OF_MONTH).appendLiteral('-').appendValue(DAY_OF_YEAR).toFormatter();
DateTimeFormatter f = base.withResolverFields(YEAR, DAY_OF_YEAR);
Set<TemporalField> expected = new HashSet<>(Arrays.asList(YEAR, DAY_OF_YEAR));
// Use set.equals(); testNG comparison of Collections is ordered
assertTrue(f.getResolverFields().equals(expected), "ResolveFields: " + f.getResolverFields());
try {
// wrong month/day-of-month
base.parse("2012-6-30-321", LocalDate::from);
fail();
} catch (DateTimeException ex) {
// expected, fails as it produces two different dates
}
// ignored month/day-of-month
LocalDate parsed = f.parse("2012-6-30-321", LocalDate::from);
assertEquals(parsed, LocalDate.of(2012, 11, 16));
}
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 AbstractDateTimeTest method basicTest_getLong_TemporalField_unsupported.
@Test()
public void basicTest_getLong_TemporalField_unsupported() {
for (TemporalAccessor sample : samples()) {
for (TemporalField field : invalidFields()) {
try {
sample.getLong(field);
fail("Failed on " + sample + " " + field);
} catch (DateTimeException ex) {
// expected
}
}
}
}
use of java.time.temporal.TemporalField in project jdk8u_jdk by JetBrains.
the class TCKChronoLocalDate method test_badTemporalFieldChrono.
@Test(dataProvider = "calendars")
public void test_badTemporalFieldChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoLocalDate date = chrono.date(refDate);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoLocalDate date2 = chrono2.date(refDate);
TemporalField adjuster = new FixedTemporalField(date2);
if (chrono != chrono2) {
try {
date.with(adjuster, 1);
Assert.fail("TemporalField doSet should have thrown a ClassCastException" + date.getClass() + ", can not be cast to " + date2.getClass());
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoLocalDate result = date.with(adjuster, 1);
assertEquals(result, date2, "TemporalField doSet failed to replace date");
}
}
}
use of java.time.temporal.TemporalField in project jdk8u_jdk by JetBrains.
the class TCKChronoZonedDateTime method test_badTemporalFieldChrono.
@Test(dataProvider = "calendars")
public void test_badTemporalFieldChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
TemporalField adjuster = new FixedTemporalField(czdt2);
if (chrono != chrono2) {
try {
czdt.with(adjuster, 1);
Assert.fail("TemporalField doWith() should have thrown a ClassCastException, " + czdt.getClass() + " can not be cast to " + czdt2.getClass());
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoZonedDateTime<?> result = czdt.with(adjuster, 1);
assertEquals(result, czdt2, "TemporalField doWith() failed to replace date");
}
}
}
Aggregations