diff --git a/approvaltests-util-tests/src/test/java/com/spun/util/io/NetUtilsTest.java b/approvaltests-util-tests/src/test/java/com/spun/util/io/NetUtilsTest.java index ee2343a42..508ccccc6 100644 --- a/approvaltests-util-tests/src/test/java/com/spun/util/io/NetUtilsTest.java +++ b/approvaltests-util-tests/src/test/java/com/spun/util/io/NetUtilsTest.java @@ -59,22 +59,20 @@ void testReadWebPageReturnsPageContent() Approvals.verify(s); } @Test - void testLoadWebPageWithQueryParams() throws InterruptedException { + void testLoadWebPageWithQueryParams() throws InterruptedException + { MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody("hello, world!")); - NetUtils.loadWebPage(server.url("/api").toString(), "query=param"); - RecordedRequest recordedRequest = server.takeRequest(); assertEquals("/api?query=param", recordedRequest.getPath()); } @Test - void testReadWebPageWithoutQueryParams() throws InterruptedException { + void testReadWebPageWithoutQueryParams() throws InterruptedException + { MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody("hello, world!")); - NetUtils.readWebpage(server.url("/api").toString()); - RecordedRequest recordedRequest = server.takeRequest(); assertEquals("/api", recordedRequest.getPath()); } diff --git a/approvaltests-util/src/main/java/com/spun/util/io/NetUtils.java b/approvaltests-util/src/main/java/com/spun/util/io/NetUtils.java index 0982d0e0a..f0224c331 100644 --- a/approvaltests-util/src/main/java/com/spun/util/io/NetUtils.java +++ b/approvaltests-util/src/main/java/com/spun/util/io/NetUtils.java @@ -26,13 +26,9 @@ public static String loadWebPage(String url, String parameters) connection = (HttpURLConnection) urlObj.openConnection(); connection.setRequestMethod("GET"); connection.connect(); - int responseCode = connection.getResponseCode(); if (responseCode != HttpURLConnection.HTTP_OK) - { - throw new RuntimeException("Failed to load web page, response code: " + responseCode); - } - + { throw new RuntimeException("Failed to load web page, response code: " + responseCode); } InputStream inputStream = connection.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); StringBuilder html = new StringBuilder(); @@ -56,7 +52,6 @@ public static String loadWebPage(String url, String parameters) } } } - public static String readWebpage(String query) { HttpURLConnection connection = null; @@ -66,13 +61,9 @@ public static String readWebpage(String query) connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); - int responseCode = connection.getResponseCode(); if (responseCode != HttpURLConnection.HTTP_OK) - { - throw new RuntimeException("Failed to read web page, response code: " + responseCode); - } - + { throw new RuntimeException("Failed to read web page, response code: " + responseCode); } InputStream inputStream = connection.getInputStream(); return FileUtils.readStream(inputStream); }