Skip to content

Commit

Permalink
a reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jan 16, 2025
1 parent 3e5db39 commit 92592fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
13 changes: 2 additions & 11 deletions approvaltests-util/src/main/java/com/spun/util/io/NetUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -56,7 +52,6 @@ public static String loadWebPage(String url, String parameters)
}
}
}

public static String readWebpage(String query)
{
HttpURLConnection connection = null;
Expand All @@ -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);
}
Expand Down

0 comments on commit 92592fd

Please sign in to comment.