@Test public void testDoFilter() throws Exception { IMocksControl ctrl = createStrictControl(); FilterChain originalChain = ctrl.createMock(FilterChain.class); Filter filter1 = ctrl.createMock("filter1", Filter.class); Filter filter2 = ctrl.createMock("filter2", Filter.class); ServletRequest request = ctrl.createMock(ServletRequest.class); ServletResponse response = ctrl.createMock(ServletResponse.class); Capture<FilterChain> fc1 = Capture.newInstance(); Capture<FilterChain> fc2 = Capture.newInstance(); filter1.doFilter(same(request), same(response), and(anyObject(FilterChain.class), capture(fc1))); filter2.doFilter(same(request), same(response), and(anyObject(FilterChain.class), capture(fc2))); originalChain.doFilter(request, response); ctrl.replay(); SimpleFilterChain underTest = new SimpleFilterChain(originalChain, Arrays.asList(filter1, filter2).iterator()); underTest.doFilter(request, response); fc1.getValue().doFilter(request, response); fc2.getValue().doFilter(request, response); ctrl.verify(); }
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { if (chain.hasNext()) { Filter filter = chain.next(); filter.doFilter(request, response, this); } else if (!originalCalled) { originalCalled = true; originalChain.doFilter(request, response); } }
SimpleFilterChain implements FilterChain { public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { if (chain.hasNext()) { Filter filter = chain.next(); filter.doFilter(request, response, this); } else if (!originalCalled) { originalCalled = true; originalChain.doFilter(request, response); } } }
SimpleFilterChain implements FilterChain { public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { if (chain.hasNext()) { Filter filter = chain.next(); filter.doFilter(request, response, this); } else if (!originalCalled) { originalCalled = true; originalChain.doFilter(request, response); } } SimpleFilterChain(FilterChain originalChain, Iterator<? extends Filter> chain); }
SimpleFilterChain implements FilterChain { public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { if (chain.hasNext()) { Filter filter = chain.next(); filter.doFilter(request, response, this); } else if (!originalCalled) { originalCalled = true; originalChain.doFilter(request, response); } } SimpleFilterChain(FilterChain originalChain, Iterator<? extends Filter> chain); void doFilter(ServletRequest request, ServletResponse response); }
SimpleFilterChain implements FilterChain { public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { if (chain.hasNext()) { Filter filter = chain.next(); filter.doFilter(request, response, this); } else if (!originalCalled) { originalCalled = true; originalChain.doFilter(request, response); } } SimpleFilterChain(FilterChain originalChain, Iterator<? extends Filter> chain); void doFilter(ServletRequest request, ServletResponse response);  }