use of java.time.chrono.Chronology in project jdk8u_jdk by JetBrains.
the class TCKChronoLocalDateTime method test_badTemporalFieldChrono.
@Test(dataProvider = "calendars")
public void test_badTemporalFieldChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
TemporalField adjuster = new FixedTemporalField(cdt2);
if (chrono != chrono2) {
try {
cdt.with(adjuster, 1);
Assert.fail("TemporalField doWith() should have thrown a ClassCastException" + cdt.getClass() + ", can not be cast to " + cdt2.getClass());
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoLocalDateTime<?> result = cdt.with(adjuster, 1);
assertEquals(result, cdt2, "TemporalField doWith() failed to replace date");
}
}
}
use of java.time.chrono.Chronology in project jdk8u_jdk by JetBrains.
the class TCKChronology method test_ofLocaleByType.
/**
* Test lookup by calendarType of each chronology.
* Verify that the calendar can be found by {@link java.time.chrono.Chronology#ofLocale}.
*/
@Test
public void test_ofLocaleByType() {
// Test that all available chronologies can be successfully found using ofLocale
Set<Chronology> chronos = Chronology.getAvailableChronologies();
for (Chronology chrono : chronos) {
Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA");
builder.setUnicodeLocaleKeyword("ca", chrono.getCalendarType());
Locale locale = builder.build();
assertEquals(Chronology.ofLocale(locale), chrono, "Lookup by type");
}
}
use of java.time.chrono.Chronology in project jdk8u_jdk by JetBrains.
the class TCKChronology method test_ThaiBuddhistChronology_dateYearDay.
@Test
public void test_ThaiBuddhistChronology_dateYearDay() {
Chronology chrono = Chronology.of("ThaiBuddhist");
ChronoLocalDate date1 = chrono.dateYearDay(ThaiBuddhistEra.BE, 2459, 60);
ChronoLocalDate date2 = chrono.date(ThaiBuddhistEra.BE, 2459, 2, 29);
assertEquals(date1, ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BE, 2459, 60));
assertEquals(date2, ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BE, 2459, 60));
}
use of java.time.chrono.Chronology in project jdk8u_jdk by JetBrains.
the class TCKChronology method test_epoch.
/**
* Compute the number of days from the Epoch and compute the date from the number of days.
*/
@Test(dataProvider = "calendarNameAndType")
public void test_epoch(String name, String alias) {
// a chronology. In practice this is rarely hardcoded
Chronology chrono = Chronology.of(name);
ChronoLocalDate date1 = chrono.dateNow();
long epoch1 = date1.getLong(ChronoField.EPOCH_DAY);
ChronoLocalDate date2 = date1.with(ChronoField.EPOCH_DAY, epoch1);
assertEquals(date1, date2, "Date from epoch day is not same date: " + date1 + " != " + date2);
long epoch2 = date1.getLong(ChronoField.EPOCH_DAY);
assertEquals(epoch1, epoch2, "Epoch day not the same: " + epoch1 + " != " + epoch2);
}
use of java.time.chrono.Chronology in project jdk8u_jdk by JetBrains.
the class TCKChronology method test_required_calendars.
@Test(dataProvider = "calendarNameAndType")
public void test_required_calendars(String chronoId, String calendarSystemType) {
Chronology chrono = Chronology.of(chronoId);
assertNotNull(chrono, "Required calendar not found by ID: " + chronoId);
chrono = Chronology.of(calendarSystemType);
assertNotNull(chrono, "Required calendar not found by type: " + chronoId);
Set<Chronology> cals = Chronology.getAvailableChronologies();
assertTrue(cals.contains(chrono), "Required calendar not found in set of available calendars");
}
Aggregations