@Test public void testDetermineLocaleEndlessLoop() { DefaultI18nContentSupport defSupport = new DefaultI18nContentSupport(); defSupport.setFallbackLocale(DEFAULT_LOCALE); defSupport.addLocale(new LocaleDefinition("de", "CH", true)); defSupport.addLocale(new LocaleDefinition("it", null, true)); // no language setCurrentURI("/home.html"); Locale locale = defSupport.determineLocale(); assertEquals(DEFAULT_LOCALE, locale); // exact match on the lang/country setCurrentURI("/de_ch/home.html"); locale = defSupport.determineLocale(); assertEquals(new Locale("de", "ch"), locale); // supported lang, but not country - should default to the same lang but with diff country setCurrentURI("/de_at/home.html"); locale = defSupport.determineLocale(); assertEquals(new Locale("de", "ch"), locale); // supported lang, but not w/o country code - should default to the same lang but with different country code setCurrentURI("/de/home.html"); locale = defSupport.determineLocale(); assertEquals(new Locale("de", "ch"), locale); // not supported language setCurrentURI("/fr/home.html"); locale = defSupport.determineLocale(); assertEquals(DEFAULT_LOCALE, locale); setCurrentURI("/it/home.html"); locale = defSupport.determineLocale(); assertEquals(new Locale("it"), locale); }
@Test public void testDetermineLocale() { DefaultI18nContentSupport defSupport = new DefaultI18nContentSupport(); defSupport.setFallbackLocale(DEFAULT_LOCALE); defSupport.addLocale(new LocaleDefinition("de", null, true)); defSupport.addLocale(new LocaleDefinition("de", "CH", true)); defSupport.addLocale(new LocaleDefinition("it", null, false)); // no language setCurrentURI("/home.html"); Locale locale = defSupport.determineLocale(); assertEquals(DEFAULT_LOCALE, locale); setCurrentURI("/de/home.html"); locale = defSupport.determineLocale(); assertEquals(new Locale("de"), locale); setCurrentURI("/de"); locale = defSupport.determineLocale(); assertEquals(new Locale("de"), locale); setCurrentURI("/de_ch/home.html"); locale = defSupport.determineLocale(); assertEquals(new Locale("de", "ch"), locale); // not supported language setCurrentURI("/fr/home.html"); locale = defSupport.determineLocale(); assertEquals(DEFAULT_LOCALE, locale); // disabled language setCurrentURI("/it/home.html"); locale = defSupport.determineLocale(); assertEquals(DEFAULT_LOCALE, locale); }