Class AssertConsumeCount<T>
java.lang.Object
org.soliscode.test.assertions.actions.AssertConsumeCount<T>
- Type Parameters:
T
- element type
- All Implemented Interfaces:
Consumer<T>
,AssertAction
,AssertConsumer<T>
A consumer that counts each time it consumes an object and asserts that it has consumed the expected number of
objects when done. Instead of instantiating this class directly, the AssertActions
utility class should be used:
Consumer<Integer> consumer = AssertActions.consumeCount(3);
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.consumeCount(7);
collection.forEach(consumer);
consumer.assertCheck();
- Since:
- 1.0
- Author:
- evanbergstrom
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAssertConsumeCount
(int expected) Create a consumer that expect to consume a specified number of objects.AssertConsumeCount
(int expected, @Nullable String message) Create a consumer that expect to consume a specified number of objects.AssertConsumeCount
(int expected, @Nullable Supplier<String> messageSupplier) Create a consumer that expect to consume a specified number of objects. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Increments the count of the number of times the consumer has been used.void
Asserts that the consumer has been called the expected number of times.
-
Constructor Details
-
AssertConsumeCount
public AssertConsumeCount(int expected) Create a consumer that expect to consume a specified number of objects.- Parameters:
expected
- the number of objects to expect.
-
AssertConsumeCount
Create a consumer that expect to consume a specified number of objects. This constructor allows specification of a string to be included in the exception of the assertion fails.- Parameters:
expected
- the number of objects to expect.message
- the text to include in the exception.
-
AssertConsumeCount
Create a consumer that expect to consume a specified number of objects. This constructor allows specification of a supplier of a message to be included in the exception.- Parameters:
expected
- the number of objects to expect.messageSupplier
- the supplier of the text to include in the exception.
-
-
Method Details
-
accept
-
assertCheck
public void assertCheck()Asserts that the consumer has been called the expected number of times.- Specified by:
assertCheck
in interfaceAssertAction
- Throws:
org.opentest4j.AssertionFailedError
- if the consumer has not been called the expected number of times.
-