Class AssertionPredicate<T>

Type Parameters:
T - the type of input being tested.
All Implemented Interfaces:
Direct Known Subclasses:
AssertionPredicate.And, AssertionPredicate.Not, AssertionPredicate.Or

public class AssertionPredicate<T> extends Object implements Predicate<T>
Wrapper around a Predicate that allows for an error message for when the predicate fails.

Typically used wherever predicates are allowed for testing of Assertion objects such as...

See AssertionPredicates for a set of predefined predicates for common use cases.


// Asserts that a bean passes a custom test. // AssertionError with specified message is thrown otherwise. Predicate<MyBean> predicate = new AssertionPredicate<MyBean>( x -> x.getFoo().equals("bar"), "Foo did not equal bar. Bean was=''{0}''", VALUE ); assertObject(myBean).is(predicate);

See Also:
  • Field Details

  • Constructor Details

    • AssertionPredicate

      public AssertionPredicate(Predicate<T> inner, String message, Object... args)
      inner - The predicate test.
      message - The error message if predicate fails.
      Supports MessageFormat-style arguments.
      args - Optional message arguments.
      Can contain VALUE to specify the value itself as an argument.
      Can contain functions to apply to the tested value.
  • Method Details

    • test

      public boolean test(T t)
      Specified by:
      test in interface Predicate<T>
    • getFailureMessage

      Returns the error message from the last call to this assertion.
      The error message, or null if there was no failure.