counter: 1.2.11 - Refactored test-classes (DRY for test-config) counter-1.2.11
authorKai Moritz <kai@juplo.de>
Mon, 13 May 2024 19:11:38 +0000 (21:11 +0200)
committerKai Moritz <kai@juplo.de>
Tue, 14 May 2024 20:35:39 +0000 (22:35 +0200)
pom.xml
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

diff --git a/pom.xml b/pom.xml
index 2d65a21..5c0de9f 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
        </parent>
        <groupId>de.juplo.kafka.wordcount</groupId>
        <artifactId>counter</artifactId>
-       <version>1.2.10</version>
+       <version>1.2.11</version>
        <name>Wordcount-Counter</name>
        <description>Word-counting stream-processor of the multi-user wordcount-example</description>
        <properties>
index fea89ab..e0f4672 100644 (file)
@@ -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<String, Object> propertyMap = streamProcessorProperties
-                                       .entrySet()
-                                       .stream()
-                                       .collect(
-                                                       Collectors.toMap(
-                                                                       entry -> (String)entry.getKey(),
-                                                                       entry -> entry.getValue()
-                                                       ));
+                       Map<String, Object> propertyMap = convertToMap(streamProcessorProperties);
 
                        propertyMap.put(
                                        ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
@@ -120,14 +113,7 @@ public class CounterApplicationIT
                ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory(
                                Properties streamProcessorProperties)
                {
-                       Map<String, Object> propertyMap = streamProcessorProperties
-                                       .entrySet()
-                                       .stream()
-                                       .collect(
-                                                       Collectors.toMap(
-                                                                       entry -> (String)entry.getKey(),
-                                                                       entry -> entry.getValue()
-                                                       ));
+                       Map<String, Object> propertyMap = convertToMap(streamProcessorProperties);
 
                        propertyMap.put(
                                        ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,
index 1bdfd48..159123b 100644 (file)
@@ -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<String, Object> propertyMap = convertToMap(streamProcessorProperties);
 
-    Map<String, ?> 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<>();
index 5798fc3..c1dd45a 100644 (file)
@@ -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<String, Object> convertToMap(Properties properties)
+       {
+               return properties
+                               .entrySet()
+                               .stream()
+                               .collect(
+                                               Collectors.toMap(
+                                                               entry -> (String)entry.getKey(),
+                                                               entry -> entry.getValue()
+                                               ));
+       }
 }