Class CheckerFunction<T,R>
java.lang.Object
util.AbstractChecker<Function<T,R>,CheckerFunction<T,R>>
specialized_checkers.lambda.CheckerFunction<T,R>
- Type Parameters:
T
- the type of the input to theFunction
being checkedR
- the type of the result returned by theFunction
- All Implemented Interfaces:
InterfaceChecker<AbstractChecker<Function<T,
R>, CheckerFunction<T, R>>, Function<T, R>>
A specialized checker for
Function
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:
CheckerFunction<String, Integer> checker = CheckerFunction.check(String::length); checker.producesExpected("abc", 3) .applyWithoutException("test") .producesNonNull("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
CheckerFunction
(Function<T, R> function, String name) Constructs a newCheckerFunction
with the specified function and name. -
Method Summary
Modifier and TypeMethodDescriptionEnables deep cloning of input objects before passing them to theFunction
.applyWithoutException
(T input) Asserts that applying theFunction
to the given input does not throw any exception.static <T,
R> CheckerFunction <T, R> Creates a newCheckerFunction
for the givenFunction
instance with a default name.static <T,
R> CheckerFunction <T, R> Creates a newCheckerFunction
for the givenFunction
instance with a custom name.Disables deep cloning of input objects before passing them to theFunction
.Returns the input object, deep-cloned if deep cloning is activated, otherwise returns the original input.producesExpected
(T input, R expected) Asserts that applying theFunction
to the given input produces the expected result.producesNonNull
(T input) Asserts that applying theFunction
to the given input produces a non-null result.protected CheckerFunction
<T, R> self()
Returns this checker instance (for fluent API usage).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
-
CheckerFunction
-
-
Method Details
-
check
Creates a newCheckerFunction
for the givenFunction
instance with a custom name.- Type Parameters:
T
- the type of the input to theFunction
being checkedR
- the type of the result returned by theFunction
- Parameters:
function
- theFunction
instance to be checkedname
- the name to identify this checker instance (useful for error messages)- Returns:
- a new
CheckerFunction
for the providedFunction
-
check
Creates a newCheckerFunction
for the givenFunction
instance with a default name.- Type Parameters:
T
- the type of the input to theFunction
being checkedR
- the type of the result returned by theFunction
- Parameters:
function
- theFunction
instance to be checked- Returns:
- a new
CheckerFunction
for the providedFunction
-
self
Returns this checker instance (for fluent API usage).- Specified by:
self
in classAbstractChecker<Function<T,
R>, CheckerFunction<T, R>> - Returns:
- this
CheckerFunction
instance for further validation and chaining
-
activateDeepClone
Enables deep cloning of input objects before passing them to theFunction
.This is useful to ensure that the original input is not modified by the operation, especially when the function may mutate its input.
- Returns:
- this
CheckerFunction
instance for further validation and chaining
-
deactivateDeepClone
Disables deep cloning of input objects before passing them to theFunction
.- Returns:
- this
CheckerFunction
instance for further validation and chaining
-
getInput
-
applyWithoutException
Asserts that applying theFunction
to the given input does not throw any exception.This check is useful to ensure that the function is safe to apply to the provided input and does not result in runtime errors.
- Parameters:
input
- the input object to be processed by the function- Returns:
- this
CheckerFunction
instance for further validation and chaining
-
producesExpected
Asserts that applying theFunction
to the given input produces the expected result.This check compares the actual result of the function with the expected value using content equality.
- Parameters:
input
- the input object to be processed by the functionexpected
- the expected result to compare with the actual result of the function- Returns:
- this
CheckerFunction
instance for further validation and chaining
-
producesNonNull
Asserts that applying theFunction
to the given input produces a non-null result.This check is useful to ensure that the function always returns a valid (non-null) result for the given input.
- Parameters:
input
- the input object to be processed by the function- Returns:
- this
CheckerFunction
instance for further validation and chaining
-