Bravo
Bravo

Reputation: 9027

How to use mock on ExecutorCompletionService

I am using ExecutorCompletionService and below method calls from that

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

Now am writing Junit and Mockito and I want to mock above two calls. How can I achieve that?

Upvotes: 1

Views: 729

Answers (1)

David Rawson
David Rawson

Reputation: 21417

If you simply want to stub for the take method of a mocked taskCompletionService then you could do something like this:

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

Upvotes: 1

Related Questions