Class CheckerPredicate<T>
java.lang.Object
com.luchersol.core.util.AbstractChecker<Predicate<T>,CheckerPredicate<T>>
com.luchersol.core.specialized_checkers.lambda.CheckerPredicate<T>
- Type Parameters:
T- the type of the input to thePredicatebeing checked
- All Implemented Interfaces:
InterfaceChecker<AbstractChecker<Predicate<T>,CheckerPredicate<T>>, Predicate<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:
-
Field Summary
Fields inherited from class com.luchersol.core.util.AbstractChecker
backObject, exceptionTracker, name, object, saveErrors, stop -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCheckerPredicate(Predicate<T> predicate, String name) Constructs a newCheckerPredicatewith the specified predicate and name. -
Method Summary
Modifier and TypeMethodDescriptionEnables deep cloning of input objects before passing them to thePredicate.static <T> CheckerPredicate<T> Creates a newCheckerPredicatefor the givenPredicateinstance with a default name.static <T> CheckerPredicate<T> Creates a newCheckerPredicatefor the givenPredicateinstance with a custom name.Disables deep cloning of input objects before passing them to thePredicate.evaluatesFalse(T input) Asserts that testing thePredicatewith the given input evaluates tofalse.evaluatesTrue(T input) Asserts that testing thePredicatewith the given input evaluates totrue.producesExpected(T input, boolean expected) Asserts that testing thePredicatewith the given input produces the expected boolean result.protected CheckerPredicate<T> self()Returns this checker instance (for fluent API usage).testWithoutException(T input) Asserts that testing thePredicatewith the given input does not throw any exception.Methods inherited from class com.luchersol.core.util.AbstractChecker
checkProperty, checkProperty, checkProperty, checkProperty, end, getMethod, getObject, getProperty, hasErrors, hasNotErrors, is, is, is, isEqual, isNonNull, isNot, isNot, isNull, notSaveErrors, saveErrors, setBackObject, setExceptionTracker, setName, setObject, setSaveErrors, setStop, show, showPassedChecks, showThrownException, stop, toChecker, updateChecker
-
Constructor Details
-
CheckerPredicate
-
-
Method Details
-
check
Creates a newCheckerPredicatefor the givenPredicateinstance with a custom name.- Type Parameters:
T- the type of the input to thePredicate- Parameters:
predicate- thePredicateinstance to be checkedname- the name to identify this checker instance (useful for error messages)- Returns:
- a new
CheckerPredicatefor the providedPredicate
-
check
Creates a newCheckerPredicatefor the givenPredicateinstance with a default name.- Type Parameters:
T- the type of the input to thePredicate- Parameters:
predicate- thePredicateinstance to be checked- Returns:
- a new
CheckerPredicatefor the providedPredicate
-
self
Returns this checker instance (for fluent API usage).- Specified by:
selfin classAbstractChecker<Predicate<T>,CheckerPredicate<T>> - Returns:
- this
CheckerPredicateinstance
-
activateDeepClone
Enables deep cloning of input objects before passing them to thePredicate. This is useful to ensure that the original input is not modified by the operation.- Returns:
- this
CheckerPredicateinstance for further validation
-
deactivateDeepClone
Disables deep cloning of input objects before passing them to thePredicate.- Returns:
- this
CheckerPredicateinstance for further validation
-
testWithoutException
Asserts that testing thePredicatewith the given input does not throw any exception.- Parameters:
input- the input object to be tested by the predicate- Returns:
- this
CheckerPredicateinstance for further validation
-
evaluatesTrue
Asserts that testing thePredicatewith the given input evaluates totrue.- Parameters:
input- the input object to be tested by the predicate- Returns:
- this
CheckerPredicateinstance for further validation
-
evaluatesFalse
Asserts that testing thePredicatewith the given input evaluates tofalse.- Parameters:
input- the input object to be tested by the predicate- Returns:
- this
CheckerPredicateinstance for further validation
-
producesExpected
Asserts that testing thePredicatewith the given input produces the expected boolean result.- Parameters:
input- the input object to be tested by the predicateexpected- the expected boolean result to compare with the actual result of the predicate- Returns:
- this
CheckerPredicateinstance for further validation
-