title: How to mock completablefuture.get()?
body: <p>This is the method I'm trying to mock:</p>
  <pre><code>@VisibleForTesting
  public List&lt;Row&gt; processRows2(CompletableFuture future) {
      List&lt;Row&gt; rows2 = new ArrayList&lt;&gt;();
      try {
          DefaultAsyncResultSet beep = (DefaultAsyncResultSet) future.get();
          for (Row b : beep.currentPage()) {
              rows2.add(b);
          }
      }
      catch (ExecutionException | InterruptedException e) {
          LOGGER.error(e);
          LOGGER.error(e.getStackTrace());
          throw new RuntimeException(e.getMessage() + &quot; - Check thread pool resources are enough, may be too many queries in queue&quot;);
      }
      return rows2;
  }
  </code></pre>
  <p>The problem is that when I try to test it with this (currently just trying to get it to run all the way to either success or failure):</p>
  <pre><code>@Test
  public void processRows2test() {
      FeatureDaoImpl gar = new FeatureDaoImpl(connection);
      CompletableFuture L = new CompletableFuture();
      gar.processRows2(L);
  }
  </code></pre>
  <p>It hangs endlessly. My guess is that the future.get() is where it's hanging; I'm not sure. But I'm not sure how to mock that. I've tried this:</p>
  <pre><code>@Mock
  private CompletableFuture mockFutures;
  
  @Before
      public void setUp() {
          try {
              Mockito.when(mockFutures.get()).thenReturn((AsyncResultSet) mockResultSetFuture);
          }
          catch (Exception e) {
          }
      }
  </code></pre>
  <p>But this I feel is not correct. The try catch is because it yells at me about unhandled exceptions on the get(), so I don't know how to get around that.</p>
  <p>I have also now tried this:</p>
  <pre><code>@Mock
  final CompletableFuture&lt;List&lt;String&gt;&gt; mockedFuture = Mockito.mock(CompletableFuture.class);
  </code></pre>
  <p>With the following in the setup:</p>
  <pre><code>    Mockito.doReturn(new ArrayList&lt;Row&gt;()).when(mockedFuture).get();
  </code></pre>
  <p>But it still hangs endlessly.</p>
  <p>I've seen these:</p>
  <p><a href="https://stackoverflow.com/questions/53021545/how-to-mock-completion-of-a-completablefuture-in-mockito">How to mock completion of a CompletableFuture in Mockito</a>
  This one I don't understand what exactly it's trying to get me to do, and doesn't feel super applicable, because it's not a get method. I saw some examples here that have .get() in them... but none were mocked methods unfortunately, they were gets in the test itself: <a href="https://www.javatips.net/api/java.util.concurrent.completablefuture" rel="nofollow noreferrer">https://www.javatips.net/api/java.util.concurrent.completablefuture</a></p>
  <p>EDIT: the code runs. It returns results. So it isn't that the actual method isn't returning a value - I know it does this, it's doing it in QA right now.</p>