counter: 1.2.15 - `TestData` only holds and asserts the test-data
authorKai Moritz <kai@juplo.de>
Mon, 27 May 2024 20:28:28 +0000 (22:28 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 8 Jun 2024 11:33:30 +0000 (13:33 +0200)
src/test/java/de/juplo/kafka/wordcount/counter/CounterApplicationIT.java
src/test/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessorTopologyTest.java
src/test/java/de/juplo/kafka/wordcount/counter/TestData.java

index 3889cea..ad4faf2 100644 (file)
@@ -20,6 +20,7 @@ import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
 
 import java.time.Duration;
+import java.util.stream.Stream;
 
 import static de.juplo.kafka.wordcount.counter.CounterApplicationIT.TOPIC_IN;
 import static de.juplo.kafka.wordcount.counter.CounterApplicationIT.TOPIC_OUT;
@@ -66,7 +67,9 @@ public class CounterApplicationIT
        @Test
        void testSendMessage()
        {
-               TestData.injectInputMessages((key, value) -> kafkaTemplate.send(TOPIC_IN, key, value));
+               Stream
+                               .of(TestData.INPUT_MESSAGES)
+                               .forEach(word -> kafkaTemplate.send(TOPIC_IN, word.getUser(), word));
 
                await("Expected messages")
                                .atMost(Duration.ofSeconds(10))
index 1b3e1e4..8e09d0c 100644 (file)
@@ -17,6 +17,7 @@ import org.springframework.util.MultiValueMap;
 
 import java.util.Map;
 import java.util.Properties;
+import java.util.stream.Stream;
 
 import static de.juplo.kafka.wordcount.counter.TestData.convertToMap;
 import static de.juplo.kafka.wordcount.counter.TestData.parseHeader;
@@ -72,7 +73,9 @@ public class CounterStreamProcessorTopologyTest
   @Test
   public void test()
   {
-    TestData.injectInputMessages((key, value) -> in.pipeInput(key, value));
+    Stream
+        .of(TestData.INPUT_MESSAGES)
+        .forEach(word -> in.pipeInput(word.getUser(), word));
 
     MultiValueMap<Word, WordCounter> receivedMessages = new LinkedMultiValueMap<>();
     out
index 6110f80..5dc8bc2 100644 (file)
@@ -8,7 +8,6 @@ import org.springframework.util.MultiValueMap;
 
 import java.util.Map;
 import java.util.Properties;
-import java.util.function.BiConsumer;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -17,13 +16,6 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 class TestData
 {
-       static void injectInputMessages(BiConsumer<String, Word> consumer)
-       {
-               Stream
-                               .of(INPUT_MESSAGES)
-                               .forEach(word -> consumer.accept(word.getUser(), word));
-       }
-
        static final Word[] INPUT_MESSAGES = new Word[]
        {
                        Word.of("peter","Hallo"),
@@ -41,7 +33,7 @@ class TestData
 
        static void assertExpectedMessages(MultiValueMap<Word, WordCounter> receivedMessages)
        {
-               expectedMessages.forEach(
+               expectedMessages().forEach(
                                (word, counter) ->
                                                assertThat(receivedMessages.get(word))
                                                                .containsExactlyElementsOf(counter));
@@ -84,13 +76,13 @@ class TestData
                                        WordCounter.of("klaus","s",3)),
        };
 
-       static MultiValueMap<Word, WordCounter> expectedMessages;
-       static
+       static MultiValueMap<Word, WordCounter> expectedMessages()
        {
-               expectedMessages = new LinkedMultiValueMap<>();
+               MultiValueMap<Word, WordCounter> expectedMessages = new LinkedMultiValueMap<>();
                Stream
                                .of(EXPECTED_MESSAGES)
                                .forEach(keyValue -> expectedMessages.add(keyValue.key, keyValue.value));
+               return expectedMessages;
        }
 
        static Map<String, Object> convertToMap(Properties properties)