Class CheckerConsumer<T>

java.lang.Object
util.AbstractChecker<Consumer<T>,CheckerConsumer<T>>
specialized_checkers.lambda.CheckerConsumer<T>
Type Parameters:
T - the type of the input to the Consumer
All Implemented Interfaces:
InterfaceChecker<AbstractChecker<Consumer<T>,CheckerConsumer<T>>,Consumer<T>>

public class CheckerConsumer<T> extends AbstractChecker<Consumer<T>,CheckerConsumer<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:
  • Constructor Details

    • CheckerConsumer

      protected CheckerConsumer(Consumer<T> consumer, String name)
      Constructs a new CheckerConsumer with the specified consumer and name.
      Parameters:
      consumer - the Consumer to be used by this checker
      name - the name identifying this checker
  • Method Details

    • check

      public static <T> CheckerConsumer<T> check(Consumer<T> Consumer, String name)
      Creates a new CheckerConsumer for the given Consumer instance with a custom name.
      Type Parameters:
      T - the type of the input to the Consumer
      Parameters:
      Consumer - the Consumer instance to be checked
      name - the name to identify this checker instance (useful for error messages)
      Returns:
      a new CheckerConsumer for the provided Consumer
    • check

      public static <T> CheckerConsumer<T> check(Consumer<T> Consumer)
      Creates a new CheckerConsumer for the given Consumer instance with a default name.
      Type Parameters:
      T - the type of the input to the Consumer
      Parameters:
      Consumer - the Consumer instance to be checked
      Returns:
      a new CheckerConsumer for the provided Consumer
    • self

      protected CheckerConsumer<T> self()
      Returns this checker instance (for fluent API usage).
      Specified by:
      self in class AbstractChecker<Consumer<T>,CheckerConsumer<T>>
      Returns:
      this CheckerConsumer instance
    • activateDeepClone

      public CheckerConsumer<T> activateDeepClone()
      Enables deep cloning of input objects before passing them to the Consumer. This is useful to ensure that the original input is not modified by the operation.
      Returns:
      this CheckerConsumer instance for further validation
    • deactivateDeepClone

      public CheckerConsumer<T> deactivateDeepClone()
      Disables deep cloning of input objects before passing them to the Consumer.
      Returns:
      this CheckerConsumer instance for further validation
    • getInput

      public T getInput(T input)
      Returns the input object, deep-cloned if deep cloning is activated, otherwise returns the original input.
      Parameters:
      input - the input object to process
      Returns:
      the processed input (deep-cloned or original)
    • applyWithoutException

      public CheckerConsumer<T> applyWithoutException(T input)
      Asserts that applying the Consumer 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

      public CheckerConsumer<T> applyWithoutException(Collection<T> input)
      Asserts that applying the Consumer 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

      public CheckerConsumer<T> modifiesInput(T input, Predicate<T> condition)
      Asserts that applying the Consumer to the given input modifies the input as specified by the provided condition.
      Parameters:
      input - the input object to be consumed
      condition - a predicate to test the modified input after consumption
      Returns:
      this CheckerConsumer instance for further validation
    • modifiesInput

      public CheckerConsumer<T> modifiesInput(Collection<T> input, Predicate<T> condition)
      Asserts that applying the Consumer 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 consumed
      condition - a predicate to test each modified input after consumption
      Returns:
      this CheckerConsumer instance for further validation
    • doesNothing

      public CheckerConsumer<T> doesNothing(T input)
      Asserts that applying the Consumer 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

      public CheckerConsumer<T> doesNothing(Collection<T> input)
      Asserts that applying the Consumer 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