});
}
+ @DisplayName("Await the expected number of messages")
+ @Test
+ public void testAwaitExpectedNumberOfMessagesForUsers()
+ {
+ await("Expected number of messages")
+ .atMost(Duration.ofSeconds(5))
+ .untilAsserted(() -> consumer.enforceAssertion(TestData.expectedNumberOfMessagesForWordAssertion()));
+ }
+
@DisplayName("Await the expected output messages")
@Test
void testSendMessage()
.containsExactlyElementsOf(counter));
}
+ static Consumer<MultiValueMap<TestOutputWord, TestOutputWordCounter>> expectedNumberOfMessagesForWordAssertion()
+ {
+ return receivedMessages -> assertExpectedNumberOfMessagesForWord(receivedMessages);
+ }
+
+ static void assertExpectedNumberOfMessagesForWord(MultiValueMap<TestOutputWord, TestOutputWordCounter> receivedMessages)
+ {
+ assertThat(countMessagesForWord(PETER_HALLO, receivedMessages));
+ assertThat(countMessagesForWord(PETER_WELT, receivedMessages));
+ assertThat(countMessagesForWord(PETER_BOÄH, receivedMessages));
+ assertThat(countMessagesForWord(KLAUS_MÜSCH, receivedMessages));
+ assertThat(countMessagesForWord(KLAUS_S, receivedMessages));
+ }
+
+ private static int countMessagesForWord(TestOutputWord word, MultiValueMap<TestOutputWord, TestOutputWordCounter> messagesForUsers)
+ {
+ return messagesForUsers.get(word).size();
+ }
+
private static final KeyValue<TestOutputWord, TestOutputWordCounter>[] EXPECTED_MESSAGES = new KeyValue[]
{
KeyValue.pair(