From ed364e3fb4436eeb181b6eac9ff4650d3d91f21c Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 8 Jun 2024 09:09:37 +0200 Subject: [PATCH] counter: 1.2.15 - DRY for test-data --- .../kafka/wordcount/counter/TestData.java | 78 +++++++++++-------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java b/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java index 8d87793..714e585 100644 --- a/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java +++ b/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java @@ -18,41 +18,53 @@ class TestData static final String PETER = "peter"; static final String KLAUS = "klaus"; + static final String WORD_HALLO = "Hallo"; + static final String WORD_MÜSCH = "Müsch"; + static final String WORD_WELT = "Welt"; + static final String WORD_S = "s"; + static final String WORD_BOÄH = "Boäh"; + + static final TestOutputWord PETER_HALLO = TestOutputWord.of(PETER, WORD_HALLO); + static final TestOutputWord PETER_WELT = TestOutputWord.of(PETER, WORD_WELT); + static final TestOutputWord PETER_BOÄH = TestOutputWord.of(PETER, WORD_BOÄH); + static final TestOutputWord KLAUS_MÜSCH = TestOutputWord.of(KLAUS, WORD_MÜSCH); + static final TestOutputWord KLAUS_S = TestOutputWord.of(KLAUS, WORD_S); + private static final KeyValue[] INPUT_MESSAGES = new KeyValue[] { new KeyValue<>( PETER, - TestInputWord.of(PETER, "Hallo")), + TestInputWord.of(PETER, WORD_HALLO)), new KeyValue<>( KLAUS, - TestInputWord.of(KLAUS, "Müsch")), + TestInputWord.of(KLAUS, WORD_MÜSCH)), new KeyValue<>( PETER, - TestInputWord.of(PETER, "Welt")), + TestInputWord.of(PETER, WORD_WELT)), new KeyValue<>( KLAUS, - TestInputWord.of(KLAUS, "Müsch")), + TestInputWord.of(KLAUS, WORD_MÜSCH)), new KeyValue<>( KLAUS, - TestInputWord.of(KLAUS, "s")), + TestInputWord.of(KLAUS, WORD_S)), new KeyValue<>( PETER, - TestInputWord.of(PETER, "Boäh")), + TestInputWord.of(PETER, WORD_BOÄH)), new KeyValue<>( PETER, - TestInputWord.of(PETER, "Welt")), + TestInputWord.of(PETER, WORD_WELT)), new KeyValue<>( PETER, - TestInputWord.of(PETER, "Boäh")), + TestInputWord.of(PETER, WORD_BOÄH)), new KeyValue<>( KLAUS, - TestInputWord.of(KLAUS, "s")), + TestInputWord.of(KLAUS, WORD_S)), new KeyValue<>( PETER, - TestInputWord.of(PETER, "Boäh")), + TestInputWord.of(PETER, WORD_BOÄH)), new KeyValue<>( KLAUS, - TestInputWord.of(KLAUS, "s")), + TestInputWord.of(KLAUS, WORD_S)), }; static Stream> getInputMessages() @@ -76,38 +88,38 @@ class TestData private static final KeyValue[] EXPECTED_MESSAGES = new KeyValue[] { KeyValue.pair( - TestOutputWord.of(PETER, "Hallo"), - TestOutputWordCounter.of(PETER, "Hallo",1)), + PETER_HALLO, + TestOutputWordCounter.of(PETER, WORD_HALLO,1)), KeyValue.pair( - TestOutputWord.of(KLAUS, "Müsch"), - TestOutputWordCounter.of(KLAUS, "Müsch",1)), + KLAUS_MÜSCH, + TestOutputWordCounter.of(KLAUS, WORD_MÜSCH,1)), KeyValue.pair( - TestOutputWord.of(PETER, "Welt"), - TestOutputWordCounter.of(PETER, "Welt",1)), + PETER_WELT, + TestOutputWordCounter.of(PETER, WORD_WELT,1)), KeyValue.pair( - TestOutputWord.of(KLAUS, "Müsch"), - TestOutputWordCounter.of(KLAUS, "Müsch",2)), + KLAUS_MÜSCH, + TestOutputWordCounter.of(KLAUS, WORD_MÜSCH,2)), KeyValue.pair( - TestOutputWord.of(KLAUS, "s"), - TestOutputWordCounter.of(KLAUS, "s",1)), + KLAUS_S, + TestOutputWordCounter.of(KLAUS, WORD_S,1)), KeyValue.pair( - TestOutputWord.of(PETER, "Boäh"), - TestOutputWordCounter.of(PETER, "Boäh",1)), + PETER_BOÄH, + TestOutputWordCounter.of(PETER, WORD_BOÄH,1)), KeyValue.pair( - TestOutputWord.of(PETER, "Welt"), - TestOutputWordCounter.of(PETER, "Welt",2)), + PETER_WELT, + TestOutputWordCounter.of(PETER, WORD_WELT,2)), KeyValue.pair( - TestOutputWord.of(PETER, "Boäh"), - TestOutputWordCounter.of(PETER, "Boäh",2)), + PETER_BOÄH, + TestOutputWordCounter.of(PETER, WORD_BOÄH,2)), KeyValue.pair( - TestOutputWord.of(KLAUS, "s"), - TestOutputWordCounter.of(KLAUS, "s",2)), + KLAUS_S, + TestOutputWordCounter.of(KLAUS, WORD_S,2)), KeyValue.pair( - TestOutputWord.of(PETER, "Boäh"), - TestOutputWordCounter.of(PETER, "Boäh",3)), + PETER_BOÄH, + TestOutputWordCounter.of(PETER, WORD_BOÄH,3)), KeyValue.pair( - TestOutputWord.of(KLAUS, "s"), - TestOutputWordCounter.of(KLAUS, "s",3)), + KLAUS_S, + TestOutputWordCounter.of(KLAUS, WORD_S,3)), }; static MultiValueMap expectedMessages() -- 2.20.1