ControllerImpl implements Controller { @Override public void start() throws IllegalStateException { if (webServer != null) { throw new IllegalStateException("Webserver already started!"); } ServerSocket serverSocket; try { serverSocket = serverSocketFactory.createServerSocket(); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Unable to create server socket ", e); return; } webServer = new WebServer(serverSocket, serverConfigFactory.getServerConfig()); if (webServer.startServer()) { gui.start(); } else { webServer = null; } } ControllerImpl(final ServerConfigFactory serverConfigFactory,
                          final ServerSocketFactory serverSocketFactory,
                          final ServerGui gui); @Override WebServer getWebServer(); @Override void start(); @Override void stop();  }
@Test(expected = IllegalStateException.class) public void shouldThrowExceptionOnIllegalStart() { ControllerImpl controllerImpl = new ControllerImpl(serverConfigFactory, serverSocketFactory, serverGui); controllerImpl.start(); controllerImpl.start(); }
@Test public void shouldLogSituationOnExceptionOnCreateException() throws IOException { when(serverSocketFactory.createServerSocket()).thenThrow(new IOException("Something")); ControllerImpl controllerImpl = new ControllerImpl(serverConfigFactory, serverSocketFactory, serverGui); try { controllerImpl.start(); } catch (IllegalStateException e) { fail("Should start web server"); } }