### Question:
ServletModuleContainerServlet extends HttpServlet { protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (getServletModuleManager() == null) { log.error("Could not get ServletModuleManager?"); response.sendError(500, "Could not get ServletModuleManager."); return; } HttpServlet servlet = getServletModuleManager().getServlet(getPathInfo(request), servletConfig); if (servlet == null) { log.debug("No servlet found for: " + getRequestURI(request)); response.sendError(404, "Could not find servlet for: " + getRequestURI(request)); return; } try { servlet.service(request, response); } catch (UnavailableException e) { log.error(e.getMessage(), e); response.sendError(500, e.getMessage()); } catch (ServletException e) { log.error(e.getMessage(), e); response.sendError(500, e.getMessage()); } }  void init(ServletConfig servletConfig);  }### Answer:
@Test public void testIncludedServletDispatchesCorrectly() throws IOException, ServletException { final Mock mockHttpServletRequest = new Mock(HttpServletRequest.class); mockHttpServletRequest.matchAndReturn("getPathInfo", "/original"); mockHttpServletRequest.expectAndReturn("getAttribute", "javax.servlet.include.path_info", "/included"); final Mock mockHttpServletResponse = new Mock(HttpServletResponse.class); final MockHttpServlet originalServlet = new MockHttpServlet(); final MockHttpServlet includedServlet = new MockHttpServlet(); final ServletModuleManager servletModuleManager = new DefaultServletModuleManager(new DefaultPluginEventManager()) { @Override public HttpServlet getServlet(String path, ServletConfig servletConfig) throws ServletException { if (path.equals("/original")) { return originalServlet; } else if (path.equals("/included")) { return includedServlet; } return null; } }; final ServletModuleContainerServlet servlet = new ServletModuleContainerServlet() { @Override protected ServletModuleManager getServletModuleManager() { return servletModuleManager; } }; servlet.service((HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy()); assertTrue("includedServlet should have been invoked", includedServlet.wasCalled); assertFalse("originalServlet should not have been invoked", originalServlet.wasCalled); }
@Test public void testServletDoesntUnloadItself() throws IOException, ServletException { Mock mockServletModuleManager = new Mock(ServletModuleManager.class); Mock mockModuleClassFactory = new Mock(ModuleFactory.class); mockModuleClassFactory.expectAndReturn("createModule", new AnyConstraintMatcher(), null); ServletModuleDescriptor servletModuleDescriptor = new ServletModuleDescriptor((ModuleFactory) mockModuleClassFactory.proxy(), (ServletModuleManager) mockServletModuleManager.proxy()); final DelegatingPluginServlet delegatingPluginServlet = new DelegatingPluginServlet(servletModuleDescriptor) { public void service(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException { throw new UnavailableException("Error in plugin servlet"); } }; final ServletModuleManager servletModuleManager = new DefaultServletModuleManager(new DefaultPluginEventManager()) { public DelegatingPluginServlet getServlet(String path, ServletConfig servletConfig) { return delegatingPluginServlet; } }; Mock mockHttpServletRequest = new Mock(HttpServletRequest.class); mockHttpServletRequest.matchAndReturn("getAttribute", C.anyArgs(1), null); mockHttpServletRequest.expectAndReturn("getPathInfo", "confluence"); Mock mockHttpServletResponse = new Mock(HttpServletResponse.class); mockHttpServletResponse.expect("sendError", C.args(C.eq(500), C.isA(String.class))); ServletModuleContainerServlet servlet = new ServletModuleContainerServlet() { protected ServletModuleManager getServletModuleManager() { return servletModuleManager; } }; servlet.service((HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy()); }