Class PredicateAssertions


  • public final class PredicateAssertions
    extends Object
    A collection of utility methods that support asserting conditions on objects using predicates. These methods are like Assertions.assertTrue(boolean) and Assertions.assertFalse(boolean), but use an actual object that's not always true or false. As a result, the assertions in this class provide more information about why assertions fail.
    Author:
    Rob Spoor
    Since:
    2.0
    • Method Detail

      • assertMatches

        public static <T> void assertMatches​(Predicate<? super T> matcher,
                                             T actual)
        Asserts that the supplied value matches the supplied predicate.
        Type Parameters:
        T - The value type.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
      • assertMatches

        public static <T> void assertMatches​(Predicate<? super T> matcher,
                                             T actual,
                                             String message)
        Asserts that the supplied value matches the supplied predicate.
        Type Parameters:
        T - The value type.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
        message - The failure message to fail with.
      • assertMatches

        public static <T> void assertMatches​(Predicate<? super T> matcher,
                                             T actual,
                                             Supplier<String> messageSupplier)
        Asserts that the supplied value matches the supplied predicate.
        Type Parameters:
        T - The value type.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
        messageSupplier - The supplier for the failure message to fail with.
      • assertIntMatches

        public static void assertIntMatches​(IntPredicate matcher,
                                            int actual)
        Asserts that the supplied value matches the supplied predicate.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
      • assertIntMatches

        public static void assertIntMatches​(IntPredicate matcher,
                                            int actual,
                                            String message)
        Asserts that the supplied value matches the supplied predicate.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
        message - The failure message to fail with.
      • assertIntMatches

        public static void assertIntMatches​(IntPredicate matcher,
                                            int actual,
                                            Supplier<String> messageSupplier)
        Asserts that the supplied value matches the supplied predicate.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
        messageSupplier - The supplier for the failure message to fail with.
      • assertLongMatches

        public static void assertLongMatches​(LongPredicate matcher,
                                             long actual)
        Asserts that the supplied value matches the supplied predicate.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
      • assertLongMatches

        public static void assertLongMatches​(LongPredicate matcher,
                                             long actual,
                                             String message)
        Asserts that the supplied value matches the supplied predicate.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
        message - The failure message to fail with.
      • assertLongMatches

        public static void assertLongMatches​(LongPredicate matcher,
                                             long actual,
                                             Supplier<String> messageSupplier)
        Asserts that the supplied value matches the supplied predicate.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
        messageSupplier - The supplier for the failure message to fail with.
      • assertDoubleMatches

        public static void assertDoubleMatches​(DoublePredicate matcher,
                                               double actual)
        Asserts that the supplied value matches the supplied predicate.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
      • assertDoubleMatches

        public static void assertDoubleMatches​(DoublePredicate matcher,
                                               double actual,
                                               String message)
        Asserts that the supplied value matches the supplied predicate.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
        message - The failure message to fail with.
      • assertDoubleMatches

        public static void assertDoubleMatches​(DoublePredicate matcher,
                                               double actual,
                                               Supplier<String> messageSupplier)
        Asserts that the supplied value matches the supplied predicate.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
        messageSupplier - The supplier for the failure message to fail with.
      • assertDoesNotMatch

        public static <T> void assertDoesNotMatch​(Predicate<? super T> matcher,
                                                  T actual)
        Asserts that the supplied value does not match the supplied predicate.
        Type Parameters:
        T - The value type.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
      • assertDoesNotMatch

        public static <T> void assertDoesNotMatch​(Predicate<? super T> matcher,
                                                  T actual,
                                                  String message)
        Asserts that the supplied value does not match the supplied predicate.
        Type Parameters:
        T - The value type.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
        message - The failure message to fail with.
      • assertDoesNotMatch

        public static <T> void assertDoesNotMatch​(Predicate<? super T> matcher,
                                                  T actual,
                                                  Supplier<String> messageSupplier)
        Asserts that the supplied value does not match the supplied predicate.
        Type Parameters:
        T - The value type.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
        messageSupplier - The supplier for the failure message to fail with.
      • assertIntDoesNotMatch

        public static void assertIntDoesNotMatch​(IntPredicate matcher,
                                                 int actual)
        Asserts that the supplied value does not match the supplied predicate.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
      • assertIntDoesNotMatch

        public static void assertIntDoesNotMatch​(IntPredicate matcher,
                                                 int actual,
                                                 String message)
        Asserts that the supplied value does not match the supplied predicate.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
        message - The failure message to fail with.
      • assertIntDoesNotMatch

        public static void assertIntDoesNotMatch​(IntPredicate matcher,
                                                 int actual,
                                                 Supplier<String> messageSupplier)
        Asserts that the supplied value does not match the supplied predicate.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
        messageSupplier - The supplier for the failure message to fail with.
      • assertLongDoesNotMatch

        public static void assertLongDoesNotMatch​(LongPredicate matcher,
                                                  long actual)
        Asserts that the supplied value does not match the supplied predicate.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
      • assertLongDoesNotMatch

        public static void assertLongDoesNotMatch​(LongPredicate matcher,
                                                  long actual,
                                                  String message)
        Asserts that the supplied value does not match the supplied predicate.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
        message - The failure message to fail with.
      • assertLongDoesNotMatch

        public static void assertLongDoesNotMatch​(LongPredicate matcher,
                                                  long actual,
                                                  Supplier<String> messageSupplier)
        Asserts that the supplied value does not match the supplied predicate.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
        messageSupplier - The supplier for the failure message to fail with.
      • assertDoubleDoesNotMatch

        public static void assertDoubleDoesNotMatch​(DoublePredicate matcher,
                                                    double actual)
        Asserts that the supplied value does not match the supplied predicate.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
      • assertDoubleDoesNotMatch

        public static void assertDoubleDoesNotMatch​(DoublePredicate matcher,
                                                    double actual,
                                                    String message)
        Asserts that the supplied value does not match the supplied predicate.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
        message - The failure message to fail with.
      • assertDoubleDoesNotMatch

        public static void assertDoubleDoesNotMatch​(DoublePredicate matcher,
                                                    double actual,
                                                    Supplier<String> messageSupplier)
        Asserts that the supplied value does not match the supplied predicate.
        Parameters:
        matcher - The predicate to use.
        actual - The value to check.
        messageSupplier - The supplier for the failure message to fail with.