diff --git a/metafacture-io/src/test/java/org/metafacture/io/HttpOpenerTest.java b/metafacture-io/src/test/java/org/metafacture/io/HttpOpenerTest.java index 87dcdda39..dd3bdbb1a 100644 --- a/metafacture-io/src/test/java/org/metafacture/io/HttpOpenerTest.java +++ b/metafacture-io/src/test/java/org/metafacture/io/HttpOpenerTest.java @@ -330,16 +330,14 @@ private void shouldPerformRequest(final String input, final HttpOpener.Method me WireMock.stubFor(stub); - TestHelpers.assertReader(receiver, responseBody, () -> { + TestHelpers.assertReader(receiver, () -> { opener.process(String.format(input, baseUrl)); // use the opener a second time in a workflow: opener.process(String.format(input, baseUrl)); opener.closeStream(); - - return 2; - }); + }, responseBody, responseBody); WireMock.verify(request); } diff --git a/metafacture-io/src/test/java/org/metafacture/io/TestHelpers.java b/metafacture-io/src/test/java/org/metafacture/io/TestHelpers.java index bb4c7725e..722cefeb0 100644 --- a/metafacture-io/src/test/java/org/metafacture/io/TestHelpers.java +++ b/metafacture-io/src/test/java/org/metafacture/io/TestHelpers.java @@ -24,13 +24,15 @@ import java.io.File; import java.io.Reader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.function.Consumer; -import java.util.function.IntSupplier; public final class TestHelpers { public static void assertFile(final ObjectReceiver receiver, final String expected, final File file, final Consumer consumer) { - assertReader(receiver, expected, () -> { + assertReader(receiver, () -> { final FileOpener opener = new FileOpener(); if (consumer != null) { consumer.accept(opener); @@ -39,25 +41,18 @@ public static void assertFile(final ObjectReceiver receiver, final Strin opener.setReceiver(receiver); opener.process(file.getAbsolutePath()); opener.closeStream(); - - return 1; - }); + }, expected); } - public static void assertReader(final ObjectReceiver receiver, final String expected, final IntSupplier supplier) { - final StringBuilder sb = new StringBuilder(); - - Mockito.doAnswer(i -> { - sb.delete(0, sb.length()); - sb.append(ResourceUtil.readAll(i.getArgument(0))); - - return null; - }).when(receiver).process(Mockito.any(Reader.class)); + public static void assertReader(final ObjectReceiver receiver, final Runnable runnable, final String... expected) { + final List actual = new ArrayList<>(); + Mockito.doAnswer(i -> actual.add(ResourceUtil.readAll(i.getArgument(0)))).when(receiver).process(Mockito.any(Reader.class)); - final int times = supplier.getAsInt(); + runnable.run(); - Mockito.verify(receiver, Mockito.times(times)).process(Mockito.any(Reader.class)); - Assert.assertEquals(expected, sb.toString()); + Mockito.verify(receiver, Mockito.times(expected.length)).process(Mockito.any(Reader.class)); + Arrays.stream(expected).forEach(i -> Assert.assertEquals(i, actual.remove(0))); + Assert.assertEquals(0, actual.size()); } }