How to capture a list of specific type with mockito

后端 未结 8 1592
天命终不由人
天命终不由人 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:45

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

    public class Test{
    
        @Mock
        private Service service;
    
        @Captor
        private ArgumentCaptor> captor;
    
        @Before
        public void init(){
            MockitoAnnotations.initMocks(this);
        }
    
        @Test 
        public void shouldDoStuffWithListValues() {
            //...
            verify(service).doStuff(captor.capture()));
        }
    }
    

提交回复
热议问题