### Question:
LocaleProvidingFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final Cookie[] cookies = ((HttpServletRequest) request).getCookies(); if (cookies != null) { for (int j = cookies.length; --j >= 0;) { if (cookies[j].getName().equals(USER_LOCALE)) { String localeString = cookies[j].getValue(); Locale locale = Locales.getLocale(localeString); HttpSession session = ((HttpServletRequest) request).getSession(); session.setAttribute(Attributes.PREFERRED_LOCALE, locale); break; } } } chain.doFilter(request, response); }  @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void destroy(); static final String USER_LOCALE; }### Answer:
@Test public void testRequestWithNonexistentLocale() throws IOException, ServletException { Cookie[] cookies = new Cookie[1]; cookies[0] = new Cookie("notLocale", "2c"); when(request.getCookies()).thenReturn(cookies); interceptor.doFilter(request, response, chain); verify(session, never()).setAttribute(anyString(), any()); verifyZeroInteractions(response); }
@Test public void testRequestRu() throws IOException, ServletException { Cookie[] cookies = new Cookie[2]; cookies[0] = new Cookie(USER_LOCALE, RU_LOCALE_LANG); cookies[1] = new Cookie("notLocale", "2c"); when(request.getCookies()).thenReturn(cookies); interceptor.doFilter(request, response, chain); verify(session).setAttribute(Attributes.PREFERRED_LOCALE, Locales.getLocale(RU_LOCALE_LANG)); verifyZeroInteractions(response); }
@Test public void testRequestEn() throws IOException, ServletException { Cookie[] cookies = new Cookie[2]; cookies[0] = new Cookie(USER_LOCALE, EN_LOCALE_LANG); cookies[1] = new Cookie("notLocale", "2c"); when(request.getCookies()).thenReturn(cookies); interceptor.doFilter(request, response, chain); verify(session).setAttribute(Attributes.PREFERRED_LOCALE, Locales.getLocale(EN_LOCALE_LANG)); verifyZeroInteractions(response); }