From: Kai Moritz Date: Mon, 27 May 2024 20:28:28 +0000 (+0200) Subject: counter: 1.2.15 - `TestData` only holds and asserts the test-data X-Git-Tag: counter-1.2.15~12 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=48dabf093db63d517252f47b15f597e80852e9d4;p=demos%2Fkafka%2Fwordcount counter: 1.2.15 - `TestData` only holds and asserts the test-data --- diff --git a/src/test/java/de/juplo/kafka/wordcount/counter/CounterApplicationIT.java b/src/test/java/de/juplo/kafka/wordcount/counter/CounterApplicationIT.java index 3889cea..ad4faf2 100644 --- a/src/test/java/de/juplo/kafka/wordcount/counter/CounterApplicationIT.java +++ b/src/test/java/de/juplo/kafka/wordcount/counter/CounterApplicationIT.java @@ -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)) diff --git a/src/test/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessorTopologyTest.java b/src/test/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessorTopologyTest.java index 1b3e1e4..8e09d0c 100644 --- a/src/test/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessorTopologyTest.java +++ b/src/test/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessorTopologyTest.java @@ -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 receivedMessages = new LinkedMultiValueMap<>(); out diff --git a/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java b/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java index 6110f80..5dc8bc2 100644 --- a/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java +++ b/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java @@ -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 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 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 expectedMessages; - static + static MultiValueMap expectedMessages() { - expectedMessages = new LinkedMultiValueMap<>(); + MultiValueMap expectedMessages = new LinkedMultiValueMap<>(); Stream .of(EXPECTED_MESSAGES) .forEach(keyValue -> expectedMessages.add(keyValue.key, keyValue.value)); + return expectedMessages; } static Map convertToMap(Properties properties)