From e32a74e6a989ba8fc1061cffd1bed814edb4f72f Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 2 Jun 2024 10:58:24 +0200 Subject: [PATCH] top10: 1.2.1 - DRY for `User` in `TestData` --- .../juplo/kafka/wordcount/top10/TestData.java | 69 ++++++++++--------- 1 file changed, 36 insertions(+), 33 deletions(-) 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 f6d7ccd..d8c603a 100644 --- a/src/test/java/de/juplo/kafka/wordcount/top10/TestData.java +++ b/src/test/java/de/juplo/kafka/wordcount/top10/TestData.java @@ -19,41 +19,44 @@ import static org.assertj.core.api.Assertions.assertThat; class TestData { + static final User PETER = User.of("peter"); + static final User KLAUS = User.of("klaus"); + static final KeyValue[] INPUT_MESSAGES = new KeyValue[] { new KeyValue<>( - TestWord.of("peter","Hallo"), - TestCounter.of("peter","Hallo",1)), + TestWord.of(PETER.getUser(),"Hallo"), + TestCounter.of(PETER.getUser(),"Hallo",1)), new KeyValue<>( - TestWord.of("klaus","Müsch"), - TestCounter.of("klaus","Müsch",1)), + TestWord.of(KLAUS.getUser(),"Müsch"), + TestCounter.of(KLAUS.getUser(),"Müsch",1)), new KeyValue<>( - TestWord.of("peter","Welt"), - TestCounter.of("peter","Welt",1)), + TestWord.of(PETER.getUser(),"Welt"), + TestCounter.of(PETER.getUser(),"Welt",1)), new KeyValue<>( - TestWord.of("klaus","Müsch"), - TestCounter.of("klaus","Müsch",2)), + TestWord.of(KLAUS.getUser(),"Müsch"), + TestCounter.of(KLAUS.getUser(),"Müsch",2)), new KeyValue<>( - TestWord.of("klaus","s"), - TestCounter.of("klaus","s",1)), + TestWord.of(KLAUS.getUser(),"s"), + TestCounter.of(KLAUS.getUser(),"s",1)), new KeyValue<>( - TestWord.of("peter","Boäh"), - TestCounter.of("peter","Boäh",1)), + TestWord.of(PETER.getUser(),"Boäh"), + TestCounter.of(PETER.getUser(),"Boäh",1)), new KeyValue<>( - TestWord.of("peter","Welt"), - TestCounter.of("peter","Welt",2)), + TestWord.of(PETER.getUser(),"Welt"), + TestCounter.of(PETER.getUser(),"Welt",2)), new KeyValue<>( - TestWord.of("peter","Boäh"), - TestCounter.of("peter","Boäh",2)), + TestWord.of(PETER.getUser(),"Boäh"), + TestCounter.of(PETER.getUser(),"Boäh",2)), new KeyValue<>( - TestWord.of("klaus","s"), - TestCounter.of("klaus","s",2)), + TestWord.of(KLAUS.getUser(),"s"), + TestCounter.of(KLAUS.getUser(),"s",2)), new KeyValue<>( - TestWord.of("peter","Boäh"), - TestCounter.of("peter","Boäh",3)), + TestWord.of(PETER.getUser(),"Boäh"), + TestCounter.of(PETER.getUser(),"Boäh",3)), new KeyValue<>( - TestWord.of("klaus","s"), - TestCounter.of("klaus","s",3)), + TestWord.of(KLAUS.getUser(),"s"), + TestCounter.of(KLAUS.getUser(),"s",3)), }; static void assertExpectedMessages(MultiValueMap receivedMessages) @@ -73,58 +76,58 @@ class TestData static KeyValue[] EXPECTED_MESSAGES = new KeyValue[] { KeyValue.pair( // 0 - User.of("peter"), + PETER, Ranking.of( Entry.of("Hallo", 1l))), KeyValue.pair( // 1 - User.of("klaus"), + KLAUS, Ranking.of( Entry.of("Müsch", 1l))), KeyValue.pair( // 2 - User.of("peter"), + PETER, Ranking.of( Entry.of("Hallo", 1l), Entry.of("Welt", 1l))), KeyValue.pair( // 3 - User.of("klaus"), + KLAUS, Ranking.of( Entry.of("Müsch", 2l))), KeyValue.pair( // 4 - User.of("klaus"), + KLAUS, Ranking.of( Entry.of("Müsch", 2l), Entry.of("s", 1l))), KeyValue.pair( // 5 - User.of("peter"), + PETER, Ranking.of( Entry.of("Hallo", 1l), Entry.of("Welt", 1l), Entry.of("Boäh", 1l))), KeyValue.pair( // 6 - User.of("peter"), + PETER, Ranking.of( Entry.of("Welt", 2l), Entry.of("Hallo", 1l), Entry.of("Boäh", 1l))), KeyValue.pair( // 7 - User.of("peter"), + PETER, Ranking.of( Entry.of("Welt", 2l), Entry.of("Boäh", 2l), Entry.of("Hallo", 1l))), KeyValue.pair( // 8 - User.of("klaus"), + KLAUS, Ranking.of( Entry.of("Müsch", 2l), Entry.of("s", 2l))), KeyValue.pair( // 9 - User.of("peter"), + PETER, Ranking.of( Entry.of("Boäh", 3l), Entry.of("Welt", 2l), Entry.of("Hallo", 1l))), KeyValue.pair( // 10 - User.of("klaus"), + KLAUS, Ranking.of( Entry.of("s", 3l), Entry.of("Müsch", 2l))), -- 2.20.1