SimpleFileServer implements Runnable { public InetSocketAddress getAddress() { if (server == null) { throw new IllegalStateException("Fileserver is not running. Cannot get address."); } else { return NetworkUtils.hostSocket(server.getAddress().getPort()); } } SimpleFileServer(String file); void serve(); InetSocketAddress getAddress(); @Override void run();  }
@Test(expected = IllegalStateException.class) public void shouldErrorIfGettingAddressBeforeStart() { final SimpleFileServer simpleFileServer = new SimpleFileServer(TEST_FILE); simpleFileServer.getAddress(); }