Class CheckerConsumer<T>
- Type Parameters:
T
- the type of the input to theConsumer
- All Implemented Interfaces:
InterfaceChecker<AbstractChecker<Consumer<T>,
CheckerConsumer<T>>, Consumer<T>>
A specialized checker for
Consumer
instances, providing fluent assertions
for verifying the behavior of Consumer operations. This class allows you to check if a Consumer
executes without exceptions, modifies its input as expected, or leaves its input unchanged.
Supports optional deep cloning of input objects to ensure that original inputs are not modified during validation.
Example usage:
CheckerConsumer<MyObject> checker = CheckerConsumer.check(myConsumer)
.activateDeepClone()
.applyWithoutException(myObject)
.modifiesInput(myObject, obj -> obj.isModified());
- See Also:
-
Field Summary
Fields inherited from class util.AbstractChecker
backObject, exceptionTracker, name, object, saveErrors, stop
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
CheckerConsumer
(Consumer<T> consumer, String name) Constructs a newCheckerConsumer
with the specified consumer and name. -
Method Summary
Modifier and TypeMethodDescriptionEnables deep cloning of input objects before passing them to theConsumer
.applyWithoutException
(Collection<T> input) Asserts that applying theConsumer
to all elements in the given collection does not throw any exception.applyWithoutException
(T input) Asserts that applying theConsumer
to the given input does not throw any exception.static <T> CheckerConsumer
<T> Creates a newCheckerConsumer
for the givenConsumer
instance with a default name.static <T> CheckerConsumer
<T> Creates a newCheckerConsumer
for the givenConsumer
instance with a custom name.Disables deep cloning of input objects before passing them to theConsumer
.doesNothing
(Collection<T> input) Asserts that applying theConsumer
to all elements in the given collection does not modify any input (all inputs remain unchanged).doesNothing
(T input) Asserts that applying theConsumer
to the given input does not modify the input (input remains unchanged).Returns the input object, deep-cloned if deep cloning is activated, otherwise returns the original input.modifiesInput
(Collection<T> input, Predicate<T> condition) Asserts that applying theConsumer
to all elements in the given collection modifies each input as specified by the provided condition.modifiesInput
(T input, Predicate<T> condition) Asserts that applying theConsumer
to the given input modifies the input as specified by the provided condition.protected CheckerConsumer
<T> 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
-
CheckerConsumer
-
-
Method Details
-
check
Creates a newCheckerConsumer
for the givenConsumer
instance with a custom name.- Type Parameters:
T
- the type of the input to theConsumer
- Parameters:
Consumer
- theConsumer
instance to be checkedname
- the name to identify this checker instance (useful for error messages)- Returns:
- a new
CheckerConsumer
for the providedConsumer
-
check
Creates a newCheckerConsumer
for the givenConsumer
instance with a default name.- Type Parameters:
T
- the type of the input to theConsumer
- Parameters:
Consumer
- theConsumer
instance to be checked- Returns:
- a new
CheckerConsumer
for the providedConsumer
-
self
Returns this checker instance (for fluent API usage).- Specified by:
self
in classAbstractChecker<Consumer<T>,
CheckerConsumer<T>> - Returns:
- this
CheckerConsumer
instance
-
activateDeepClone
Enables deep cloning of input objects before passing them to theConsumer
. This is useful to ensure that the original input is not modified by the operation.- Returns:
- this
CheckerConsumer
instance for further validation
-
deactivateDeepClone
Disables deep cloning of input objects before passing them to theConsumer
.- Returns:
- this
CheckerConsumer
instance for further validation
-
getInput
-
applyWithoutException
Asserts that applying theConsumer
to the given input does not throw any exception.- Parameters:
input
- the input object to be consumed- Returns:
- this
CheckerConsumer
instance for further validation
-
applyWithoutException
Asserts that applying theConsumer
to all elements in the given collection does not throw any exception.- Parameters:
input
- the collection of input objects to be consumed- Returns:
- this
CheckerConsumer
instance for further validation
-
modifiesInput
Asserts that applying theConsumer
to the given input modifies the input as specified by the provided condition.- Parameters:
input
- the input object to be consumedcondition
- a predicate to test the modified input after consumption- Returns:
- this
CheckerConsumer
instance for further validation
-
modifiesInput
Asserts that applying theConsumer
to all elements in the given collection modifies each input as specified by the provided condition.- Parameters:
input
- the collection of input objects to be consumedcondition
- a predicate to test each modified input after consumption- Returns:
- this
CheckerConsumer
instance for further validation
-
doesNothing
Asserts that applying theConsumer
to the given input does not modify the input (input remains unchanged).- Parameters:
input
- the input object to be consumed- Returns:
- this
CheckerConsumer
instance for further validation
-
doesNothing
Asserts that applying theConsumer
to all elements in the given collection does not modify any input (all inputs remain unchanged).- Parameters:
input
- the collection of input objects to be consumed- Returns:
- this
CheckerConsumer
instance for further validation
-