当尝试使用ArgumentCaptor捕获ArrayList参数时,结果对象始终是一个空列表。
我正在使用@Captor批注创建我的ArgumentCaptor,但是它仍然导致返回一个空列表。
@RunWith(MockitoJUnitRunner.class)
public class Test{
@Mock
private Service service;
@Captor
private ArgumentCaptor<ArrayList<SomeType>> secondCaptor;
@Before
public void init(){
MockitoAnnotations.initMocks(this);
}
@Test
public void shouldDoStuffWithListValues(){
ArgumentCaptor<SomeType> captor = ArgumentCaptor.forClass(SomeType.class);
//...
verify(service).doStuff(captor.capture(), secondCaptor.capture()));
SomeType type = captor.getValue();
List<SomeType> someTypeList = secondCaptor.getValue();
//this assert is fine
Assert.assertTrue(type != null);
//whereas; this assert always fails, despite the call containing a value
Assert.assertTrue(someTypeList.size()>0);
}
}