PreFlightReportingFilter implements Filter { public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain ) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; if ( isPreFlight( httpRequest ) ) { final HttpServletResponse servletResponse = (HttpServletResponse) response; servletResponse.sendError( HttpServletResponse.SC_METHOD_NOT_ALLOWED ); } else { chain.doFilter( request, response ); } }  void init( FilterConfig filterConfig ); void destroy(); void doFilter( ServletRequest request, ServletResponse response, FilterChain chain );  }
@Test public void notPreFlight() throws Exception { Mockito.when( request.getMethod() ).thenReturn( HttpMethod.POST ); new PreFlightReportingFilter().doFilter( request, response, chain ); Mockito.verify( chain, Mockito.times( 1 ) ).doFilter( request, response ); }