diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/WebhooksHelper.java b/client/src/test/java/com/sinch/sdk/e2e/domains/WebhooksHelper.java index 0a3ea49f..45deaf9d 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/WebhooksHelper.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/WebhooksHelper.java @@ -22,10 +22,12 @@ public static Response callURL(URL url, Function 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 response = new Response<>(); response.headers = transformHeaders(con.getHeaderFields()); response.rawPayload = byteArrayOutputStream.toString("UTF-8"); @@ -38,18 +40,10 @@ static Map transformHeaders(Map> headers) { return null; } HashMap 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 values) { - if (null == values) { - return null; - } - return values.stream() - .reduce(null, (previous, current) -> (null != previous ? previous + ";" : "") + current); - } - public static class Response { public Map headers; public String rawPayload;