Andreas Köberle Andreas Köberle - 2 months ago 24x
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() {