-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
Milestone
Description
Assume we have the following test.
@Mock
private Consumer<Collection<?>> consumer;
@Test
public void test() throws Exception {
consumer.accept(new HashSet<>());
consumer.accept(new ArrayList<>());
ArgumentCaptor<ArrayList<?>> captor = ArgumentCaptor.forClass(ArrayList.class);
verify(consumer).accept(captor.capture());
}
The test fails with:
org.mockito.exceptions.verification.TooManyActualInvocations:
consumer.accept(<Capturing argument>);
Wanted 1 time:
-> at foo.TestClass.testName(TestClass.java:64)
But was 2 times. Undesired invocation:
-> at agh.TestClass.testName(TestClass.java:61)
at foo.TestClass.test(TestClass.java:64)
[..]
The problem here is that ArgumentCaptor is not type aware. That should be fixed.
dariush-moshiri, derTobsch and jesantana