2017-04-13 43 views
0

我使用ExecutorCompletionService,并将以下方法从如何使用模拟上ExecutorCompletionService

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

现在正在写JUnit和调用的Mockito我想嘲弄上述两个呼叫。我怎样才能做到这一点?

回答

0

如果你只是想存根的嘲笑taskCompletionServicetake方法,那么你可以做这样的事情:

List<Student> studentDetails = Arrays.asList(fakeStudentDetail); 
when(taskCompletionService.take()) 
    .thenReturn(CompletableFuture.completedFuture(studentDetails));