KhaninArtur commented on a change in pull request #14322:
URL: https://github.com/apache/beam/pull/14322#discussion_r600517005



##########
File path: 
sdks/java/core/src/test/java/org/apache/beam/sdk/testing/PAssertTest.java
##########
@@ -596,4 +598,59 @@ public void countAssertsMultipleCallsIndependent() {
 
     assertThat(PAssert.countAsserts(pipeline), equalTo(3));
   }
+
+  @Test
+  public void testPAssertThatFlattened() {
+    PCollection<Integer> firstCollection = pipeline.apply("FirstCreate", 
Create.of(1, 2, 3));
+    PCollection<Integer> secondCollection = pipeline.apply("SecondCreate", 
Create.of(4, 5, 6));
+
+    PCollectionList<Integer> collectionList =
+        PCollectionList.of(firstCollection).and(secondCollection);
+
+    PAssert.thatFlattened(collectionList).containsInAnyOrder(1, 2, 3, 4, 5, 6);
+    PAssert.thatFlattened("Reason", collectionList).containsInAnyOrder(1, 2, 
3, 4, 5, 6);
+  }
+
+  @Test
+  public void testPAssertThatListSatisfiesOneMatcher() {
+    PCollection<Integer> firstCollection = pipeline.apply("FirstCreate", 
Create.of(1, 2, 3));
+    PCollection<Integer> secondCollection = pipeline.apply("SecondCreate", 
Create.of(4, 5, 6));
+
+    PCollectionList<Integer> collectionList =
+        PCollectionList.of(firstCollection).and(secondCollection);
+
+    PAssert.thatList(collectionList)
+        .satisfies(
+            input -> {
+              for (Integer element : input) {
+                assertTrue(element > 0);
+              }
+              return null;
+            });
+  }
+
+  @Test
+  public void testPAssertThatListSatisfiesMultipleMatchers() {
+    PCollection<Integer> firstCollection = pipeline.apply("FirstCreate", 
Create.of(1, 2, 3));
+    PCollection<Integer> secondCollection = pipeline.apply("SecondCreate", 
Create.of(4, 5, 6));
+
+    PCollectionList<Integer> collectionList =
+        PCollectionList.of(firstCollection).and(secondCollection);
+
+    PAssert.thatList(collectionList)
+        .satisfies(
+            ImmutableList.of(
+                input -> {
+                  for (Integer element : input) {
+                    assertTrue(element < 4);
+                  }
+                  return null;
+                },
+                input -> {
+                  for (Integer element : input) {
+                    assertTrue(element < 7);
+                  }
+                  return null;
+                }));
+  }

Review comment:
       Should we also check that PAssert fails correctly? I.e. add negative 
test cases?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to