HandlerChain { public void next(HttpServletRequest request, HttpServletResponse response) throws Exception { if (nextHandlerIndex < handlers.length) { RequestResponseHandler handler = handlers[nextHandlerIndex]; nextHandlerIndex++; handler.handle(request, response, this); } } HandlerChain(RequestResponseHandler[] handlers); void next(HttpServletRequest request, HttpServletResponse response);  }
@Test public void testHandlerInvocation() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); RequestResponseHandler[] handlers = {new TestRequestResponseHandler(), new TestRequestResponseHandler()}; HandlerChain chain = new HandlerChain(handlers); chain.next(request, response); verify(request, times(2)).setAttribute(anyString(), any()); }