|
16 | 16 |
|
17 | 17 | package org.metafacture.io; |
18 | 18 |
|
19 | | -import org.metafacture.commons.ResourceUtil; |
20 | 19 | import org.metafacture.framework.ObjectReceiver; |
21 | 20 |
|
22 | 21 | import com.github.tomakehurst.wiremock.client.MappingBuilder; |
23 | 22 | import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; |
24 | 23 | import com.github.tomakehurst.wiremock.client.WireMock; |
25 | 24 | import com.github.tomakehurst.wiremock.core.WireMockConfiguration; |
26 | | -import com.github.tomakehurst.wiremock.http.HttpHeader; |
27 | | -import com.github.tomakehurst.wiremock.http.HttpHeaders; |
28 | 25 | import com.github.tomakehurst.wiremock.http.RequestMethod; |
29 | 26 | import com.github.tomakehurst.wiremock.junit.WireMockRule; |
30 | 27 | import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder; |
|
34 | 31 | import org.junit.ComparisonFailure; |
35 | 32 | import org.junit.Rule; |
36 | 33 | import org.junit.Test; |
37 | | -import org.mockito.ArgumentCaptor; |
38 | | -import org.mockito.Captor; |
39 | 34 | import org.mockito.Mock; |
40 | | -import org.mockito.Mockito; |
41 | 35 | import org.mockito.junit.MockitoJUnit; |
42 | 36 | import org.mockito.junit.MockitoRule; |
43 | 37 |
|
|
49 | 43 | import java.util.function.Consumer; |
50 | 44 | import java.util.zip.GZIPOutputStream; |
51 | 45 |
|
52 | | -import static org.mockito.Mockito.times; |
53 | | - |
54 | 46 | /** |
55 | 47 | * Tests for class {@link HttpOpener}. |
56 | 48 | * |
@@ -92,9 +84,6 @@ public final class HttpOpenerTest { |
92 | 84 | @Mock |
93 | 85 | private ObjectReceiver<Reader> receiver; |
94 | 86 |
|
95 | | - @Captor |
96 | | - private ArgumentCaptor<Reader> processedObject; |
97 | | - |
98 | 87 | @Test |
99 | 88 | public void shouldPerformGetRequestWithInputAsUrlByDefault() throws IOException { |
100 | 89 | shouldPerformRequest(TEST_URL, HttpOpener.Method.GET, (o, u) -> {}); |
@@ -341,17 +330,18 @@ private void shouldPerformRequest(final String input, final HttpOpener.Method me |
341 | 330 |
|
342 | 331 | WireMock.stubFor(stub); |
343 | 332 |
|
344 | | - opener.process(String.format(input, baseUrl)); |
| 333 | + TestHelpers.assertReader(receiver, responseBody, () -> { |
| 334 | + opener.process(String.format(input, baseUrl)); |
345 | 335 |
|
346 | | - // use the opener a second time in a workflow: |
347 | | - opener.process(String.format(input, baseUrl)); |
| 336 | + // use the opener a second time in a workflow: |
| 337 | + opener.process(String.format(input, baseUrl)); |
348 | 338 |
|
349 | | - opener.closeStream(); |
| 339 | + opener.closeStream(); |
350 | 340 |
|
351 | | - WireMock.verify(request); |
| 341 | + return 2; |
| 342 | + }); |
352 | 343 |
|
353 | | - Mockito.verify(receiver, times(2)).process(processedObject.capture()); |
354 | | - Assert.assertEquals(responseBody, ResourceUtil.readAll(processedObject.getValue())); |
| 344 | + WireMock.verify(request); |
355 | 345 | } |
356 | 346 |
|
357 | 347 | } |
0 commit comments