Simplified code: DRY for assertions
authorKai Moritz <kai@juplo.de>
Fri, 5 Jul 2024 21:30:56 +0000 (23:30 +0200)
committerKai Moritz <kai@juplo.de>
Fri, 5 Jul 2024 21:30:56 +0000 (23:30 +0200)
src/test/java/de/juplo/kafka/wordcount/counter/StreamStreamJoinTopologyTest.java

index de45d53..f73d028 100644 (file)
@@ -62,37 +62,37 @@ public class StreamStreamJoinTopologyTest
 
 
     inLeft.pipeInput(recordOf("A", 3));
-    assertThat(outcome()).containsExactlyInAnyOrder();
+    assertThatOutcomeIs();
 
     inRight.pipeInput(recordOf("a", 4));
-    assertThat(outcome()).containsExactlyInAnyOrder("A-a");
+    assertThatOutcomeIs("A-a");
 
     inLeft.pipeInput(recordOf("B", 5));
-    assertThat(outcome()).containsExactlyInAnyOrder("B-a");
+    assertThatOutcomeIs("B-a");
 
     inRight.pipeInput(recordOf("b", 6));
-    assertThat(outcome()).containsExactlyInAnyOrder("A-b", "B-b");
+    assertThatOutcomeIs("A-b", "B-b");
 
     inLeft.pipeInput(recordOf("C", 9));
-    assertThat(outcome()).containsExactlyInAnyOrder("C-a", "C-b");
+    assertThatOutcomeIs("C-a", "C-b");
 
     inRight.pipeInput(recordOf("c", 10));
-    assertThat(outcome()).containsExactlyInAnyOrder("A-c", "B-c", "C-c");
+    assertThatOutcomeIs("A-c", "B-c", "C-c");
 
     inRight.pipeInput(recordOf("d", 14));
-    assertThat(outcome()).containsExactlyInAnyOrder("B-d", "C-d"); // !
+    assertThatOutcomeIs("B-d", "C-d"); // !
 
     inLeft.pipeInput(recordOf("D", 15));
-    assertThat(outcome()).containsExactlyInAnyOrder("D-b", "D-c", "D-d");
+    assertThatOutcomeIs("D-b", "D-c", "D-d");
 
     inLeft.pipeInput(recordOf("E", 40));
-    assertThat(outcome()).containsExactlyInAnyOrder();
+    assertThatOutcomeIs();
 
     inLeft.pipeInput(recordOf("F", 60));
-    assertThat(outcome()).containsExactlyInAnyOrder();
+    assertThatOutcomeIs();
 
     inLeft.pipeInput(recordOf("G", 100));
-    assertThat(outcome()).containsExactlyInAnyOrder();
+    assertThatOutcomeIs();
   }
 
 
@@ -102,6 +102,11 @@ public class StreamStreamJoinTopologyTest
     return new TestRecord<>("foo", value, T.plusSeconds(second));
   }
 
+  void assertThatOutcomeIs(String... expected)
+  {
+    assertThat(outcome()).containsExactlyInAnyOrder(expected);
+  }
+
   Stream<String> outcome()
   {
     return outJoined