DefaultLocaleResolver implements LocaleResolver { public Locale resolveLocale(Request request) { Locale retValue = null; Map<String, Object> session = request.getContext("session"); if (session != null) { retValue = (Locale) session.get(DefaultLocaleResolver.LOCALE_KEY); } if (retValue == null) { retValue = request.getRequestLocale(); } return retValue; }  Locale resolveLocale(Request request); static final String LOCALE_KEY; }
@SuppressWarnings("unchecked") @Test public void testResolveLocale() { Request request = createMock(Request.class); Map<String, Object> sessionScope = createMock(Map.class); Locale locale = Locale.ITALY; expect(request.getContext("session")).andReturn(sessionScope); expect(sessionScope.get(DefaultLocaleResolver.LOCALE_KEY)).andReturn(null); expect(request.getRequestLocale()).andReturn(locale); replay(request, sessionScope); DefaultLocaleResolver resolver = new DefaultLocaleResolver(); assertSame(locale, resolver.resolveLocale(request)); verify(request, sessionScope); }