mockito Verify method calls Verify call arguments using ArgumentCaptor


Example

ArgumentCaptor will to receive the actual invocation arguments that has been passed to method.

ArgumentCaptor<Foo> captor = ArgumentCaptor.forClass(Foo.class);
verify(mockObj).doSomethind(captor.capture());
Foo invocationArg = captor.getValue();
//do any assertions on invocationArg

For cases of multiple invocations of mocked method to receive all invocation arguments

List<Foo> invocationArgs = captor.getAllValues();

The same approach is used for capturing varargs.

Also there is possibility to create ArgumentCaptor using @Captor annotation:

@Captor
private ArgumentCaptor<Foo> captor;