MockWebServer implements TestRule { public synchronized void shutdown() throws IOException { if (!started) return; if (serverSocket == null) throw new IllegalStateException("shutdown() before start()"); serverSocket.close(); try { if (!executor.awaitTermination(5, TimeUnit.SECONDS)) { throw new IOException("Gave up waiting for executor to shut down"); } } catch (InterruptedException e) { throw new AssertionError(); } }  @Override Statement apply(final Statement base, Description description); int getPort(); String getHostName(); Proxy toProxyAddress(); void setServerSocketFactory(ServerSocketFactory serverSocketFactory); HttpUrl url(String path); void setBodyLimit(long maxBodyLength); void setProtocolNegotiationEnabled(boolean protocolNegotiationEnabled); void setProtocols(List<Protocol> protocols); void useHttps(SSLSocketFactory sslSocketFactory, boolean tunnelProxy); RecordedRequest takeRequest(); RecordedRequest takeRequest(long timeout, TimeUnit unit); int getRequestCount(); void enqueue(MockResponse response); void start(); void start(int port); void start(InetAddress inetAddress, int port); synchronized void shutdown(); void setDispatcher(Dispatcher dispatcher); @Override String toString();  }
@Test public void shutdownWithoutStart() throws IOException { MockWebServer server = new MockWebServer(); server.shutdown(); }