title: CompletableFuture usability and unit test
body: <p>I'm learning about java 8 <code>CompletableFuture</code> and ended up with this.</p>
  
  <p>Fist of all, what do you think about this lines of code? I need to send request to different services in parallel and then wait for all of them to response and continue working.</p>
  
  <pre><code>//service A
  CompletableFuture&lt;ServiceAResponse&gt; serviceAFuture = CompletableFuture.supplyAsync(
      () -&gt; this.ServiceA.retrieve(serviceARequest), serviceAExecutorService
  );
  
  //service B
  CompletableFuture&lt;ServiceBResponse&gt; serviceBFuture = CompletableFuture.supplyAsync(
      () -&gt; this.ServiceB.retrieve(serviceBRequest), serviceBExecutorService
  );
  
  CompletableFuture.allOf(serviceAFuture, serviceBFuture).join();
  ServiceAResponse responseA = serviceAFuture.join();
  ServiceBResponse responseB = serviceBFuture.join();
  </code></pre>
  
  <p>And even the code is doing what I want, I'm having problems testing the class where that code is. I tried using Mockito and do something like:</p>
  
  <pre><code>doAnswer(invocation -&gt; CompletableFuture.completedFuture(this.serviceAResponse))
      .when(this.serviceAExecutorService)
      .execute(any());
  </code></pre>
  
  <p>Where executor services and services responses are mocking but the test never ends and the thread keeps waiting for something in this line</p>
  
  <pre><code>CompletableFuture.allOf(serviceAFuture, serviceBFuture).join();
  </code></pre>
  
  <p>Any hint on what I'm missing here? Thank you!</p>