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 thePredicate
being 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 util.AbstractChecker
backObject, exceptionTracker, name, object, saveErrors, stop
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
CheckerPredicate
(Predicate<T> predicate, String name) Constructs a newCheckerPredicate
with 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 newCheckerPredicate
for the givenPredicate
instance with a default name.static <T> CheckerPredicate
<T> Creates a newCheckerPredicate
for the givenPredicate
instance with a custom name.Disables deep cloning of input objects before passing them to thePredicate
.evaluatesFalse
(T input) Asserts that testing thePredicate
with the given input evaluates tofalse
.evaluatesTrue
(T input) Asserts that testing thePredicate
with the given input evaluates totrue
.producesExpected
(T input, boolean expected) Asserts that testing thePredicate
with 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 thePredicate
with the given input does not throw any exception.Methods inherited from class util.AbstractChecker
checkProperty, checkProperty, checkProperty, end, getMethod, getObject, getProperty, hasErrors, hasNotErrors, is, is, isEqual, isNonNull, isNot, isNot, isNull, notSaveErrors, saveErrors, show, showNotThrownException, showThrownException, stop
-
Constructor Details
-
CheckerPredicate
-
-
Method Details
-
check
Creates a newCheckerPredicate
for the givenPredicate
instance with a custom name.- Type Parameters:
T
- the type of the input to thePredicate
- Parameters:
predicate
- thePredicate
instance to be checkedname
- the name to identify this checker instance (useful for error messages)- Returns:
- a new
CheckerPredicate
for the providedPredicate
-
check
Creates a newCheckerPredicate
for the givenPredicate
instance with a default name.- Type Parameters:
T
- the type of the input to thePredicate
- Parameters:
predicate
- thePredicate
instance to be checked- Returns:
- a new
CheckerPredicate
for the providedPredicate
-
self
Returns this checker instance (for fluent API usage).- Specified by:
self
in classAbstractChecker<Predicate<T>,
CheckerPredicate<T>> - Returns:
- this
CheckerPredicate
instance
-
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
CheckerPredicate
instance for further validation
-
deactivateDeepClone
Disables deep cloning of input objects before passing them to thePredicate
.- Returns:
- this
CheckerPredicate
instance for further validation
-
testWithoutException
Asserts that testing thePredicate
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
Asserts that testing thePredicate
with the given input evaluates totrue
.- Parameters:
input
- the input object to be tested by the predicate- Returns:
- this
CheckerPredicate
instance for further validation
-
evaluatesFalse
Asserts that testing thePredicate
with the given input evaluates tofalse
.- Parameters:
input
- the input object to be tested by the predicate- Returns:
- this
CheckerPredicate
instance for further validation
-
producesExpected
Asserts that testing thePredicate
with 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
CheckerPredicate
instance for further validation
-