Skip to content

Commit 0aafe05

Browse files
committed
Clean up HttpOpener test. (#513)
1 parent 2ef2d3a commit 0aafe05

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

metafacture-io/src/test/java/org/metafacture/io/HttpOpenerTest.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package org.metafacture.io;
1818

19+
import org.metafacture.commons.ResourceUtil;
20+
import org.metafacture.framework.ObjectReceiver;
21+
1922
import com.github.tomakehurst.wiremock.client.MappingBuilder;
2023
import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder;
2124
import com.github.tomakehurst.wiremock.client.WireMock;
@@ -31,16 +34,16 @@
3134
import org.junit.ComparisonFailure;
3235
import org.junit.Rule;
3336
import org.junit.Test;
34-
import org.metafacture.commons.ResourceUtil;
35-
import org.metafacture.framework.ObjectReceiver;
3637
import org.mockito.ArgumentCaptor;
3738
import org.mockito.Captor;
3839
import org.mockito.Mock;
3940
import org.mockito.Mockito;
4041
import org.mockito.junit.MockitoJUnit;
4142
import org.mockito.junit.MockitoRule;
4243

43-
import java.io.*;
44+
import java.io.ByteArrayOutputStream;
45+
import java.io.IOException;
46+
import java.io.Reader;
4447
import java.util.Arrays;
4548
import java.util.function.BiConsumer;
4649
import java.util.function.Consumer;
@@ -63,15 +66,17 @@ public final class HttpOpenerTest {
6366

6467
private static final String REQUEST_BODY = "request body";
6568
private static final String RESPONSE_BODY = "response bödy"; // UTF-8
69+
6670
private static byte[] GZIPPED_RESPONSE_BODY;
6771
static {
68-
try {
69-
ByteArrayOutputStream out = new ByteArrayOutputStream();
70-
GZIPOutputStream gzip = new GZIPOutputStream(out);
72+
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
73+
final GZIPOutputStream gzip = new GZIPOutputStream(out);
7174
gzip.write(RESPONSE_BODY.getBytes("UTF-8"));
7275
gzip.close();
76+
7377
GZIPPED_RESPONSE_BODY = out.toByteArray();
74-
}catch (Exception e){
78+
}
79+
catch (final IOException e) {
7580
e.printStackTrace();
7681
}
7782
}
@@ -290,11 +295,9 @@ public void shouldPerformGetRequestWithErrorResponseAndWithoutErrorPrefixParamet
290295
}
291296

292297
@Test
293-
public void shouldPerformGetRequestWithGzipedContentEncoding() throws IOException {
298+
public void shouldPerformGetRequestWithGzippedContentEncoding() throws IOException {
294299
shouldPerformRequest(TEST_URL, HttpOpener.Method.GET, (o, u) -> o.setAcceptEncoding("gzip"),
295-
null, null,
296-
WireMock.ok().withBody(GZIPPED_RESPONSE_BODY).withHeaders(new HttpHeaders(new HttpHeader(HttpOpener.CONTENT_ENCODING_HEADER,"gzip"))),
297-
RESPONSE_BODY);
300+
null, null, WireMock.ok().withBody(GZIPPED_RESPONSE_BODY).withHeader(HttpOpener.CONTENT_ENCODING_HEADER, "gzip"), RESPONSE_BODY);
298301
}
299302

300303
private void shouldPerformRequest(final String input, final HttpOpener.Method method, final BiConsumer<HttpOpener, String> consumer, final String... headers) throws IOException {
@@ -308,6 +311,7 @@ private void shouldPerformRequest(final String input, final HttpOpener.Method me
308311
if (responseConsumer != null) {
309312
responseConsumer.accept(response);
310313
}
314+
311315
shouldPerformRequest(input, method,
312316
consumer, stubConsumer, requestConsumer,
313317
response, method.getResponseHasBody() ? RESPONSE_BODY : "");

0 commit comments

Comments
 (0)