< prev index next >

test/java/util/stream/bootlib/java.base/java/util/stream/LambdaTestHelpers.java

Print this page

        

@@ -45,10 +45,11 @@
 import java.util.function.ToIntFunction;
 import java.util.function.ToLongFunction;
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.assertFalse;
 
 /**
  * LambdaTestHelpers -- assertion methods and useful objects for lambda test cases
  */
 public class LambdaTestHelpers {

@@ -398,10 +399,20 @@
 
     public static<T> void assertContentsUnordered(Iterator<T> actual, Iterator<T> expected) {
         assertEquals(toBoxedMultiset(actual), toBoxedMultiset(expected));
     }
 
+    public static<T> void assertContains(Optional<T> actual, Iterator<T> it) {
+        actual.ifPresentOrElse(r -> {
+            boolean contained = false;
+            while (!contained && it.hasNext()) {
+                contained = Objects.equals(r, it.next());
+            }
+            assertTrue(contained, "Not found: "+r);
+        }, () -> assertFalse(it.hasNext()));
+    }
+
     public static void launderAssertion(Runnable r, Supplier<String> additionalInfo) {
         try {
             r.run();
         }
         catch (AssertionError ae) {
< prev index next >