< prev index next >

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

Print this page




  30 import java.util.function.DoubleBinaryOperator;
  31 import java.util.function.DoubleConsumer;
  32 import java.util.function.DoublePredicate;
  33 import java.util.function.Function;
  34 import java.util.function.IntBinaryOperator;
  35 import java.util.function.IntConsumer;
  36 import java.util.function.IntFunction;
  37 import java.util.function.IntPredicate;
  38 import java.util.function.IntUnaryOperator;
  39 import java.util.function.LongBinaryOperator;
  40 import java.util.function.LongConsumer;
  41 import java.util.function.LongPredicate;
  42 import java.util.function.Predicate;
  43 import java.util.function.Supplier;
  44 import java.util.function.ToDoubleFunction;
  45 import java.util.function.ToIntFunction;
  46 import java.util.function.ToLongFunction;
  47 
  48 import static org.testng.Assert.assertEquals;
  49 import static org.testng.Assert.assertTrue;

  50 
  51 /**
  52  * LambdaTestHelpers -- assertion methods and useful objects for lambda test cases
  53  */
  54 public class LambdaTestHelpers {
  55     public static final String LONG_STRING = "When in the Course of human events it becomes necessary for one people to dissolve the political bands which have connected them with another and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.";
  56 
  57     @SuppressWarnings("rawtypes")
  58     public static final Consumer bEmpty = x -> {  };
  59     @SuppressWarnings("rawtypes")
  60     public static final IntConsumer bIntEmpty = x -> {  };
  61     @SuppressWarnings("rawtypes")
  62     public static final BiConsumer bBiEmpty = (x,y) -> { };
  63     @SuppressWarnings("rawtypes")
  64     public static final Consumer bHashCode = x -> { Objects.hashCode(x); };
  65     @SuppressWarnings("rawtypes")
  66     public static final BiConsumer bBiHashCode = (x,y) -> { Objects.hash(x, y); };
  67     public static final Function<Integer, Integer> mZero = x -> 0;
  68     public static final Function<Integer, Integer> mId = x -> x;
  69     public static final Function<Integer, Integer> mDoubler = x -> x * 2;


 381                     result.put(o, 1);
 382             }));
 383 
 384         return (Map<T, Integer>) result;
 385     }
 386 
 387     @SuppressWarnings("unchecked")
 388     public static void assertContentsEqual(Object a, Object b) {
 389         if (a instanceof Iterable && b instanceof Iterable)
 390             assertContents((Iterable) a, (Iterable) b);
 391         else
 392             assertEquals(a, b);
 393     }
 394 
 395     public static<T> void assertContentsUnordered(Iterable<T> actual, Iterable<T> expected) {
 396         assertContentsUnordered(actual.iterator(), expected.iterator());
 397     }
 398 
 399     public static<T> void assertContentsUnordered(Iterator<T> actual, Iterator<T> expected) {
 400         assertEquals(toBoxedMultiset(actual), toBoxedMultiset(expected));










 401     }
 402 
 403     public static void launderAssertion(Runnable r, Supplier<String> additionalInfo) {
 404         try {
 405             r.run();
 406         }
 407         catch (AssertionError ae) {
 408             AssertionError cloned = new AssertionError(ae.getMessage() + String.format("%n%s", additionalInfo.get()));
 409             cloned.setStackTrace(ae.getStackTrace());
 410             if (ae.getCause() != null)
 411                 cloned.initCause(ae.getCause());
 412             throw cloned;
 413         }
 414     }
 415 
 416     public static <T, S extends BaseStream<T, S>>
 417     List<Function<S, S>> permuteStreamFunctions(List<Function<S, S>> opFunctions) {
 418         List<List<Function<S, S>>> opFunctionPermutations = perm(opFunctions);
 419 
 420         List<Function<S, S>> appliedFunctions = new ArrayList<>();




  30 import java.util.function.DoubleBinaryOperator;
  31 import java.util.function.DoubleConsumer;
  32 import java.util.function.DoublePredicate;
  33 import java.util.function.Function;
  34 import java.util.function.IntBinaryOperator;
  35 import java.util.function.IntConsumer;
  36 import java.util.function.IntFunction;
  37 import java.util.function.IntPredicate;
  38 import java.util.function.IntUnaryOperator;
  39 import java.util.function.LongBinaryOperator;
  40 import java.util.function.LongConsumer;
  41 import java.util.function.LongPredicate;
  42 import java.util.function.Predicate;
  43 import java.util.function.Supplier;
  44 import java.util.function.ToDoubleFunction;
  45 import java.util.function.ToIntFunction;
  46 import java.util.function.ToLongFunction;
  47 
  48 import static org.testng.Assert.assertEquals;
  49 import static org.testng.Assert.assertTrue;
  50 import static org.testng.Assert.assertFalse;
  51 
  52 /**
  53  * LambdaTestHelpers -- assertion methods and useful objects for lambda test cases
  54  */
  55 public class LambdaTestHelpers {
  56     public static final String LONG_STRING = "When in the Course of human events it becomes necessary for one people to dissolve the political bands which have connected them with another and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.";
  57 
  58     @SuppressWarnings("rawtypes")
  59     public static final Consumer bEmpty = x -> {  };
  60     @SuppressWarnings("rawtypes")
  61     public static final IntConsumer bIntEmpty = x -> {  };
  62     @SuppressWarnings("rawtypes")
  63     public static final BiConsumer bBiEmpty = (x,y) -> { };
  64     @SuppressWarnings("rawtypes")
  65     public static final Consumer bHashCode = x -> { Objects.hashCode(x); };
  66     @SuppressWarnings("rawtypes")
  67     public static final BiConsumer bBiHashCode = (x,y) -> { Objects.hash(x, y); };
  68     public static final Function<Integer, Integer> mZero = x -> 0;
  69     public static final Function<Integer, Integer> mId = x -> x;
  70     public static final Function<Integer, Integer> mDoubler = x -> x * 2;


 382                     result.put(o, 1);
 383             }));
 384 
 385         return (Map<T, Integer>) result;
 386     }
 387 
 388     @SuppressWarnings("unchecked")
 389     public static void assertContentsEqual(Object a, Object b) {
 390         if (a instanceof Iterable && b instanceof Iterable)
 391             assertContents((Iterable) a, (Iterable) b);
 392         else
 393             assertEquals(a, b);
 394     }
 395 
 396     public static<T> void assertContentsUnordered(Iterable<T> actual, Iterable<T> expected) {
 397         assertContentsUnordered(actual.iterator(), expected.iterator());
 398     }
 399 
 400     public static<T> void assertContentsUnordered(Iterator<T> actual, Iterator<T> expected) {
 401         assertEquals(toBoxedMultiset(actual), toBoxedMultiset(expected));
 402     }
 403 
 404     public static<T> void assertContains(Optional<T> actual, Iterator<T> it) {
 405         actual.ifPresentOrElse(r -> {
 406             boolean contained = false;
 407             while (!contained && it.hasNext()) {
 408                 contained = Objects.equals(r, it.next());
 409             }
 410             assertTrue(contained, "Not found: "+r);
 411         }, () -> assertFalse(it.hasNext()));
 412     }
 413 
 414     public static void launderAssertion(Runnable r, Supplier<String> additionalInfo) {
 415         try {
 416             r.run();
 417         }
 418         catch (AssertionError ae) {
 419             AssertionError cloned = new AssertionError(ae.getMessage() + String.format("%n%s", additionalInfo.get()));
 420             cloned.setStackTrace(ae.getStackTrace());
 421             if (ae.getCause() != null)
 422                 cloned.initCause(ae.getCause());
 423             throw cloned;
 424         }
 425     }
 426 
 427     public static <T, S extends BaseStream<T, S>>
 428     List<Function<S, S>> permuteStreamFunctions(List<Function<S, S>> opFunctions) {
 429         List<List<Function<S, S>>> opFunctionPermutations = perm(opFunctions);
 430 
 431         List<Function<S, S>> appliedFunctions = new ArrayList<>();


< prev index next >