splitter: 1.2.0 - `TestData.assertExpectedResult(..)`
authorKai Moritz <kai@juplo.de>
Sun, 2 Jun 2024 11:44:28 +0000 (13:44 +0200)
committerKai Moritz <kai@juplo.de>
Mon, 3 Jun 2024 07:34:40 +0000 (09:34 +0200)
src/test/java/de/juplo/kafka/wordcount/splitter/TestData.java

index 2af8644..e2bf9cc 100644 (file)
@@ -41,15 +41,14 @@ public class TestData
 
        static void assertExpectedMessages(MultiValueMap<String, TestWord> receivedMessages)
        {
-               MultiValueMap<String, TestWord> expected = new LinkedMultiValueMap<>();
-               expectedMessages.forEach(keyValue -> expected.add(keyValue.key, keyValue.value));
                await("Received expected messages")
                                .atMost(Duration.ofSeconds(5))
-                               .untilAsserted(() -> expected.forEach((user, word) ->
+                               .untilAsserted(() -> expectedMessages().forEach((user, word) ->
                                                assertThat(receivedMessages.get(user)).containsExactlyElementsOf(word)));
        }
 
-       static Stream<KeyValue<String, TestWord>> expectedMessages = Stream.of(
+       static final KeyValue<String, TestWord>[] EXPECTED_MESSAGES = new KeyValue[]
+       {
                        KeyValue.pair(
                                        "peter",
                                        TestWord.of("peter", "Hallo")),
@@ -85,5 +84,15 @@ public class TestData
                                        TestWord.of("peter", "nä")),
                        KeyValue.pair(
                                        "peter",
-                                       TestWord.of("peter", "Nümmäh")));
+                                       TestWord.of("peter", "Nümmäh")),
+       };
+
+       static MultiValueMap<String, TestWord> expectedMessages()
+       {
+               MultiValueMap<String, TestWord> expectedMessages = new LinkedMultiValueMap<>();
+               Stream
+                               .of(EXPECTED_MESSAGES)
+                               .forEach(keyValue -> expectedMessages.add(keyValue.key, keyValue.value));
+               return expectedMessages;
+       }
 }