Skip to content

ArgumentCaptor should be type aware #565

@ChristianSchwarz

Description

@ChristianSchwarz

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.

This issue was extracted from #358 and relates to #439.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions