【问题标题】:How to use mock on ExecutorCompletionService如何在 ExecutorCompletionService 上使用模拟
【发布时间】:2017-04-13 10:48:46
【问题描述】:

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

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

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

【问题讨论】:

    标签: java junit mockito completion-service


    【解决方案1】:

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

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

    【讨论】:

    • 这必须被接受为答案。它帮助我解决了我的问题。谢谢大卫!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-22
    • 2012-05-03
    • 1970-01-01
    • 2011-02-23
    • 1970-01-01
    • 2016-03-07
    • 1970-01-01
    相关资源
    最近更新 更多