Class AssertConsumeExactly<T>

java.lang.Object
org.soliscode.test.assertions.actions.AssertConsumeExactly<T>
Type Parameters:
T - element type
All Implemented Interfaces:
Consumer<T>, AssertAction, AssertConsumer<T>

public class AssertConsumeExactly<T> extends Object implements AssertConsumer<T>

A consumer that checks that is consumes a specified set of objects, consuming each of those objects once, and not consuming any objects not in the set. This consumer requires that all of the objects in the set are consumed. Instead of instantiating this class directly, the AssertActions utility class should be used:

Consumer<Integer> consumer = AssertActions.consumeExactly(Set.of(1, 3, 5, 7));

This assertion action must be checked after the method it is passed to has completed, so the assertCheck() method will need to be explicitly called:

AssertConsumer<Integer> consumer = AssertActions.consumeExactly(Set.of(1, 3, 5, 7);
collection.forEach(consumer);
consumer.assertCheck();
Since:
1.0
Author:
evanbergstrom
See Also:
  • Constructor Details

    • AssertConsumeExactly

      public AssertConsumeExactly(@NotNull @NotNull Iterable<T> expected)
      A consumer that checks that is consumes a specified set of objects.
      Parameters:
      expected - the set of objects that should be consumed.
    • AssertConsumeExactly

      public AssertConsumeExactly(@NotNull @NotNull Iterable<T> expected, @Nullable @Nullable String message)
      A consumer that checks that is consumes a specified set of objects. This constructor allows specification of a string to be included in the exception of the assertion fails.
      Parameters:
      expected - the set of objects that should be consumed.
      message - the text to include in the exception.
    • AssertConsumeExactly

      public AssertConsumeExactly(@NotNull @NotNull Iterable<T> expected, @Nullable @Nullable Supplier<String> messageSupplier)
      A consumer that checks that is consumes a specified set of objects. This constructor allows specification of a supplier of a message to be included in the exception.
      Parameters:
      expected - the set of objects that should be consumed.
      messageSupplier - the supplier of the text to include in the exception.
  • Method Details

    • accept

      public void accept(T e)
      Specified by:
      accept in interface Consumer<T>
    • assertCheck

      public void assertCheck()
      Description copied from interface: AssertAction
      An assertion method that is called after a method had used the action and returned. This is used to test assertions on the aggregate effect of calling an action multiple times during the execution of a method.
      Specified by:
      assertCheck in interface AssertAction