Class AssertionPredicates

java.lang.Object
org.apache.juneau.assertions.AssertionPredicates

public class AssertionPredicates extends Object
Predefined AssertionPredicate objects.

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

Example:

// Asserts that a list contains te specified values. List<Object> myList = AList.of(...); assertList(myList) .is(eq("foo"), any(), match("bar*"));

See Also:
  • Constructor Details

  • Method Details

    • any

      public static final <T> AssertionPredicate<T> any()
      Predicate that always returns true.

      Note that this typically has the same affect as a null predicate.

      Type Parameters:
      T - The object type being tested.
      Returns:
      A new predicate.
    • notNull

      public static final <T> AssertionPredicate<T> notNull()
      Predicate that returns true if the tested value is not null.

      Assertion error message is "Value was null.".

      Type Parameters:
      T - The object type being tested.
      Returns:
      A new predicate.
    • isNull

      public static final <T> AssertionPredicate<T> isNull()
      Predicate that returns true if the tested value is null.

      Assertion error message is "Value was not null.".

      Type Parameters:
      T - The object type being tested.
      Returns:
      A new predicate.
    • eq

      public static final <T> AssertionPredicate<T> eq(Object value)
      Predicate that returns true if the tested value equals the specified value.

      Uses standard Java equality for testing.

      Assertion error message is "Value did not match expected. Expected='{0}', Actual='{1}'.".

      Type Parameters:
      T - The object type being tested.
      Parameters:
      value - The specified value.
      Returns:
      A new predicate.
    • eq

      public static final <T> AssertionPredicate<T> eq(String value)
      Predicate that returns true if the tested value converted to a string matches the specified value.

      Assertion error message is "Value did not match expected. Expected='{0}', Actual='{1}'.".

      Type Parameters:
      T - The object type being tested.
      Parameters:
      value - The specified value.
      Returns:
      A new predicate.
    • ne

      public static final <T> AssertionPredicate<T> ne(Object value)
      Predicate that returns true if the tested value does not match the specified value.

      Assertion error message is "Value unexpectedly matched. Value='{0}'.".

      Type Parameters:
      T - The object type being tested.
      Parameters:
      value - The specified value.
      Returns:
      A new predicate.
    • ne

      public static final <T> AssertionPredicate<T> ne(String value)
      Predicate that returns true if the tested value converted to a string does not match the specified value.

      Assertion error message is "Value unexpectedly matched. Value='{0}'.".

      Type Parameters:
      T - The object type being tested.
      Parameters:
      value - The specified value.
      Returns:
      A new predicate.
    • eqic

      public static final <T> AssertionPredicate<T> eqic(String value)
      Predicate that returns true if the tested value converted to a string does not match the specified value ignoring case.

      Assertion error message is "Value did not match expected. Expected='{0}', Actual='{1}'.".

      Type Parameters:
      T - The object type being tested.
      Parameters:
      value - The specified value.
      Returns:
      A new predicate.
    • contains

      public static final <T> AssertionPredicate<T> contains(String value)
      Predicate that returns true if the tested value converted to a string contains the specified substring.

      Assertion error message is "Value did not contain expected. Expected='{0}', Actual='{1}'.".

      Type Parameters:
      T - The object type being tested.
      Parameters:
      value - The specified value.
      Returns:
      A new predicate.
    • type

      public static final <T> AssertionPredicate<T> type(Class<?> type)
      Predicate that returns true if the tested value is the specified or child type.

      Assertion error message is "Value was not expected type. Expected='{0}', Actual='{1}'.".

      Type Parameters:
      T - The object type being tested.
      Parameters:
      type - The specified type.
      Returns:
      A new predicate.
    • exactType

      public static final <T> AssertionPredicate<T> exactType(Class<?> type)
      Predicate that returns true if the tested value is exactly specified type.

      Assertion error message is "Value was not expected type. Expected='{0}', Actual='{1}'.".

      Type Parameters:
      T - The object type being tested.
      Parameters:
      type - The specified type.
      Returns:
      A new predicate.
    • match

      public static final <T> AssertionPredicate<T> match(String value)
      Predicate that returns true if the tested value converted to a string matches the specified match pattern.

      Match pattern can contain the "*" meta-character.

      Assertion error message is "Value did not match pattern. Pattern='{0}', Actual='{1}'.".

      Type Parameters:
      T - The object type being tested.
      Parameters:
      value - The specified value.
      Returns:
      A new predicate.
    • regex

      public static final <T> AssertionPredicate<T> regex(String expression)
      Predicate that returns true if the tested value converted to a string matches the specified regular expression.

      Assertion error message is "Value did not match pattern. Pattern='{0}', Actual='{1}'.".

      Type Parameters:
      T - The object type being tested.
      Parameters:
      expression - The regular expression to match.
      Returns:
      A new predicate.
    • regex

      public static final <T> AssertionPredicate<T> regex(String expression, int flags)
      Predicate that returns true if the tested value converted to a string matches the specified regular expression.

      Assertion error message is "Value did not match pattern. Pattern='{0}', Actual='{1}'.".

      Type Parameters:
      T - The object type being tested.
      Parameters:
      expression - The regular expression to match.
      flags - Match flags, a bit mask that may include:
      Returns:
      A new predicate.
    • regex

      public static final <T> AssertionPredicate<T> regex(Pattern value)
      Predicate that returns true if the tested value converted to a string matches the specified regular expression.

      Assertion error message is "Value did not match pattern. Pattern='{0}', Actual='{1}'.".

      Type Parameters:
      T - The object type being tested.
      Parameters:
      value - The regular expression to match.
      Returns:
      A new predicate.
    • test

      public static final <T> AssertionPredicate<T> test(Predicate<T> predicate)
      Predicate that wraps another predicate.

      If the predicate extends from AssertionPredicate, the assertion error message is "Value did not pass test." followed by the inner assertion error. Otherwise the message is "Value did not pass test. Value='{0}'."

      Type Parameters:
      T - The object type being tested.
      Parameters:
      predicate - The predicate to run.
      Returns:
      A new predicate.
    • test

      public static final <T> AssertionPredicate<T> test(Predicate<T> predicate, String msg, Object... args)
      Predicate that wraps another predicate.

      If the message specified is null and the predicate extends from AssertionPredicate, the assertion error message is "Value did not pass test." followed by the inner assertion error. Otherwise the message is "Value did not pass test. Value='{0}'."

      Type Parameters:
      T - The object type being tested.
      Parameters:
      predicate - The predicate to run.
      msg - 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.
      Returns:
      A new predicate.
    • and

      @SafeVarargs public static final <T> AssertionPredicate<T> and(Predicate<T>... predicates)
      Combines the specified predicates into a singled AND'ed predicate.

      Assertion error message is "Predicate test #x failed." followed by the inner failed message if the failed predicate extends from AssertionPredicate.

      Type Parameters:
      T - The predicate type.
      Parameters:
      predicates - The predicates to combine.
      Returns:
      The combined predicates.
    • or

      @SafeVarargs public static final <T> AssertionPredicate<T> or(Predicate<T>... predicates)
      Combines the specified predicates into a singled OR'ed predicate.

      Assertion error message is "No predicate tests passed.".

      Type Parameters:
      T - The predicate type.
      Parameters:
      predicates - The predicates to combine.
      Returns:
      The combined predicates.
    • not

      public static final <T> AssertionPredicate<T> not(Predicate<T> predicate)
      Negates the specified predicate.

      Assertion error message is "Predicate test unexpectedly passed.".

      Type Parameters:
      T - The predicate type.
      Parameters:
      predicate - The predicate to negate.
      Returns:
      The combined predicates.