From: Kai Moritz Date: Sun, 16 Jun 2024 19:17:27 +0000 (+0200) Subject: counter: 1.3.1 - Refined `CounterStreamProcessor` (DRY for type-mapping) X-Git-Tag: counter-1.3.1 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=58681eb5c2ea655385c8209b07330e4ef0ab2c49;p=demos%2Fkafka%2Fwordcount counter: 1.3.1 - Refined `CounterStreamProcessor` (DRY for type-mapping) --- diff --git a/src/main/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessor.java b/src/main/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessor.java index c983a25..2304e55 100644 --- a/src/main/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessor.java +++ b/src/main/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessor.java @@ -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 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(",")); } } 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 06a0798..cfb6bd8 100644 --- a/src/test/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessorTopologyTest.java +++ b/src/test/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessorTopologyTest.java @@ -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 typeMappings() - { - return Map.of( - "word", TestOutputWord.class, - "counter", TestOutputWordCounter.class); + return CounterStreamProcessor.typeMappingsConfig(TestOutputWord.class, TestOutputWordCounter.class); } }