- Message.of(
- Word.of("peter","Hallo"),
- WordCount.of("peter","Hallo",1)),
- Message.of(
- Word.of("klaus","Müsch"),
- WordCount.of("klaus","Müsch",1)),
- Message.of(
- Word.of("peter","Welt"),
- WordCount.of("peter","Welt",1)),
- Message.of(
- Word.of("klaus","Müsch"),
- WordCount.of("klaus","Müsch",2)),
- Message.of(
- Word.of("klaus","s"),
- WordCount.of("klaus","s",1)),
- Message.of(
- Word.of("peter","Boäh"),
- WordCount.of("peter","Boäh",1)),
- Message.of(
- Word.of("peter","Welt"),
- WordCount.of("peter","Welt",2)),
- Message.of(
- Word.of("peter","Boäh"),
- WordCount.of("peter","Boäh",2)),
- Message.of(
- Word.of("klaus","s"),
- WordCount.of("klaus","s",2)),
- Message.of(
- Word.of("peter","Boäh"),
- WordCount.of("peter","Boäh",3)),
- Message.of(
- Word.of("klaus","s"),
- WordCount.of("klaus","s",3)),
+ return messagesForUsers.get(word).size();
+ }
+
+ static void assertExpectedState(ReadOnlyKeyValueStore<Word, Long> store)
+ {
+ assertWordCountEqualsWordCountFromLastMessage(PETER_HALLO, store.get(wordOf(PETER_HALLO)));
+ assertWordCountEqualsWordCountFromLastMessage(PETER_WELT, store.get(wordOf(PETER_WELT)));
+ assertWordCountEqualsWordCountFromLastMessage(PETER_BOÄH, store.get(wordOf(PETER_BOÄH)));
+ assertWordCountEqualsWordCountFromLastMessage(KLAUS_MÜSCH, store.get(wordOf(KLAUS_MÜSCH)));
+ assertWordCountEqualsWordCountFromLastMessage(KLAUS_S, store.get(wordOf(KLAUS_S)));
+ }
+
+ private static Word wordOf(TestOutputWord testOutputWord)
+ {
+ Word word = new Word();
+
+ word.setUser(testOutputWord.getUser());
+ word.setWord(testOutputWord.getWord());
+
+ return word;
+ }
+
+ static void assertExpectedLastMessagesForWord(MultiValueMap<TestOutputWord, TestOutputWordCounter> receivedMessages)
+ {
+ assertWordCountEqualsWordCountFromLastMessage(PETER_HALLO, getLastMessageFor(PETER_HALLO, receivedMessages));
+ assertWordCountEqualsWordCountFromLastMessage(PETER_WELT, getLastMessageFor(PETER_WELT, receivedMessages));
+ assertWordCountEqualsWordCountFromLastMessage(PETER_BOÄH, getLastMessageFor(PETER_BOÄH, receivedMessages));
+ assertWordCountEqualsWordCountFromLastMessage(KLAUS_MÜSCH, getLastMessageFor(KLAUS_MÜSCH, receivedMessages));
+ assertWordCountEqualsWordCountFromLastMessage(KLAUS_S, getLastMessageFor(KLAUS_S, receivedMessages));
+ }
+
+ private static void assertWordCountEqualsWordCountFromLastMessage(
+ TestOutputWord word,
+ Long counter)
+ {
+ TestOutputWordCounter testOutputWordCounter = TestOutputWordCounter.of(
+ word.getUser(),
+ word.getWord(),
+ counter);
+ assertWordCountEqualsWordCountFromLastMessage(word, testOutputWordCounter);
+ }
+
+ private static void assertWordCountEqualsWordCountFromLastMessage(
+ TestOutputWord word,
+ TestOutputWordCounter counter)
+ {
+ assertThat(counter).isEqualTo(getLastMessageFor(word));
+ }
+
+ private static TestOutputWordCounter getLastMessageFor(TestOutputWord word)
+ {
+ return getLastMessageFor(word, expectedMessages());
+ }
+
+ private static TestOutputWordCounter getLastMessageFor(
+ TestOutputWord user,
+ MultiValueMap<TestOutputWord, TestOutputWordCounter> messagesForWord)
+ {
+ return messagesForWord
+ .get(user)
+ .stream()
+ .reduce(null, (left, right) -> right);
+ }
+
+ 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)),