DataprepLocaleContextResolver implements LocaleContextResolver { @Override public Locale resolveLocale(HttpServletRequest request) { return getLocale(request); } DataprepLocaleContextResolver(@Value("${dataprep.locale:en-US}") String configuredLocale); @Override Locale resolveLocale(HttpServletRequest request); @Override void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale); @Override LocaleContext resolveLocaleContext(HttpServletRequest request); @Override void setLocaleContext(HttpServletRequest request, HttpServletResponse response,
            LocaleContext localeContext);  }
@Test public void resolveLocaleContextWithWellFormattedLocaleIsTaken() throws Exception { DataprepLocaleContextResolver resolver = new DataprepLocaleContextResolver(TEST_LOCALE); Locale locale = resolver.resolveLocale(request); assertNotNull(locale); assertEquals(TEST_LOCALE, locale.toLanguageTag()); }
@Test public void resolveLocaleContextWithNotFormattedLocaleDefault() throws Exception { DataprepLocaleContextResolver resolver = new DataprepLocaleContextResolver("abcd"); Locale locale = resolver.resolveLocale(request); assertNotNull(locale); assertEquals(Locale.US, locale); }
@Test public void resolveLocaleContextWithNoLocaleThenDefault() throws Exception { DataprepLocaleContextResolver resolver = new DataprepLocaleContextResolver(null); Locale locale = resolver.resolveLocale(request); assertNotNull(locale); assertEquals(Locale.US, locale); }
@Test public void resolveLocaleContextWithFromHttpHeader() throws Exception { DataprepLocaleContextResolver resolver = new DataprepLocaleContextResolver(null); when(request.getHeader(eq(HttpHeaders.ACCEPT_LANGUAGE))).thenReturn(Locale.JAPANESE.toLanguageTag()); when(request.getLocales()).thenReturn(Collections.enumeration(Arrays.asList(Locale.JAPANESE, Locale.US))); Locale locale = resolver.resolveLocale(request); assertNotNull(locale); assertEquals(Locale.JAPANESE, locale); }
@Test public void resolveLocaleContextWithMalformedLocale() throws Exception { DataprepLocaleContextResolver resolver = new DataprepLocaleContextResolver("@@&&"); Locale locale = resolver.resolveLocale(request); assertNotNull(locale); assertEquals(Locale.US, locale); }