mockito Verify method calls Verify call arguments using ArgumentCaptor


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

ArgumentCaptor<Foo> captor = ArgumentCaptor.forClass(Foo.class);
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:

private ArgumentCaptor<Foo> captor;