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");
}
}
}
use of java.time.temporal.TemporalField in project jdk8u_jdk by JetBrains.
the class TCKHijrahChronology method test_resolve_ymd_strict.
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_strict(int y, int m, int d, HijrahDate expected, Object smart, boolean strict) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.YEAR, (long) y);
fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
if (strict) {
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
assertEquals(date, expected, "Resolved to incorrect date");
assertEquals(fieldValues.size(), 0);
} else {
try {
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
fail("Should have failed, returned: " + date);
} catch (DateTimeException ex) {
// expected
}
}
}
use of java.time.temporal.TemporalField in project jdk8u_jdk by JetBrains.
the class TCKHijrahChronology method test_resolve_ymd_lenient.
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_lenient(int y, int m, int d, HijrahDate expected, Object smart, boolean strict) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.YEAR, (long) y);
fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
if (expected != null) {
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
assertEquals(date, expected);
assertEquals(fieldValues.size(), 0);
} else {
try {
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
fail("Should have failed, returned: " + date);
} catch (DateTimeException ex) {
// expected
}
}
}
Aggregations