### Question:
PageContextHelper { public Locale getCurrentLocale() { return LocaleUtils.getUserLocale(request); } PageContextHelper(HttpServletRequest request); String getCurrentProfile(); Locale getCurrentLocale(); APISession getApiSession(); static final String PROFILE_PARAM; static final String ATTRIBUTE_API_SESSION; }### Answer:
@Test public void should_getCurrentLocale_return_request_parameter() throws Exception { doReturn(locale.toString()).when(request).getParameter(LocaleUtils.LOCALE_PARAM); pageContextHelper = new PageContextHelper(request); final Locale returnedLocale = pageContextHelper.getCurrentLocale(); assertThat(returnedLocale).isEqualToComparingFieldByField(locale); }
@Test public void should_getCurrentLocale_return_cookie_locale() throws Exception { Cookie[] cookieList = new Cookie[1]; cookieList[0] = new Cookie(LocaleUtils.LOCALE_COOKIE_NAME, locale.getLanguage()); doReturn(null).when(request).getParameter(LocaleUtils.LOCALE_PARAM); doReturn(cookieList).when(request).getCookies(); pageContextHelper = new PageContextHelper(request); final Locale returnedLocale = pageContextHelper.getCurrentLocale(); assertThat(returnedLocale).isEqualToComparingFieldByField(locale); }
@Test public void should_getCurrentLocale_return_default_locale() throws Exception { Cookie[] cookieList = new Cookie[1]; cookieList[0] = new Cookie("otherCookie", "otherValue"); doReturn(null).when(request).getParameter(LocaleUtils.LOCALE_PARAM); doReturn(cookieList).when(request).getCookies(); pageContextHelper = new PageContextHelper(request); final Locale returnedLocale = pageContextHelper.getCurrentLocale(); assertThat(returnedLocale.toString()).isEqualTo(LocaleUtils.DEFAULT_LOCALE); }