HttpService extends AbstractIdleService { @Override protected void startUp() throws Exception { LOGGER.info("starting {}", serviceName()); if (server != null) { LOGGER.error("Server is already stopped"); return; } else { server = new Server(httpPort); } HandlerCollection handlers = new HandlerCollection(false); handlers.addHandler(makeMonitorHandler()); if (contentDirectory != null) { handlers.addHandler(makeContentHandler(contentDirectory)); } handlers.addHandler(makeContextHandler(guiceFilter)); handlers.addHandler(makeRequestLogHandler()); server.setHandler(handlers); server.start(); LOGGER.info("started {}", serviceName()); } @Inject  HttpService(
            @Named("application.http.port") int port,
            @Named("application.http.context.path") String contextPath,
            @Named("application.http.content.directory") @Nullable String contentDirectory,
            GuiceFilter guiceFilter);   }
@Test public void startable() throws Exception { int port = 8080; Server server = createMockAndExpectNew(Server.class, port); server.setHandler(isA(HandlerCollection.class)); server.start(); replay(server, Server.class); HttpService httpService = new HttpService(port, "/", null, guiceFilter); httpService.startUp(); verify(server, Server.class); }
@Test public void startableAndStopableWithEmptyContextPath() throws Exception { int port = 8080; Server server = createMockAndExpectNew(Server.class, port); server.setHandler(isA(HandlerCollection.class)); server.start(); replay(server, Server.class); HttpService httpService = new HttpService(port, "", null, guiceFilter); httpService.startUp(); verify(server, Server.class); }
@Test public void notStartableAlreadyStarted() throws Exception { int port = 8080; Server server = createMock(Server.class, port); HttpService httpService = new HttpService(port, null, null, guiceFilter); setInternalState(httpService, "server", server); replay(server, Server.class); httpService.startUp(); verify(server, Server.class); }