{
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
ServletDispatcher dispatcher = new ServletDispatcher();
Servlet servlet = mock(Servlet.class);
HttpContext context = mock(HttpContext.class);
ServletRegistration registration = new ServletRegistration("/a/b", servlet, context);
doAnswer(new Answer()
{
public Object answer(InvocationOnMock invocation)
{
HttpServletResponse resp = (HttpServletResponse) invocation.getArguments()[1];
resp.setStatus(HttpServletResponse.SC_OK);
return null;
}
}).when(servlet).service(request, response);
when(context.handleSecurity(request, response)).thenReturn(true);
when(request.getPathInfo()).thenReturn("/a/b/c");
dispatcher.register(registration);
dispatcher.service(request, response);