### Question:
AuthorizationFilter extends OncePerRequestFilter { @Override protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain ) throws ServletException, IOException { String header = httpServletRequest.getHeader(tokenProperties.getHeader()); if (headerIsValid(header)) { try { Claims claims = getClaims(getToken(header)); Optional.ofNullable(claims.getSubject()) .ifPresent(username -> setUserContext(claims, username)); } catch (ExpiredJwtException | UnsupportedJwtException | MalformedJwtException | SignatureException | IllegalArgumentException e) { LOG.info(e.getMessage(), e); SecurityContextHolder.clearContext(); } } goToNextFilter(httpServletRequest, httpServletResponse, filterChain); } AuthorizationFilter(TokenProperties tokenProperties, JwtParser jwtParser);   }### Answer:
@Test void shouldSkipGettingClaimsWhenHeaderIsNull() throws ServletException, IOException { when(request.getHeader(HEADER_NAME)) .thenReturn(null); filter.doFilterInternal(request, response, filterChain); verify(claims, times(0)).getSubject(); }
@Test void shouldSkipGettingClaimsWhenInvalidHeader() throws ServletException, IOException { when(request.getHeader(HEADER_NAME)) .thenReturn("faulty"); when(tokenProperties.getPrefix()) .thenReturn(HEADER_PREFIX); filter.doFilterInternal(request, response, filterChain); verify(claims, times(0)).getSubject(); }