From: Kai Moritz Date: Mon, 13 May 2024 19:11:38 +0000 (+0200) Subject: counter: 1.2.11 - Refactored test-classes (DRY for test-config) X-Git-Tag: counter-1.2.11 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=15f12279802c23601b648c631d044c3c77f40902;p=demos%2Fkafka%2Fwordcount counter: 1.2.11 - Refactored test-classes (DRY for test-config) --- diff --git a/pom.xml b/pom.xml index 2d65a21..5c0de9f 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ de.juplo.kafka.wordcount counter - 1.2.10 + 1.2.11 Wordcount-Counter Word-counting stream-processor of the multi-user wordcount-example 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 fea89ab..e0f4672 100644 --- a/src/test/java/de/juplo/kafka/wordcount/counter/CounterApplicationIT.java +++ b/src/test/java/de/juplo/kafka/wordcount/counter/CounterApplicationIT.java @@ -27,9 +27,9 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; -import java.util.stream.Collectors; import static de.juplo.kafka.wordcount.counter.CounterApplicationIT.*; +import static de.juplo.kafka.wordcount.counter.TestData.convertToMap; import static org.awaitility.Awaitility.*; @@ -97,14 +97,7 @@ public class CounterApplicationIT @Bean ProducerFactory producerFactory(Properties streamProcessorProperties) { - Map propertyMap = streamProcessorProperties - .entrySet() - .stream() - .collect( - Collectors.toMap( - entry -> (String)entry.getKey(), - entry -> entry.getValue() - )); + Map propertyMap = convertToMap(streamProcessorProperties); propertyMap.put( ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, @@ -120,14 +113,7 @@ public class CounterApplicationIT ConcurrentKafkaListenerContainerFactory kafkaListenerContainerFactory( Properties streamProcessorProperties) { - Map propertyMap = streamProcessorProperties - .entrySet() - .stream() - .collect( - Collectors.toMap( - entry -> (String)entry.getKey(), - entry -> entry.getValue() - )); + Map propertyMap = convertToMap(streamProcessorProperties); propertyMap.put( ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, 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 1bdfd48..159123b 100644 --- a/src/test/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessorTopologyTest.java +++ b/src/test/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessorTopologyTest.java @@ -10,7 +10,8 @@ import org.springframework.kafka.support.serializer.JsonSerializer; import java.util.List; import java.util.Map; import java.util.Properties; -import java.util.stream.Collectors; + +import static de.juplo.kafka.wordcount.counter.TestData.convertToMap; public class CounterStreamProcessorTopologyTest @@ -30,15 +31,8 @@ public class CounterStreamProcessorTopologyTest new CounterApplicationConfiguriation(); Properties streamProcessorProperties = applicationConfiguriation.streamProcessorProperties(new CounterApplicationProperties()); + Map propertyMap = convertToMap(streamProcessorProperties); - Map propertyMap = streamProcessorProperties - .entrySet() - .stream() - .collect( - Collectors.toMap( - entry -> (String)entry.getKey(), - entry -> entry.getValue() - )); JsonSerde keySerde = new JsonSerde<>(); keySerde.configure(propertyMap, true); JsonSerde valueSerde = new JsonSerde<>(); 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 5798fc3..c1dd45a 100644 --- a/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java +++ b/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java @@ -3,7 +3,10 @@ package de.juplo.kafka.wordcount.counter; import org.apache.kafka.streams.KeyValue; import java.util.List; +import java.util.Map; +import java.util.Properties; import java.util.function.BiConsumer; +import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; @@ -104,4 +107,16 @@ class TestData Word.of("klaus","s"), WordCount.of("klaus","s",3)), }; + + static Map convertToMap(Properties properties) + { + return properties + .entrySet() + .stream() + .collect( + Collectors.toMap( + entry -> (String)entry.getKey(), + entry -> entry.getValue() + )); + } }