- static Message peter1 = Message.of(
- "{\"username\":\"peter\",\"word\":\"Hallo\"}",
- "1");
- static Message peter2 = Message.of(
- "{\"username\":\"peter\",\"word\":\"Welt\"}",
- "1");
- static Message peter3 = Message.of(
- "{\"username\":\"peter\",\"word\":\"Boäh\"}",
- "1");
- static Message peter4 = Message.of(
- "{\"username\":\"peter\",\"word\":\"Welt\"}",
- "2");
- static Message peter5 = Message.of(
- "{\"username\":\"peter\",\"word\":\"Boäh\"}",
- "2");
- static Message peter6 = Message.of(
- "{\"username\":\"peter\",\"word\":\"Boäh\"}",
- "3");
-
- static Message klaus1 = Message.of(
- "{\"username\":\"klaus\",\"word\":\"Müsch\"}",
- "1");
- static Message klaus2 = Message.of(
- "{\"username\":\"klaus\",\"word\":\"Müsch\"}",
- "2");
- static Message klaus3 = Message.of(
- "{\"username\":\"klaus\",\"word\":\"s\"}",
- "1");
- static Message klaus4 = Message.of(
- "{\"username\":\"klaus\",\"word\":\"s\"}",
- "2");
- static Message klaus5 = Message.of(
- "{\"username\":\"klaus\",\"word\":\"s\"}",
- "3");
+ 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(
+ PETER_HALLO,
+ TestOutputWordCounter.of(PETER, WORD_HALLO,1)),
+ KeyValue.pair(
+ KLAUS_MÜSCH,
+ TestOutputWordCounter.of(KLAUS, WORD_MÜSCH,1)),
+ KeyValue.pair(
+ PETER_WELT,
+ TestOutputWordCounter.of(PETER, WORD_WELT,1)),
+ KeyValue.pair(
+ KLAUS_MÜSCH,
+ TestOutputWordCounter.of(KLAUS, WORD_MÜSCH,2)),
+ KeyValue.pair(
+ KLAUS_S,
+ TestOutputWordCounter.of(KLAUS, WORD_S,1)),
+ KeyValue.pair(
+ PETER_BOÄH,
+ TestOutputWordCounter.of(PETER, WORD_BOÄH,1)),
+ KeyValue.pair(
+ PETER_WELT,
+ TestOutputWordCounter.of(PETER, WORD_WELT,2)),
+ KeyValue.pair(
+ PETER_BOÄH,
+ TestOutputWordCounter.of(PETER, WORD_BOÄH,2)),
+ KeyValue.pair(
+ KLAUS_S,
+ TestOutputWordCounter.of(KLAUS, WORD_S,2)),
+ KeyValue.pair(
+ PETER_BOÄH,
+ TestOutputWordCounter.of(PETER, WORD_BOÄH,3)),
+ KeyValue.pair(
+ KLAUS_S,
+ TestOutputWordCounter.of(KLAUS, WORD_S,3)),
+ };
+
+ static MultiValueMap<TestOutputWord, TestOutputWordCounter> expectedMessages()
+ {
+ MultiValueMap<TestOutputWord, TestOutputWordCounter> expectedMessages = new LinkedMultiValueMap<>();
+ Stream
+ .of(EXPECTED_MESSAGES)
+ .forEach(keyValue -> expectedMessages.add(keyValue.key, keyValue.value));
+ return expectedMessages;
+ }