### Question:
CookieContentFilter extends AbstractSecureContentFilter { public Optional<AbstractAuthenticationToken> extractContent(HttpServletRequest request) { Cookie[] cookies = request.getCookies(); if (cookies == null) { return Optional.empty(); } return Arrays.stream(cookies) .filter(cookie -> cookie.getName().equals(authConfigurationProperties.getCookieProperties().getCookieName())) .filter(cookie -> !cookie.getValue().isEmpty()) .findFirst() .map(cookie -> new TokenAuthentication(cookie.getValue())); } CookieContentFilter(AuthenticationManager authenticationManager,
                               AuthenticationFailureHandler failureHandler,
                               ResourceAccessExceptionHandler resourceAccessExceptionHandler,
                               AuthConfigurationProperties authConfigurationProperties);  CookieContentFilter(AuthenticationManager authenticationManager,
                               AuthenticationFailureHandler failureHandler,
                               ResourceAccessExceptionHandler resourceAccessExceptionHandler,
                               AuthConfigurationProperties authConfigurationProperties,
                               String[] endpoints); Optional<AbstractAuthenticationToken> extractContent(HttpServletRequest request);  }### Answer:
@Test public void shouldReturnEmptyIfNoCookies() { Optional<AbstractAuthenticationToken> content = cookieContentFilter.extractContent(request); assertEquals(Optional.empty(), content); }
@Test public void shouldExtractContent() { Cookie cookie = new Cookie(authConfigurationProperties.getCookieProperties().getCookieName(), "cookie"); request.setCookies(cookie); Optional<AbstractAuthenticationToken> content = cookieContentFilter.extractContent(request); TokenAuthentication actualToken = new TokenAuthentication(cookie.getValue()); assertTrue(content.isPresent()); assertEquals(actualToken, content.get()); }
@Test public void shouldReturnEmptyIfCookieValueIsEmpty() { Cookie cookie = new Cookie(authConfigurationProperties.getCookieProperties().getCookieName(), ""); request.setCookies(cookie); Optional<AbstractAuthenticationToken> content = cookieContentFilter.extractContent(request); assertFalse(content.isPresent()); }