### Question:
ServletController { public void invoke(HttpServletRequest request, HttpServletResponse res) throws ServletException { invoke(request, res, true); } ServletController(DestinationRegistry destinationRegistry,
                                ServletConfig config,
                                HttpServlet serviceListGenerator); void setServiceListRelativePath(String relativePath); boolean filter(HttpServletRequest request, HttpServletResponse res); void invoke(HttpServletRequest request, HttpServletResponse res); boolean invoke(HttpServletRequest request, HttpServletResponse res, boolean returnErrors); void invokeDestination(final HttpServletRequest request, HttpServletResponse response,
                                  AbstractHTTPDestination d); static final String AUTH_SERVICE_LIST; static final String AUTH_SERVICE_LIST_REALM; }### Answer:
@Test public void testGenerateServiceListing() throws Exception { setReq(null, "/services", null, "true"); expectServiceListGeneratorCalled(); EasyMock.replay(req, registry, serviceListGenerator); TestServletController sc = new TestServletController(registry, serviceListGenerator); sc.invoke(req, res); assertFalse(sc.invokeDestinationCalled()); }
@Test public void testGenerateUnformattedServiceListing() throws Exception { req.getPathInfo(); EasyMock.expectLastCall().andReturn(null).anyTimes(); req.getContextPath(); EasyMock.expectLastCall().andReturn("").anyTimes(); req.getServletPath(); EasyMock.expectLastCall().andReturn("").anyTimes(); req.getRequestURI(); EasyMock.expectLastCall().andReturn("/services").times(2); req.getParameter("stylesheet"); EasyMock.expectLastCall().andReturn(null); req.getParameter("formatted"); EasyMock.expectLastCall().andReturn("false"); req.getRequestURL(); EasyMock.expectLastCall().andReturn(new StringBuffer("http: req.setAttribute(Message.BASE_PATH, "http: EasyMock.expectLastCall().anyTimes(); registry.getDestinationsPaths(); EasyMock.expectLastCall().andReturn(Collections.emptySet()).atLeastOnce(); registry.getDestinationForPath("", true); EasyMock.expectLastCall().andReturn(null).anyTimes(); expectServiceListGeneratorCalled(); EasyMock.replay(req, registry, serviceListGenerator); TestServletController sc = new TestServletController(registry, serviceListGenerator); sc.invoke(req, res); assertFalse(sc.invokeDestinationCalled()); }
@Test public void testHideServiceListing() throws Exception { req.getPathInfo(); EasyMock.expectLastCall().andReturn(null); registry.getDestinationForPath("", true); EasyMock.expectLastCall().andReturn(null).atLeastOnce(); AbstractHTTPDestination dest = EasyMock.createMock(AbstractHTTPDestination.class); registry.checkRestfulRequest(""); EasyMock.expectLastCall().andReturn(dest).atLeastOnce(); dest.getBus(); EasyMock.expectLastCall().andReturn(null).anyTimes(); dest.getMessageObserver(); EasyMock.expectLastCall().andReturn(EasyMock.createMock(MessageObserver.class)).atLeastOnce(); expectServiceListGeneratorNotCalled(); EasyMock.replay(req, registry, serviceListGenerator, dest); TestServletController sc = new TestServletController(registry, serviceListGenerator); sc.setHideServiceList(true); sc.invoke(req, res); assertTrue(sc.invokeDestinationCalled()); }