CompletableFuture was introduced in Java 8. As the current line of
Mockito 2.x is Java 7 compatible there seems not to be a (simple*) way
to cover default answer for CompletableFuture, Optional, etc in Mockito
2 distribution.
Nevertheless Mockito has a mechanism to override class used to create
default return values for the whole project (see my old blog post [1]).
Using it you could implement your own Answer with CompletableFuture
support delegating other types to ReturnsMoreEmptyValues or
ReturnsSmartNulls.
In fact the idea has been in my head for some time and you motivated me
to do the initial implementation in mockito-java8 - see changes in the
defaultAnswers branch [2]. You can use the idea in your project or
create a PRs in mockito-java8 (WARNING. The implementation is definitely
a subject to change).
[1] -
https://solidsoft.wordpress.com/2012/07/02/beyond-the-mockito-refcard-part-1-a-better-error-message-on-npe-with-globally-configured-smartnull/
[2] -
https://github.com/szpak/mockito-java8/tree/feature/defaultAnswers
Alternatively, there is a new hope - Mockito 3 :) -
https://github.com/mockito/mockito/issues/297
Btw, Unfortunately I'm not sure what you would like to achieve in the
second case with "a list of futures".
* - runtime class detection and reflection to instantiate it makes code
less readable and more error prone
Marcin
--
http://blog.solidsoft.info/ - Working code is not enough