counter: 1.3.1 - Refined `CounterStreamProcessor` (DRY for type-mapping) counter-1.3.1
authorKai Moritz <kai@juplo.de>
Sun, 16 Jun 2024 19:17:27 +0000 (21:17 +0200)
committerKai Moritz <kai@juplo.de>
Sun, 16 Jun 2024 19:18:40 +0000 (21:18 +0200)
src/main/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessor.java
src/test/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessorTopologyTest.java

index c983a25..2304e55 100644 (file)
@@ -114,17 +114,17 @@ public class CounterStreamProcessor
 
        private static String typeMappingsConfig()
        {
-               return typeMappings()
-                               .entrySet()
-                               .stream()
-                               .map(entry -> entry.getKey() + ":" + entry.getValue().getName())
-                               .collect(Collectors.joining(","));
+               return typeMappingsConfig(Word.class, WordCounter.class);
        }
 
-       private static Map<String, Class> typeMappings()
+       public static String typeMappingsConfig(Class wordClass, Class wordCounterClass)
        {
                return Map.of(
-                               "word", Word.class,
-                               "counter", WordCounter.class);
+                                               "word", wordClass,
+                                               "counter", wordCounterClass)
+                               .entrySet()
+                               .stream()
+                               .map(entry -> entry.getKey() + ":" + entry.getValue().getName())
+                               .collect(Collectors.joining(","));
        }
 }
index 06a0798..cfb6bd8 100644 (file)
@@ -20,7 +20,6 @@ import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
 
 import java.util.Map;
-import java.util.stream.Collectors;
 
 import static de.juplo.kafka.wordcount.counter.CounterApplicationConfiguriation.serializationConfig;
 import static de.juplo.kafka.wordcount.counter.CounterStreamProcessor.STORE_NAME;
@@ -107,17 +106,6 @@ public class CounterStreamProcessorTopologyTest
 
   private static String typeMappingsConfig()
   {
-    return typeMappings()
-        .entrySet()
-        .stream()
-        .map(entry -> entry.getKey() + ":" + entry.getValue().getName())
-        .collect(Collectors.joining(","));
-  }
-
-  private static Map<String, Class> typeMappings()
-  {
-    return Map.of(
-        "word", TestOutputWord.class,
-        "counter", TestOutputWordCounter.class);
+    return CounterStreamProcessor.typeMappingsConfig(TestOutputWord.class, TestOutputWordCounter.class);
   }
 }