LocalizationSetterImpl implements LocalizationSetter { public boolean setLocaleFromLocaleName(String localeName) { boolean supported = isSupportedLocaleName(localeName); if (supported) { Locale locale = findClosestSupportedLocale(toLocale(localeName)); persistentLocale.set(locale); threadLocale.setLocale(locale); } else { Locale requestLocale = request.getLocale(); Locale supportedLocale = findClosestSupportedLocale(requestLocale); threadLocale.setLocale(supportedLocale); } return supported; } LocalizationSetterImpl(Request request,

    PersistentLocale persistentLocale,

    ThreadLocale threadLocale,

    @Symbol(SymbolConstants.SUPPORTED_LOCALES)
    String localeNames); Locale toLocale(String localeName); boolean setLocaleFromLocaleName(String localeName); void setNonPersistentLocaleFromLocaleName(String localeName); List<Locale> getSupportedLocales(); boolean isSupportedLocaleName(String localeName); SelectModel getSupportedLocalesModel();  }
@Test public void known_locale() { PersistentLocale pl = mockPersistentLocale(); ThreadLocale tl = mockThreadLocale(); Request request = mockRequest(); tl.setLocale(Locale.FRENCH); pl.set(Locale.FRENCH); replay(); LocalizationSetter setter = new LocalizationSetterImpl(request, pl, tl, "en,fr"); assertTrue(setter.setLocaleFromLocaleName("fr")); verify(); }
@Test public void unknown_locale_uses_locale_from_request() { PersistentLocale pl = mockPersistentLocale(); ThreadLocale tl = mockThreadLocale(); Request request = mockRequest(); tl.setLocale(Locale.FRENCH); train_getLocale(request, Locale.CANADA_FRENCH); replay(); LocalizationSetterImpl setter = new LocalizationSetterImpl(request, pl, tl, "en,fr"); assertFalse(setter.setLocaleFromLocaleName("unknown")); verify(); }
@Test public void unsupported_locale_in_request_uses_default_locale() { PersistentLocale pl = mockPersistentLocale(); ThreadLocale tl = mockThreadLocale(); Request request = mockRequest(); tl.setLocale(Locale.ITALIAN); train_getLocale(request, Locale.CHINESE); replay(); LocalizationSetterImpl setter = new LocalizationSetterImpl(request, pl, tl, "it,en,fr"); assertFalse(setter.setLocaleFromLocaleName("unknown")); verify(); }