### Question:
StaticContentFilter implements Filter { @Override public void doFilter( ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain ) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; if ( request.getServletPath() != null && request.getServletPath().endsWith( ".html" ) ) { response.addHeader( "Cache-Control", "private, no-cache, no-store, proxy-revalidate, no-transform" ); response.addHeader( "Pragma", "no-cache" ); response.addHeader( "Content-Security-Policy", "frame-ancestors 'none'" ); response.addHeader( "X-Frame-Options", "DENY" ); response.addHeader( "X-Content-Type-Options", "nosniff" ); response.addHeader( "X-XSS-Protection", "1; mode=block" ); } filterChain.doFilter( servletRequest, servletResponse); }  @Override void init( FilterConfig filterConfig ); @Override void doFilter( ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain ); @Override void destroy();  }### Answer:
@Test public void shouldAddStaticContentHeadersToHtmlResponses() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); when(request.getServletPath()).thenReturn( "index.html" ); HttpServletResponse response = mock(HttpServletResponse.class); FilterChain filterChain = mock( FilterChain.class ); new StaticContentFilter().doFilter( request, response, filterChain ); verify( response ).addHeader( "Cache-Control", "private, no-cache, no-store, proxy-revalidate, no-transform" ); verify( response ).addHeader( "Pragma", "no-cache" ); verify( response ).addHeader( "Content-Security-Policy", "frame-ancestors 'none'" ); verify( response ).addHeader( "X-Frame-Options", "DENY" ); verify( response ).addHeader( "X-Content-Type-Options", "nosniff" ); verify( response ).addHeader( "X-XSS-Protection", "1; mode=block" ); verify( filterChain ).doFilter( request, response ); }
@Test public void shouldPassThroughRequestsForNonHtmlResources() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); when(request.getServletPath()).thenReturn( "index.js" ); HttpServletResponse response = mock(HttpServletResponse.class); FilterChain filterChain = mock( FilterChain.class ); new StaticContentFilter().doFilter( request, response, filterChain ); verifyZeroInteractions( response ); verify( filterChain ).doFilter( request, response ); }
@Test public void shouldPassThroughRequestsWithNullServletPath() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); when(request.getServletPath()).thenReturn( null ); HttpServletResponse response = mock(HttpServletResponse.class); FilterChain filterChain = mock( FilterChain.class ); new StaticContentFilter().doFilter( request, response, filterChain ); verifyZeroInteractions( response ); verify( filterChain ).doFilter( request, response ); }