1

我正在使用 ExecutorCompletionService 和下面的方法调用

Future<List<Student>> studentDetails = taskCompletionService.take();
Lis<Student> details =studentDetails.get()

现在正在编写 Junit 和 Mockito,我想模拟以上两个调用。我怎样才能做到这一点?

4

1 回答 1

1

如果您只是想为模拟的take方法存根,taskCompletionService那么您可以执行以下操作:

List<Student> studentDetails = Arrays.asList(fakeStudentDetail); 
when(taskCompletionService.take())
    .thenReturn(CompletableFuture.completedFuture(studentDetails));
于 2017-04-14T22:23:44.927 回答