@Test(dataProvider = "calendarsystemtype") public void test_lookupLocale(Chronology chrono, String calendarType) { Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA"); builder.setUnicodeLocaleKeyword("ca", calendarType); Locale locale = builder.build(); assertEquals(Chronology.ofLocale(locale), chrono); }
@Test(expectedExceptions = DateTimeException.class) public void test_lookupLocale() { Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA"); builder.setUnicodeLocaleKeyword("ca", "xxx"); Locale locale = builder.build(); Chronology.ofLocale(locale); }
/** * 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"); } }
@Test public void test_chrono_byLocale_iso() { Assert.assertEquals(Chronology.ofLocale(new Locale("ja", "JP")).getId(), "ISO"); Assert.assertEquals(Chronology.ofLocale(Locale.forLanguageTag("ja-JP")).getId(), "ISO"); Assert.assertEquals(Chronology.ofLocale(Locale.forLanguageTag("ja-JP-JP")).getId(), "ISO"); }
@Test public void test_chrono_byLocale_oldJP_variant() { Chronology test = Chronology.ofLocale(new Locale("ja", "JP", "JP")); Assert.assertEquals(test.getId(), "Japanese"); Assert.assertEquals(test, JapaneseChronology.INSTANCE); }
@Test public void test_chrono_byLocale_oldJP_noVariant() { Chronology test = Chronology.ofLocale(new Locale("ja", "JP")); Assert.assertEquals(test.getId(), "ISO"); Assert.assertEquals(test, IsoChronology.INSTANCE); }
@Test public void test_chrono_byLocale_fullTag_japaneseCalendarFromElsewhere() { Chronology test = Chronology.ofLocale(Locale.forLanguageTag("en-US-u-ca-japanese")); Assert.assertEquals(test.getId(), "Japanese"); Assert.assertEquals(test, JapaneseChronology.INSTANCE); }