In this article, we will present how to capture all arguments used in multiple method calls using the Mockito testing framework.
Mockito provides a special @Captor functionality used to capture the arguments passed to a method in mock object. This annotation always goes hand in hand with
Let's check a simple unit test that uses
In this example, we create a mock object with a list of
Person objects. Then we add two persons to the list and using
getAllValues() we get arguments from all method invocations.
This test answering the question given in the article title: to capture all arguments we used the
In this short article, we presented how to capture all arguments of a method that was called multiple times. Luckily Mockito holds all information about method invocations for future assertions.
As usual the code used in this article is available under GitHub repository.