ServerFactory { public static void destroyServer(ServerConfig serverConfig) { try { Server server = serverConfig.getServer(); if (server != null) { serverConfig.setServer(null); SERVER_MAP.remove(Integer.toString(serverConfig.getPort())); server.destroy(); } } catch (Exception e) { LOGGER.error(LogCodes.getLog(LogCodes.ERROR_DESTROY_SERVER, serverConfig.getPort()), e); } }  synchronized static Server getServer(ServerConfig serverConfig); static List<Server> getServers(); static void destroyAll(); static void destroyServer(ServerConfig serverConfig);  }
@Test public void destroyServer() { ServerConfig serverConfig = new ServerConfig().setProtocol("test").setPort(1234); Server server = serverConfig.buildIfAbsent(); Assert.assertNotNull(server); Assert.assertEquals(1, ServerFactory.getServers().size()); serverConfig.destroy(); Assert.assertEquals(0, ServerFactory.getServers().size()); Assert.assertNull(serverConfig.getServer()); }