title: How do I unit test a method that contains a CompletableFuture?
body: <p>I tried looking this up, but couldn't quite understand the examples I found. I have a class with a Spring <code>AfterPropertiesSet()</code> method that calls 2 other methods to spin off asynch calls. I'm at a loss how as to to unit test them. The method <code>startProcessingThread()</code> looks like this:</p>
  
  <pre><code>void startProcessingThread(executor) {
      CompletableFuture.runAsync(() -&gt; {
          Path filePath = null;       
          do {
              filePath = retrieveFromFileQueue();
              submitFileForProcessing(filePath);            
          } while (keepRunning);
      }, executor)
      .handle((theVoid, exception) -&gt; {           
          if (exception != null) {
              LOG.error("Error submitting file for processing: " + exception);            
          }
          return null;
      });
  }
  </code></pre>
  
  <p>I don't want to rewrite the <code>CompletableFuture</code> in the test method (do I?). So I figured I need to call <code>startProcessingThread()</code>, using Mocks (from Mockito) inside the methods that need them (<code>retrieveFromFileQueue()</code> and <code>submitFileForProcessing()</code>). But what about the <code>CompletableFuture</code> itself? Should I mock that? I'm sorry, but I'm really confused...</p>