### Question:
UsernamePasswordAuthenticationFilter extends org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter { @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; extractAndCheckRememberMeToken(request); super.doFilter(req, res, chain); } UsernamePasswordAuthenticationFilter(
            RememberMeCookieDecoder rememberMeCookieDecoder,
            RememberMeCheckService rememberMeCheckService); @Override void doFilter(ServletRequest req, ServletResponse res, FilterChain chain);  }### Answer:
@Test public void passedRememberMeTokenInCookieShouldBeChecked() throws IOException, ServletException { HttpServletRequest request = new MockHttpServletRequest(); FilterChain filterChain = new MockFilterChain(); String rememberMeCookieValue = "cookie value"; String series = "series"; String token = "token"; String[] seriesAndToken = new String[] { series, token }; when(rememberMeCookieDecoder.exctractRememberMeCookieValue(request)) .thenReturn(rememberMeCookieValue); when(rememberMeCookieDecoder.extractSeriesAndToken(rememberMeCookieValue)) .thenReturn(seriesAndToken); filter.doFilter(request, new MockHttpServletResponse(), filterChain); verify(rememberMeCheckService).equalWithPersistentToken(series, token); }
@Test public void passedIncorrectRememberMeTokenInCookieShouldNotBeChecked() throws IOException, ServletException { HttpServletRequest request = new MockHttpServletRequest(); FilterChain filterChain = new MockFilterChain(); String rememberMeCookieValue = "cookie value"; String[] seriesAndToken = {"it contains only series"}; when(rememberMeCookieDecoder.exctractRememberMeCookieValue(request)) .thenReturn(rememberMeCookieValue); when(rememberMeCookieDecoder.extractSeriesAndToken(rememberMeCookieValue)) .thenReturn(seriesAndToken); filter.doFilter(request, new MockHttpServletResponse(), filterChain); verify(rememberMeCheckService, never()).equalWithPersistentToken(anyString(), anyString()); }