2017-04-13 71 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));