top10: 1.2.1 - Refined `TestData` clearified concerns
authorKai Moritz <kai@juplo.de>
Sat, 8 Jun 2024 16:37:55 +0000 (18:37 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 8 Jun 2024 17:36:26 +0000 (19:36 +0200)
src/test/java/de/juplo/kafka/wordcount/top10/TestData.java
src/test/java/de/juplo/kafka/wordcount/top10/Top10ApplicationIT.java
src/test/java/de/juplo/kafka/wordcount/top10/Top10StreamProcessorTopologyTest.java

index cf52c1f..7a3a27e 100644 (file)
@@ -21,7 +21,12 @@ class TestData
        static final TestUser PETER = TestUser.of("peter");
        static final TestUser KLAUS = TestUser.of("klaus");
 
-       static final KeyValue<TestWord, TestCounter>[] INPUT_MESSAGES = new KeyValue[]
+       static final Stream<KeyValue<TestWord, TestCounter>> getInputMessages()
+       {
+               return Stream.of(INPUT_MESSAGES);
+       }
+
+       private static final KeyValue<TestWord, TestCounter>[] INPUT_MESSAGES = new KeyValue[]
        {
                        new KeyValue<>(
                                        TestWord.of(PETER.getUser(),"Hallo"),
@@ -72,7 +77,7 @@ class TestData
                assertRankingEqualsRankingFromLastMessage(KLAUS, store.get(userOf(KLAUS)));
        }
 
-       static User userOf(TestUser user)
+       private static User userOf(TestUser user)
        {
                return User.of(user.getUser());
        }
@@ -83,7 +88,7 @@ class TestData
                assertThat(countMessagesForUser(KLAUS, receivedMessages));
        }
 
-       static int countMessagesForUser(TestUser user, MultiValueMap<TestUser, TestRanking> messagesForUsers)
+       private static int countMessagesForUser(TestUser user, MultiValueMap<TestUser, TestRanking> messagesForUsers)
        {
                return messagesForUsers.get(user) == null
                                ? 0
@@ -97,13 +102,13 @@ class TestData
                assertRankingEqualsRankingFromLastMessage(KLAUS, getLastMessageFor(KLAUS, receivedMessages));
        }
 
-       static void assertRankingEqualsRankingFromLastMessage(TestUser user, Ranking ranking)
+       private static void assertRankingEqualsRankingFromLastMessage(TestUser user, Ranking ranking)
        {
                TestRanking testRanking = TestRanking.of(testEntriesOf(ranking.getEntries()));
                assertRankingEqualsRankingFromLastMessage(user, testRanking);
        }
 
-       static TestEntry[] testEntriesOf(Entry... entries)
+       private static TestEntry[] testEntriesOf(Entry... entries)
        {
                return Arrays
                                .stream(entries)
@@ -115,17 +120,17 @@ class TestData
                                .toArray(size -> new TestEntry[size]);
        }
 
-       static void assertRankingEqualsRankingFromLastMessage(TestUser user, TestRanking ranking)
+       private static void assertRankingEqualsRankingFromLastMessage(TestUser user, TestRanking ranking)
        {
                assertThat(ranking).isEqualTo(getLastMessageFor(user));
        }
 
-       static TestRanking getLastMessageFor(TestUser user)
+       private static TestRanking getLastMessageFor(TestUser user)
        {
                return getLastMessageFor(user, expectedMessages());
        }
 
-       static TestRanking getLastMessageFor(TestUser user, MultiValueMap<TestUser, TestRanking> messagesForUsers)
+       private static TestRanking getLastMessageFor(TestUser user, MultiValueMap<TestUser, TestRanking> messagesForUsers)
        {
                return messagesForUsers
                                .get(user)
@@ -133,7 +138,7 @@ class TestData
                                .reduce(null, (left, right) -> right);
        }
 
-       static KeyValue<TestUser, TestRanking>[] EXPECTED_MESSAGES = new KeyValue[]
+       private static KeyValue<TestUser, TestRanking>[] EXPECTED_MESSAGES = new KeyValue[]
        {
                        KeyValue.pair( // 0
                                        PETER,
@@ -193,7 +198,7 @@ class TestData
                                                        TestEntry.of("Müsch", 2l))),
        };
 
-       static MultiValueMap<TestUser, TestRanking> expectedMessages()
+       private static MultiValueMap<TestUser, TestRanking> expectedMessages()
        {
                MultiValueMap<TestUser, TestRanking> expectedMessages = new LinkedMultiValueMap<>();
                Stream
index a1bc1f0..f5ef236 100644 (file)
@@ -1,13 +1,16 @@
 package de.juplo.kafka.wordcount.top10;
 
-import de.juplo.kafka.wordcount.counter.TestWord;
 import de.juplo.kafka.wordcount.counter.TestCounter;
+import de.juplo.kafka.wordcount.counter.TestWord;
 import de.juplo.kafka.wordcount.query.TestRanking;
 import de.juplo.kafka.wordcount.query.TestUser;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.kafka.streams.state.KeyValueBytesStoreSupplier;
 import org.apache.kafka.streams.state.Stores;
-import org.junit.jupiter.api.*;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.TestConfiguration;
@@ -24,7 +27,6 @@ import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
 
 import java.time.Duration;
-import java.util.stream.Stream;
 
 import static de.juplo.kafka.wordcount.top10.Top10StreamProcessor.STORE_NAME;
 import static org.awaitility.Awaitility.await;
@@ -65,8 +67,8 @@ public class Top10ApplicationIT
        public static void testSendMessage(
                        @Autowired KafkaTemplate<TestWord, TestCounter> kafkaTemplate)
        {
-               Stream
-                               .of(TestData.INPUT_MESSAGES)
+               TestData
+                               .getInputMessages()
                                .forEach(kv ->
                                {
                                        try
index cd09c06..90d8e4c 100644 (file)
@@ -20,7 +20,6 @@ import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
 
 import java.util.Map;
-import java.util.stream.Stream;
 
 import static de.juplo.kafka.wordcount.top10.Top10ApplicationConfiguration.serializationConfig;
 
@@ -68,8 +67,8 @@ public class Top10StreamProcessorTopologyTest
   @Test
   public void test()
   {
-    Stream
-        .of(TestData.INPUT_MESSAGES)
+    TestData
+        .getInputMessages()
         .forEach(kv -> in.pipeInput(kv.key, kv.value));
 
     MultiValueMap<TestUser, TestRanking> receivedMessages = new LinkedMultiValueMap<>();