How to capture a list of specific type with mockito

后端 未结 8 1596
天命终不由人
天命终不由人 2020-12-12 10:05

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

ArgumentCaptor> argumen         


        
8条回答
  •  死守一世寂寞
    2020-12-12 10:46

    List mockedList = mock(List.class);
    
    List l = new ArrayList();
    l.add("someElement");
    
    mockedList.addAll(l);
    
    ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(List.class);
    
    verify(mockedList).addAll(argumentCaptor.capture());
    
    List capturedArgument = argumentCaptor.>getValue();
    
    assertThat(capturedArgument, hasItem("someElement"));
    

提交回复
热议问题