HttpServerFactory { public static HttpServer serverFor (HttpServerSettings serverConfig) { Objects.requireNonNull(serverConfig, "server config must not be null"); HttpServer httpServer = new HttpServer(); NetworkListener listener = new NetworkListener("root", serverConfig.interfaceName, serverConfig.port); if (serverConfig.isSslEnabled) { SSLContextConfigurator sslContextConfigurator = new SSLContextConfigurator(); sslContextConfigurator.setKeyStoreFile(serverConfig.sslKeyStorePath); if (serverConfig.sslKeyStorePass!=null) { sslContextConfigurator.setKeyStorePass(serverConfig.sslKeyStorePass); } sslContextConfigurator.setTrustStoreFile(serverConfig.sslTrustStorePath); if (serverConfig.sslTrustStorePass!=null) { sslContextConfigurator.setTrustStorePass(serverConfig.sslTrustStorePass); } boolean clientMode = false; boolean wantsClientAuth = serverConfig.sslNeedsClientAuth; SSLEngineConfigurator sslEngineConfigurator = new SSLEngineConfigurator( sslContextConfigurator, clientMode, serverConfig.sslNeedsClientAuth, wantsClientAuth); listener.setSecure(true); listener.setSSLEngineConfig(sslEngineConfigurator); } if (serverConfig.compressData) { listener.getCompressionConfig().setCompressionMode(CompressionConfig.CompressionMode.ON); listener.getCompressionConfig().setCompressibleMimeTypes(serverConfig.compressibleMimeTypes); } httpServer.addListener(listener); return httpServer; } private  HttpServerFactory(); static HttpServer serverFor(HttpServerSettings serverConfig);  }
@Test void serverCantBeCreatedWithoutConfig() { assertThrows(NullPointerException.class, () -> HttpServerFactory.serverFor(null)); }
@Test void serverNotAutomaticallyStarted() { HttpServerSettings rsc = HttpServerSettings.builder().interfaceName("localhost").port(10000).build(); HttpServer httpServer = HttpServerFactory.serverFor(rsc); MatcherAssert.assertThat(httpServer.isStarted(), Matchers.is(false)); }