Skip to content

Commit

Permalink
refactor (E2E): Reduce source complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
JPPortier committed Oct 2, 2024
1 parent ac93425 commit 456e1a9
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions client/src/test/java/com/sinch/sdk/e2e/domains/WebhooksHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ public static <T> Response<T> callURL(URL url, Function<String, T> parseEvent)

byte[] buffer = new byte[1024];
int bytesRead;
InputStream inputStream = con.getInputStream();
while ((bytesRead = inputStream.read(buffer)) != -1) {
byteArrayOutputStream.write(buffer, 0, bytesRead);
try (InputStream inputStream = con.getInputStream()) {
while ((bytesRead = inputStream.read(buffer)) != -1) {
byteArrayOutputStream.write(buffer, 0, bytesRead);
}
}

Response<T> response = new Response<>();
response.headers = transformHeaders(con.getHeaderFields());
response.rawPayload = byteArrayOutputStream.toString("UTF-8");
Expand All @@ -38,18 +40,10 @@ static Map<String, String> transformHeaders(Map<String, List<String>> headers) {
return null;
}
HashMap<String, String> newMap = new HashMap<>();
headers.forEach((key, value) -> newMap.put(key, concatHeaderValues(value)));
headers.forEach((key, value) -> newMap.put(key, String.join(";", value)));
return newMap;
}

static String concatHeaderValues(List<String> values) {
if (null == values) {
return null;
}
return values.stream()
.reduce(null, (previous, current) -> (null != previous ? previous + ";" : "") + current);
}

public static class Response<T> {
public Map<String, String> headers;
public String rawPayload;
Expand Down

0 comments on commit 456e1a9

Please sign in to comment.