### Question:
JwtAuthenticationFilter extends GenericFilterBean { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { try { Authentication authentication = jwtProvider.getAuthentication((HttpServletRequest) servletRequest); if (authentication != null) { SecurityContextHolder.getContext().setAuthentication(authentication); } } catch (ExpiredJwtException e) { log.error("e : {}, {}", e.getMessage(), e); SecurityContextHolder.clearContext(); } filterChain.doFilter(servletRequest, servletResponse); } JwtAuthenticationFilter(JwtProvider jwtProvider); @Override void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain);  }### Answer:
@Test public void 필터테스트_성공() throws IOException, ServletException { SecurityContextHolder.clearContext(); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); given(jwtProvider.getAuthentication(mockRequest)).willReturn( new UsernamePasswordAuthenticationToken("akageun", null, Collections.emptyList())); JwtAuthenticationFilter filter = new JwtAuthenticationFilter(jwtProvider); MockHttpServletResponse mockResponse = new MockHttpServletResponse(); MockFilterChain filterChain = new MockFilterChain(); filter.doFilter(mockRequest, mockResponse, filterChain); assertEquals("akageun", SecurityContextHolder.getContext().getAuthentication().getName()); }
@Test public void 필터테스트_로그인정보가_없을경우() throws IOException, ServletException { SecurityContextHolder.clearContext(); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); given(jwtProvider.getAuthentication(mockRequest)).willReturn(null); JwtAuthenticationFilter filter = new JwtAuthenticationFilter(jwtProvider); MockHttpServletResponse mockResponse = new MockHttpServletResponse(); MockFilterChain filterChain = new MockFilterChain(); filter.doFilter(mockRequest, mockResponse, filterChain); assertNull(SecurityContextHolder.getContext().getAuthentication()); }