Andreas Köberle Andreas Köberle - 8 months ago 76
Java Question

How to capture a list of specific type with mockito

Is there a way to capture a list of specific type using mockitos ArgumentCaptore. This doesn't work:

ArgumentCaptor<ArrayList<SomeType>> argument = ArgumentCaptor.forClass(ArrayList.class);


The nested generics-problem can be avoided with the @Captor annotation:

public class Test{

    private Service service;

    private ArgumentCaptor<ArrayList<SomeType>> captor;

    public void shouldDoStuffWithListValues() {