DemoServer { public String getURL() { return "http: } DemoServer(InetSocketAddress inetSocketAddress);  DemoServer(int port); void start(); void stop(int delay); String getURL(); static void main(String[] args);  }
@Test public void shouldShowFrontPage() throws IOException { HttpURLConnection connection = (HttpURLConnection) new URL(server.getURL()).openConnection(); assertThat(connection.getResponseCode()).isEqualTo(200); StringWriter writer = new StringWriter(); new BufferedReader(new InputStreamReader(connection.getInputStream())).transferTo(writer); assertThat(writer.toString()) .contains("<h1>Hello World</h1>"); }
@Test public void shouldShowJson() throws IOException { HttpURLConnection connection = (HttpURLConnection) new URL(server.getURL() + "/demo/openapi.yaml").openConnection(); assertThat(connection.getResponseCode()).isEqualTo(200); StringWriter writer = new StringWriter(); new BufferedReader(new InputStreamReader(connection.getInputStream())).transferTo(writer); assertThat(writer.toString()) .contains("Swagger Petstore"); }