### Question:
AuthenticationFilter extends UsernamePasswordAuthenticationFilter { @Override protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication auth) { response.addHeader(tokenProperties.getHeader(), tokenProperties.getPrefix() + createToken(auth)); } AuthenticationFilter(AuthenticationManager authenticationManager, TokenProperties tokenProperties,
                                ObjectMapper objectMapper, Clock clock); @Override Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response);  }### Answer:
@Test void shouldAddHeaderForAuthenticatedUser() { when(tokenProperties.getHeader()) .thenReturn("header"); when(tokenProperties.getPrefix()) .thenReturn("prefix"); when(tokenProperties.getExpiration()) .thenReturn(1); when(tokenProperties.getSecret()) .thenReturn("secret"); when(authentication.getName()) .thenReturn("name"); List<GrantedAuthority> grantedAuthorities = singletonList(grantedAuthority); doReturn(grantedAuthorities) .when(authentication).getAuthorities(); when(grantedAuthority.getAuthority()) .thenReturn("test"); filter.successfulAuthentication(request, response, filterChain, authentication); var val = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJuYW1lIiwiYXV0aG9yaXRpZXMiOlsidGVzdCJdLCJpYXQiOjk0NjY4MTIwMCwiZXhwIj" + "o5NDY2ODEyMDF9.S8WGUAHCGMbvFcC4FsYjJ-7L98hJO4uWqp5oHeajNSHkKSFHU6IgrIO3ZNWnH6XMTfIzeoUeyO8pWwcOkXs9ZA"; verify(response).addHeader("header", "prefix" + val); }