CrossDomainFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse resp = (HttpServletResponse) response; resp.addHeader("Access-Control-Allow-Origin", "*"); resp.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); resp.addHeader("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, X-Codingpedia"); chain.doFilter(request, response); }  @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void destroy();  }
@Test public void testFilter() throws IOException, ServletException { ServletRequest request = mock(ServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); FilterChain filterChain = mock(FilterChain.class); crossDomainFilter.doFilter(request, response, filterChain); InOrder inOrder = Mockito.inOrder(response, filterChain); inOrder.verify(response, times(1)).addHeader("Access-Control-Allow-Origin", "*"); inOrder.verify(response, times(1)).addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); inOrder.verify(response, times(1)).addHeader("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, X-Codingpedia"); inOrder.verify(filterChain, times(1)).doFilter(request, response); }