HttpsService extends AbstractIdleService { @Override protected void shutDown() throws Exception { if (server == null) { LOGGER.error("Server is already stopped"); } else { LOGGER.debug("stopping {}", serviceName()); try { for (Connector c : server.getConnectors()) { c.stop(); } } finally { server.stop(); server = null; } LOGGER.debug("stopped {}", serviceName()); } } @Inject  HttpsService(
            @Named("application.https.port") int httpsPort,
            @Named("application.https.idletimeout") int httpsIdleTimeout,
            @Named("application.httpconfig.output.buffersize") int httpConfigOutputBufferSize,
            @Named("application.ssl.keystore.path") String keyStorePath,
            @Named("application.ssl.keystore.password") String sslKeyStorePassword,
            @Named("application.ssl.keymanager.password") String sslKeyManagerPassword,
            @Named("application.http.context.path") String contextPath,
            GuiceFilter guiceFilter);   }
@Test public void stopable() throws Exception { Server server = createMockAndExpectNew(Server.class); String path = "/foo/bar/bop.txt"; HttpsService httpsService = new HttpsService(8443, 500000, 32768, path, "ThisIsATest", "ThisIsAnotherTest", "/", guiceFilter); setInternalState(server, "_lock", new Object()); setInternalState(httpsService, "server", server); expect(server.getConnectors()).andReturn(new Connector[]{}); setInternalState(server, "_state", 3); server.stop(); replay(server, Server.class); httpsService.shutDown(); }
@Test public void stopableWithConnectors() throws Exception { Server server = createMockAndExpectNew(Server.class); Connector connector = createMock(Connector.class); String path = "/foo/bar/bop.txt"; HttpsService httpsService = new HttpsService(8443, 500000, 32768, path, "ThisIsATest", "ThisIsAnotherTest", "/", guiceFilter); setInternalState(server, "_lock", new Object()); setInternalState(httpsService, "server", server); expect(server.getConnectors()).andReturn(new Connector[]{connector}); connector.stop(); setInternalState(server, "_state", 3); server.stop(); replay(server, Server.class); replay(connector, Connector.class); httpsService.shutDown(); }
@Test public void notStopableAlreadyStarted() throws Exception { Server server = createMock(Server.class); String path = "/foo/bar/bop.txt"; HttpsService httpsService = new HttpsService(8443, 500000, 32768, path, "ThisIsATest", "ThisIsAnotherTest", "/", guiceFilter); replay(server, Server.class); httpsService.shutDown(); verify(server, Server.class); }