### Question:
HttpServerProvider implements ServerProvider<HttpServer>, ServerCreator<HttpServer> { @Override public synchronized HttpServer getServer(String host, String protocol, int port) { String connectionKey = createConnectionKey(protocol, host, port); if (!myServers.containsKey(connectionKey)) { HttpServer server = createServer(host, protocol, port); myServers.put(connectionKey, server); notifyListeners(server); } return myServers.get(connectionKey); } HttpServerProvider(Toolbox toolbox, ServerFactory factory); @Override void addServerChangedListener(ServerChangedListener<HttpServer> listener); @Override synchronized void clearServers(); void close(); @Override HttpServer createServer(URL url); @Override synchronized HttpServer getServer(String host, String protocol, int port); @Override HttpServer getServer(URL url); @Override void removeServerChangedListener(ServerChangedListener<HttpServer> listener);  }### Answer:
@Test public void testGetServerAlreadyCreated() throws GeneralSecurityException, IOException { EasyMockSupport support = new EasyMockSupport(); Toolbox toolbox = createToolbox(support); HttpServer server = support.createMock(HttpServer.class); int port = 1000; String serverKey = ourHost + ':' + port; ServerFactory factory = createFactory(support, port, serverKey, toolbox, server); support.replayAll(); URL url = new URL(ourProtocol + ": HttpServerProvider provider = new HttpServerProvider(toolbox, factory); HttpServer actualServer = provider.getServer(url); assertEquals(server, actualServer); HttpServer sameServer = provider.getServer(url); assertSame(actualServer, sameServer); support.verifyAll(); }
@Test public void testGetServerURL() throws GeneralSecurityException, IOException { EasyMockSupport support = new EasyMockSupport(); Toolbox toolbox = createToolbox(support); HttpServer server = support.createMock(HttpServer.class); int port = 1000; String serverKey = ourHost + ':' + port; ServerFactory factory = createFactory(support, port, serverKey, toolbox, server); support.replayAll(); URL url = new URL(ourProtocol + ": HttpServerProvider provider = new HttpServerProvider(toolbox, factory); HttpServer actualServer = provider.getServer(url); assertEquals(server, actualServer); support.verifyAll(); }
@Test public void testGetServerURLNoPort() throws GeneralSecurityException, IOException { EasyMockSupport support = new EasyMockSupport(); Toolbox toolbox = createToolbox(support); HttpServer server = support.createMock(HttpServer.class); URL url = new URL(ourProtocol + ": int port = url.getDefaultPort(); String serverKey = ourHost + ":" + port; ServerFactory factory = createFactory(support, port, serverKey, toolbox, server); support.replayAll(); HttpServerProvider provider = new HttpServerProvider(toolbox, factory); HttpServer actualServer = provider.getServer(url); assertEquals(server, actualServer); assertTrue(-1 != port); support.verifyAll(); }