mockito Getting started with mockito Check arguments passed to mock


Lets assume we have this class and we would like to test doSmth method. In this case we want to see if parameter "val" is passed to foo. Object foo is mocked.

public class Bar {

    private final Foo foo;

    public Bar(final Foo foo) { = foo;

    public void doSmth() {

We can achieve this with ArgumentCaptor:

private Foo fooMock;

private Bar underTest;

private ArgumentCaptor<String> stringCaptor;

public void should_test_smth() {


    assertThat(stringCaptor.getValue(), is("val"));