I ran into a problem when I need to track the call of a method, but only with the specified argument parameter. See Question below.
@Test
public void simpleTest() {
ArgumentCaptor<Pear> captor = ArgumentCaptor.forClass(Pear.class);
Action action = mock(Action.class);
action.perform(new Pear());
action.perform(new Apple());
verify(action, times(1)).perform(captor.capture());
}
static class Action {
public void perform(IFruit fruit) {}
}
static class Pear implements IFruit {}
static class Apple implements IFruit {}
interface IFruit {}
But getting:
org.mockito.exceptions.verification.TooManyActualInvocations:
action.perform(<Capturing argument>);
Wanted 1 time:
But was 2 times. Undesired invocation:
..
What am I doing wrong? Mockito v 1.10
Honestly, it's simple, and my code is more complex, and I don't know how many times the execution will be called using Apple.class. It's not important for me. I need to check only the execution call (Pear.class)
UPD:
, Pear.class . , - , - (DomainObject). , save (MyDomainObject) , , . , reset mock