How can Mockito capture arguments passed to an injected mock object’s methods?

Use one, or more, ArgumentCaptors.

It is unclear what your types are here, but anyway. Let’s suppose you have a mock which has a method doSomething() taking a Foo as an argument, then you do this:

final ArgumentCaptor<Foo> captor = ArgumentCaptor.forClass(Foo.class);

verify(mock).doSomething(captor.capture());

final Foo argument = captor.getValue();

// Test the argument

Also, it looks like your method returns void and you don’t want it to do anything. Just write this:

doNothing().when(theMock).doSomething(any());

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)