Back
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 bypassed amidst the @Captor annotation:
@RunWith(MockitoJUnitRunner.class)public class Test{ @Mock private Service service; @Captor private ArgumentCaptor<ArrayList<SomeType>> captor; @Before public void init(){ MockitoAnnotations.initMocks(this); } @Test public void shouldDoStuffWithListValues() { //... verify(service).doStuff(captor.capture())); }}
@RunWith(MockitoJUnitRunner.class)
public class Test{
@Mock
private Service service;
@Captor
private ArgumentCaptor<ArrayList<SomeType>> captor;
@Before
public void init(){
MockitoAnnotations.initMocks(this);
}
@Test
public void shouldDoStuffWithListValues() {
//...
verify(service).doStuff(captor.capture()));
31k questions
32.8k answers
501 comments
693 users