In this case do I need to write a captor for each argument in spite of the fact I need to capture only the first argument?
durron597's answer is correct—you do not need to capture all arguments if you want to capture one of them. One point of clarification, though: a call to ArgumentCaptor.capture()
counts as a Mockito matcher, and in Mockito if you use a matcher for any method argument you do have to use a matcher for all arguments.
For a method yourMock.yourMethod(int, int, int)
and an ArgumentCaptor<Integer> intCaptor
:
/* good: */ verify(yourMock).yourMethod(2, 3, 4); // eq by default
/* same: */ verify(yourMock).yourMethod(eq(2), eq(3), eq(4));
/* BAD: */ verify(yourMock).yourMethod(intCaptor.capture(), 3, 4);
/* fixed: */ verify(yourMock).yourMethod(intCaptor.capture(), eq(3), eq(4));
These also work:
verify(yourMock).yourMethod(intCaptor.capture(), eq(5), otherIntCaptor.capture());
verify(yourMock).yourMethod(intCaptor.capture(), anyInt(), gt(9000));