Class CheckerPredicate<T>

java.lang.Object
util.AbstractChecker<Predicate<T>,CheckerPredicate<T>>
specialized_checkers.lambda.CheckerPredicate<T>
Type Parameters:
T - the type of the input to the Predicate being checked
All Implemented Interfaces:
InterfaceChecker<AbstractChecker<Predicate<T>,CheckerPredicate<T>>,Predicate<T>>

public class CheckerPredicate<T> extends AbstractChecker<Predicate<T>,CheckerPredicate<T>>
A specialized checker for Predicate instances, providing a fluent API for validating function behavior and results. This class allows assertions such as verifying that a function does not throw exceptions, produces expected results, or returns non-null values for given inputs. It also supports optional deep cloning of input objects to ensure immutability during checks.

Example usage:

     CheckerPredicate<String> checker = CheckerPredicate.check(String::isEmpty);
     checker.producesExpected("   ", false)
            .evaluatesTrue("")
            .testWithoutException("hello");
 

Deep cloning can be enabled to ensure that the input object is not mutated by the function:

     checker.activateDeepClone();
 
See Also:
  • Constructor Details

    • CheckerPredicate

      protected CheckerPredicate(Predicate<T> predicate, String name)
      Constructs a new CheckerPredicate with the specified predicate and name.
      Parameters:
      predicate - the Predicate to be used by this checker
      name - the name identifying this checker
  • Method Details

    • check

      public static <T> CheckerPredicate<T> check(Predicate<T> predicate, String name)
      Creates a new CheckerPredicate for the given Predicate instance with a custom name.
      Type Parameters:
      T - the type of the input to the Predicate
      Parameters:
      predicate - the Predicate instance to be checked
      name - the name to identify this checker instance (useful for error messages)
      Returns:
      a new CheckerPredicate for the provided Predicate
    • check

      public static <T> CheckerPredicate<T> check(Predicate<T> predicate)
      Creates a new CheckerPredicate for the given Predicate instance with a default name.
      Type Parameters:
      T - the type of the input to the Predicate
      Parameters:
      predicate - the Predicate instance to be checked
      Returns:
      a new CheckerPredicate for the provided Predicate
    • self

      protected CheckerPredicate<T> self()
      Returns this checker instance (for fluent API usage).
      Specified by:
      self in class AbstractChecker<Predicate<T>,CheckerPredicate<T>>
      Returns:
      this CheckerPredicate instance
    • activateDeepClone

      public CheckerPredicate<T> activateDeepClone()
      Enables deep cloning of input objects before passing them to the Predicate. This is useful to ensure that the original input is not modified by the operation.
      Returns:
      this CheckerPredicate instance for further validation
    • deactivateDeepClone

      public CheckerPredicate<T> deactivateDeepClone()
      Disables deep cloning of input objects before passing them to the Predicate.
      Returns:
      this CheckerPredicate instance for further validation
    • testWithoutException

      public CheckerPredicate<T> testWithoutException(T input)
      Asserts that testing the Predicate with the given input does not throw any exception.
      Parameters:
      input - the input object to be tested by the predicate
      Returns:
      this CheckerPredicate instance for further validation
    • evaluatesTrue

      public CheckerPredicate<T> evaluatesTrue(T input)
      Asserts that testing the Predicate with the given input evaluates to true.
      Parameters:
      input - the input object to be tested by the predicate
      Returns:
      this CheckerPredicate instance for further validation
    • evaluatesFalse

      public CheckerPredicate<T> evaluatesFalse(T input)
      Asserts that testing the Predicate with the given input evaluates to false.
      Parameters:
      input - the input object to be tested by the predicate
      Returns:
      this CheckerPredicate instance for further validation
    • producesExpected

      public CheckerPredicate<T> producesExpected(T input, boolean expected)
      Asserts that testing the Predicate with the given input produces the expected boolean result.
      Parameters:
      input - the input object to be tested by the predicate
      expected - the expected boolean result to compare with the actual result of the predicate
      Returns:
      this CheckerPredicate instance for further validation