If you don't want to validate all the calls to doSomething()
, only the last one, you can just use ArgumentCaptor.getValue()
. According to the Mockito javadoc:
If the method was called multiple times then it returns the latest captured value
So this would work (assumes Foo
has a method getName()
):
ArgumentCaptor<Foo> fooCaptor = ArgumentCaptor.forClass(Foo.class);
verify(mockBar, times(2)).doSomething(fooCaptor.capture());
//getValue() contains value set in second call to doSomething()
assertEquals("2nd one", fooCaptor.getValue().getName());