From: Kai Moritz Date: Sun, 2 Jun 2024 09:00:36 +0000 (+0200) Subject: top10: 1.2.1 - Refined assertion of expected state X-Git-Tag: top10-1.2.1~13 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=843682fed975e5ee2ee6871e95d1cb6c420b0d9e;p=demos%2Fkafka%2Fwordcount top10: 1.2.1 - Refined assertion of expected state --- 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 d8c603a..eb30298 100644 --- a/src/test/java/de/juplo/kafka/wordcount/top10/TestData.java +++ b/src/test/java/de/juplo/kafka/wordcount/top10/TestData.java @@ -69,8 +69,26 @@ class TestData static void assertExpectedState(ReadOnlyKeyValueStore store) { - assertThat(store.get(EXPECTED_MESSAGES[9].key)).isEqualTo(EXPECTED_MESSAGES[9].value); - assertThat(store.get(EXPECTED_MESSAGES[10].key)).isEqualTo(EXPECTED_MESSAGES[10].value); + assertRankingEqualsRankingFromLastMessage(PETER, store.get(PETER)); + assertRankingEqualsRankingFromLastMessage(KLAUS, store.get(KLAUS)); + } + + static void assertRankingEqualsRankingFromLastMessage(User user, Ranking ranking) + { + assertThat(ranking).isEqualTo(getLastMessageFor(user)); + } + + static Ranking getLastMessageFor(User user) + { + return getLastMessageFor(user, expectedMessages()); + } + + static Ranking getLastMessageFor(User user, MultiValueMap messagesForUsers) + { + return messagesForUsers + .get(user) + .stream() + .reduce(null, (left, right) -> right); } static KeyValue[] EXPECTED_MESSAGES = new KeyValue[]