From: Kai Moritz Date: Sat, 8 Jun 2024 16:37:55 +0000 (+0200) Subject: top10: 1.2.1 - Refined `TestData` clearified concerns X-Git-Tag: top10-1.2.1~1 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=478b25d6700bd0a48b55647f09386f3b1d59fa29;p=demos%2Fkafka%2Fwordcount top10: 1.2.1 - Refined `TestData` clearified concerns --- diff --git a/src/test/java/de/juplo/kafka/wordcount/top10/TestData.java b/src/test/java/de/juplo/kafka/wordcount/top10/TestData.java index cf52c1f..7a3a27e 100644 --- a/src/test/java/de/juplo/kafka/wordcount/top10/TestData.java +++ b/src/test/java/de/juplo/kafka/wordcount/top10/TestData.java @@ -21,7 +21,12 @@ class TestData static final TestUser PETER = TestUser.of("peter"); static final TestUser KLAUS = TestUser.of("klaus"); - static final KeyValue[] INPUT_MESSAGES = new KeyValue[] + static final Stream> getInputMessages() + { + return Stream.of(INPUT_MESSAGES); + } + + private static final KeyValue[] 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 messagesForUsers) + private static int countMessagesForUser(TestUser user, MultiValueMap 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 messagesForUsers) + private static TestRanking getLastMessageFor(TestUser user, MultiValueMap messagesForUsers) { return messagesForUsers .get(user) @@ -133,7 +138,7 @@ class TestData .reduce(null, (left, right) -> right); } - static KeyValue[] EXPECTED_MESSAGES = new KeyValue[] + private static KeyValue[] EXPECTED_MESSAGES = new KeyValue[] { KeyValue.pair( // 0 PETER, @@ -193,7 +198,7 @@ class TestData TestEntry.of("Müsch", 2l))), }; - static MultiValueMap expectedMessages() + private static MultiValueMap expectedMessages() { MultiValueMap expectedMessages = new LinkedMultiValueMap<>(); Stream diff --git a/src/test/java/de/juplo/kafka/wordcount/top10/Top10ApplicationIT.java b/src/test/java/de/juplo/kafka/wordcount/top10/Top10ApplicationIT.java index a1bc1f0..f5ef236 100644 --- a/src/test/java/de/juplo/kafka/wordcount/top10/Top10ApplicationIT.java +++ b/src/test/java/de/juplo/kafka/wordcount/top10/Top10ApplicationIT.java @@ -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 kafkaTemplate) { - Stream - .of(TestData.INPUT_MESSAGES) + TestData + .getInputMessages() .forEach(kv -> { try diff --git a/src/test/java/de/juplo/kafka/wordcount/top10/Top10StreamProcessorTopologyTest.java b/src/test/java/de/juplo/kafka/wordcount/top10/Top10StreamProcessorTopologyTest.java index cd09c06..90d8e4c 100644 --- a/src/test/java/de/juplo/kafka/wordcount/top10/Top10StreamProcessorTopologyTest.java +++ b/src/test/java/de/juplo/kafka/wordcount/top10/Top10StreamProcessorTopologyTest.java @@ -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 receivedMessages = new LinkedMultiValueMap<>();