@Test public void shouldRetrieveLocales() { when(cookieLocaleResolver.resolveLocale(request)).thenReturn(Locale.CHINA); assertEquals(Locale.CHINA, localeService.getUserLocale(request)); when(userService.getLocale("user")).thenReturn(Locale.GERMANY); when(request.getUserPrincipal()).thenReturn(principal); when(principal.getName()).thenReturn("user"); assertEquals(Locale.GERMANY, localeService.getUserLocale(request)); when(userService.getLocale("user")).thenReturn(null); when(cookieLocaleResolver.resolveLocale(request)).thenReturn(Locale.CANADA); assertEquals(Locale.CANADA, localeService.getUserLocale(request)); }
@Override public Locale getUserLocale(final HttpServletRequest request) { if (request.getUserPrincipal() == null) { return cookieLocaleResolver.resolveLocale(request); } Locale locale = userService.getLocale(request.getUserPrincipal().getName()); return (locale == null) ? cookieLocaleResolver.resolveLocale(request) : locale; }
LocaleServiceImpl implements LocaleService { @Override public Locale getUserLocale(final HttpServletRequest request) { if (request.getUserPrincipal() == null) { return cookieLocaleResolver.resolveLocale(request); } Locale locale = userService.getLocale(request.getUserPrincipal().getName()); return (locale == null) ? cookieLocaleResolver.resolveLocale(request) : locale; } }
LocaleServiceImpl implements LocaleService { @Override public Locale getUserLocale(final HttpServletRequest request) { if (request.getUserPrincipal() == null) { return cookieLocaleResolver.resolveLocale(request); } Locale locale = userService.getLocale(request.getUserPrincipal().getName()); return (locale == null) ? cookieLocaleResolver.resolveLocale(request) : locale; }  }
LocaleServiceImpl implements LocaleService { @Override public Locale getUserLocale(final HttpServletRequest request) { if (request.getUserPrincipal() == null) { return cookieLocaleResolver.resolveLocale(request); } Locale locale = userService.getLocale(request.getUserPrincipal().getName()); return (locale == null) ? cookieLocaleResolver.resolveLocale(request) : locale; }  @Override Locale getUserLocale(final HttpServletRequest request); @Override void setUserLocale(final HttpServletRequest request, final HttpServletResponse response, final Locale locale); @Override void setSessionLocale(final HttpServletRequest request, final HttpServletResponse response, final Locale locale); @Override NavigableMap<String, String> getSupportedLanguages(); @Override Map<String, String> getMessages(HttpServletRequest request); }
LocaleServiceImpl implements LocaleService { @Override public Locale getUserLocale(final HttpServletRequest request) { if (request.getUserPrincipal() == null) { return cookieLocaleResolver.resolveLocale(request); } Locale locale = userService.getLocale(request.getUserPrincipal().getName()); return (locale == null) ? cookieLocaleResolver.resolveLocale(request) : locale; }  @Override Locale getUserLocale(final HttpServletRequest request); @Override void setUserLocale(final HttpServletRequest request, final HttpServletResponse response, final Locale locale); @Override void setSessionLocale(final HttpServletRequest request, final HttpServletResponse response, final Locale locale); @Override NavigableMap<String, String> getSupportedLanguages(); @Override Map<String, String> getMessages(HttpServletRequest request);  }