From 58681eb5c2ea655385c8209b07330e4ef0ab2c49 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 16 Jun 2024 21:17:27 +0200 Subject: [PATCH] counter: 1.3.1 - Refined `CounterStreamProcessor` (DRY for type-mapping) --- .../counter/CounterStreamProcessor.java | 16 ++++++++-------- .../CounterStreamProcessorTopologyTest.java | 14 +------------- 2 files changed, 9 insertions(+), 21 deletions(-) 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); } } -- 2.20.1