X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fde%2Fjuplo%2Fkafka%2Fwordcount%2Fcounter%2FTestData.java;h=862eb2bc67463437168bc94db062c62d8d3cdb5f;hb=58681eb5c2ea655385c8209b07330e4ef0ab2c49;hp=4e431e15106c5071a09bd8ebb213b7d49c5719df;hpb=3eb1ec997478982fffb31f09c21e756b529e474a;p=demos%2Fkafka%2Fwordcount diff --git a/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java b/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java index 4e431e1..862eb2b 100644 --- a/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java +++ b/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java @@ -1,5 +1,6 @@ package de.juplo.kafka.wordcount.counter; +import de.juplo.kafka.wordcount.splitter.TestInputUser; import de.juplo.kafka.wordcount.splitter.TestInputWord; import de.juplo.kafka.wordcount.top10.TestOutputWord; import de.juplo.kafka.wordcount.top10.TestOutputWordCounter; @@ -8,7 +9,6 @@ import org.apache.kafka.streams.state.ReadOnlyKeyValueStore; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import java.util.function.Consumer; import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; @@ -31,53 +31,48 @@ class TestData static final TestOutputWord KLAUS_MÜSCH = TestOutputWord.of(KLAUS, WORD_MÜSCH); static final TestOutputWord KLAUS_S = TestOutputWord.of(KLAUS, WORD_S); - private static final KeyValue[] INPUT_MESSAGES = new KeyValue[] + private static final KeyValue[] INPUT_MESSAGES = new KeyValue[] { - new KeyValue<>( - PETER, + KeyValue.pair( + TestInputUser.of(PETER), TestInputWord.of(PETER, WORD_HALLO)), - new KeyValue<>( - KLAUS, + KeyValue.pair( + TestInputUser.of(KLAUS), TestInputWord.of(KLAUS, WORD_MÜSCH)), - new KeyValue<>( - PETER, + KeyValue.pair( + TestInputUser.of(PETER), TestInputWord.of(PETER, WORD_WELT)), - new KeyValue<>( - KLAUS, + KeyValue.pair( + TestInputUser.of(KLAUS), TestInputWord.of(KLAUS, WORD_MÜSCH)), - new KeyValue<>( - KLAUS, + KeyValue.pair( + TestInputUser.of(KLAUS), TestInputWord.of(KLAUS, WORD_S)), - new KeyValue<>( - PETER, + KeyValue.pair( + TestInputUser.of(PETER), TestInputWord.of(PETER, WORD_BOÄH)), - new KeyValue<>( - PETER, + KeyValue.pair( + TestInputUser.of(PETER), TestInputWord.of(PETER, WORD_WELT)), - new KeyValue<>( - PETER, + KeyValue.pair( + TestInputUser.of(PETER), TestInputWord.of(PETER, WORD_BOÄH)), - new KeyValue<>( - KLAUS, + KeyValue.pair( + TestInputUser.of(KLAUS), TestInputWord.of(KLAUS, WORD_S)), - new KeyValue<>( - PETER, + KeyValue.pair( + TestInputUser.of(PETER), TestInputWord.of(PETER, WORD_BOÄH)), - new KeyValue<>( - KLAUS, + KeyValue.pair( + TestInputUser.of(KLAUS), TestInputWord.of(KLAUS, WORD_S)), }; - static Stream> getInputMessages() + static Stream> getInputMessages() { return Stream.of(TestData.INPUT_MESSAGES); } - static Consumer> expectedMessagesAssertion() - { - return receivedMessages -> assertExpectedMessages(receivedMessages); - } - static void assertExpectedMessages(MultiValueMap receivedMessages) { expectedMessages().forEach( @@ -86,11 +81,6 @@ class TestData .containsExactlyElementsOf(counter)); } - static Consumer> expectedNumberOfMessagesForWordAssertion() - { - return receivedMessages -> assertExpectedNumberOfMessagesForWord(receivedMessages); - } - static void assertExpectedNumberOfMessagesForWord(MultiValueMap receivedMessages) { assertThat(countMessagesForWord(PETER_HALLO, receivedMessages)); @@ -102,12 +92,9 @@ class TestData private static int countMessagesForWord(TestOutputWord word, MultiValueMap messagesForUsers) { - return messagesForUsers.get(word).size(); - } - - static Consumer> expectedLastMessagesForWordAssertion() - { - return receivedMessages -> assertExpectedLastMessagesForWord(receivedMessages); + return messagesForUsers.get(word) == null + ? 0 + : messagesForUsers.get(word).size(); } static void assertExpectedState(ReadOnlyKeyValueStore store)