Class CheckerFunction<T,R>
java.lang.Object
com.luchersol.core.util.AbstractChecker<Function<T,R>,CheckerFunction<T,R>>
com.luchersol.core.specialized_checkers.lambda.CheckerFunction<T,R>
- Type Parameters:
T- the type of the input to theFunctionbeing 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 com.luchersol.core.util.AbstractChecker
backObject, exceptionTracker, name, object, saveErrors, stop -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCheckerFunction(Function<T, R> function, String name) Constructs a newCheckerFunctionwith 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 theFunctionto the given input does not throw any exception.static <T,R> CheckerFunction <T, R> Creates a newCheckerFunctionfor the givenFunctioninstance with a default name.static <T,R> CheckerFunction <T, R> Creates a newCheckerFunctionfor the givenFunctioninstance 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 theFunctionto the given input produces the expected result.producesNonNull(T input) Asserts that applying theFunctionto 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 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
-
CheckerFunction
-
-
Method Details
-
check
Creates a newCheckerFunctionfor the givenFunctioninstance with a custom name.- Type Parameters:
T- the type of the input to theFunctionbeing checkedR- the type of the result returned by theFunction- Parameters:
function- theFunctioninstance to be checkedname- the name to identify this checker instance (useful for error messages)- Returns:
- a new
CheckerFunctionfor the providedFunction
-
check
Creates a newCheckerFunctionfor the givenFunctioninstance with a default name.- Type Parameters:
T- the type of the input to theFunctionbeing checkedR- the type of the result returned by theFunction- Parameters:
function- theFunctioninstance to be checked- Returns:
- a new
CheckerFunctionfor the providedFunction
-
self
Returns this checker instance (for fluent API usage).- Specified by:
selfin classAbstractChecker<Function<T,R>, CheckerFunction<T, R>> - Returns:
- this
CheckerFunctioninstance 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
CheckerFunctioninstance for further validation and chaining
-
deactivateDeepClone
Disables deep cloning of input objects before passing them to theFunction.- Returns:
- this
CheckerFunctioninstance for further validation and chaining
-
getInput
-
applyWithoutException
Asserts that applying theFunctionto 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
CheckerFunctioninstance for further validation and chaining
-
producesExpected
Asserts that applying theFunctionto 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
CheckerFunctioninstance for further validation and chaining
-
producesNonNull
Asserts that applying theFunctionto 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
CheckerFunctioninstance for further validation and chaining
-