HeaderFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { chain.doFilter(new HttpHeadersFilterRequestWrapper(filteredHeaderNames, (HttpServletRequest) request), response); } HeaderFilter(List<String> filteredHeaderNames); List<String> getFilteredHeaderNames(); @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void destroy();  }
@Test public void doFilter() throws Exception { FilterChain mockChain = Mockito.mock(FilterChain.class); HeaderFilter filter = new HeaderFilter(emptyList()); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); filter.doFilter(request, response, mockChain); ArgumentCaptor<HttpHeadersFilterRequestWrapper> args = ArgumentCaptor.forClass(HttpHeadersFilterRequestWrapper.class); Mockito.verify(mockChain, Mockito.times(1)).doFilter(args.capture(), any()); Assert.assertTrue(args.getValue() instanceof HttpHeadersFilterRequestWrapper); }