16
16
17
17
package org .metafacture .io ;
18
18
19
+ import org .metafacture .commons .ResourceUtil ;
20
+ import org .metafacture .framework .ObjectReceiver ;
21
+
19
22
import com .github .tomakehurst .wiremock .client .MappingBuilder ;
20
23
import com .github .tomakehurst .wiremock .client .ResponseDefinitionBuilder ;
21
24
import com .github .tomakehurst .wiremock .client .WireMock ;
31
34
import org .junit .ComparisonFailure ;
32
35
import org .junit .Rule ;
33
36
import org .junit .Test ;
34
- import org .metafacture .commons .ResourceUtil ;
35
- import org .metafacture .framework .ObjectReceiver ;
36
37
import org .mockito .ArgumentCaptor ;
37
38
import org .mockito .Captor ;
38
39
import org .mockito .Mock ;
39
40
import org .mockito .Mockito ;
40
41
import org .mockito .junit .MockitoJUnit ;
41
42
import org .mockito .junit .MockitoRule ;
42
43
43
- import java .io .*;
44
+ import java .io .ByteArrayOutputStream ;
45
+ import java .io .IOException ;
46
+ import java .io .Reader ;
44
47
import java .util .Arrays ;
45
48
import java .util .function .BiConsumer ;
46
49
import java .util .function .Consumer ;
@@ -63,15 +66,17 @@ public final class HttpOpenerTest {
63
66
64
67
private static final String REQUEST_BODY = "request body" ;
65
68
private static final String RESPONSE_BODY = "response bödy" ; // UTF-8
69
+
66
70
private static byte [] GZIPPED_RESPONSE_BODY ;
67
71
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 );
71
74
gzip .write (RESPONSE_BODY .getBytes ("UTF-8" ));
72
75
gzip .close ();
76
+
73
77
GZIPPED_RESPONSE_BODY = out .toByteArray ();
74
- }catch (Exception e ){
78
+ }
79
+ catch (final IOException e ) {
75
80
e .printStackTrace ();
76
81
}
77
82
}
@@ -290,11 +295,9 @@ public void shouldPerformGetRequestWithErrorResponseAndWithoutErrorPrefixParamet
290
295
}
291
296
292
297
@ Test
293
- public void shouldPerformGetRequestWithGzipedContentEncoding () throws IOException {
298
+ public void shouldPerformGetRequestWithGzippedContentEncoding () throws IOException {
294
299
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 );
298
301
}
299
302
300
303
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
308
311
if (responseConsumer != null ) {
309
312
responseConsumer .accept (response );
310
313
}
314
+
311
315
shouldPerformRequest (input , method ,
312
316
consumer , stubConsumer , requestConsumer ,
313
317
response , method .getResponseHasBody () ? RESPONSE_BODY : "" );
0 commit comments