[Optimize] using try-with-resources
This commit is contained in:
parent
223c0bd32f
commit
7eef9b46b7
|
@ -138,15 +138,14 @@ class CompletableFutureTimeoutUnitTest {
|
||||||
try {
|
try {
|
||||||
URL url = new URL("http://localhost:8080/api/dummy");
|
URL url = new URL("http://localhost:8080/api/dummy");
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
try {
|
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||||
String inputLine;
|
String inputLine;
|
||||||
StringBuffer response = new StringBuffer();
|
StringBuffer response = new StringBuffer();
|
||||||
|
|
||||||
while ((inputLine = in.readLine()) != null) {
|
while ((inputLine = in.readLine()) != null) {
|
||||||
response.append(inputLine);
|
response.append(inputLine);
|
||||||
}
|
}
|
||||||
in.close();
|
|
||||||
|
|
||||||
return response.toString();
|
return response.toString();
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -158,6 +157,7 @@ class CompletableFutureTimeoutUnitTest {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void whenorTimeout_thenGetThrow() {
|
void whenorTimeout_thenGetThrow() {
|
||||||
CompletableFuture<String> productDataFuture = fetchProductData();
|
CompletableFuture<String> productDataFuture = fetchProductData();
|
||||||
|
|
Loading…
Reference in New Issue