title: Mockito Mock method parameter of type Future<T>
body: <p>I have the below code:</p>
  
  <pre><code>public final class JoinableTaskPool&lt;T&gt; extends ABC {
  
         public Future&lt;T&gt; submit(final Callable&lt;T&gt; task) {
             executorService.submit(new Runnable() {
               public void run() {
                  try {
                      final Future&lt;T&gt; result = service.take();
                      try {
                          handler.processResult(result);
                      } catch (final Throwable t) {
                          throw new SearchException("Task has an error", t);
                      }
                  } catch (InterruptedException e) {
                      throw new SearchException("Task has an error", e);
                  }
              }
            } 
         }
    }
  </code></pre>
  
  <p>I am trying to write a unit test for this method. Below is the method:</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  public class TestJoinableTaskPool&lt;T&gt; {
  
      private JoinableTaskPool&lt;T&gt; pool;
  
      @Before
      public void setUp() {
          pool = new JoinableTaskPool&lt;T&gt;(1);
      }
  
      @After
      public void tearDown() {
          pool.shutdown();
      }
  
      @Test
      public void testSubmit() throws Exception{
          Callable task = (Callable&lt;T&gt;) () -&gt; null;
          Future&lt;T&gt; result = new FutureTask&lt;T&gt;(task);
          Mockito.when(pool.getCompService().take())
                  .thenReturn(result);
  
          Mockito.when(pool.getFinishHandler().processResult(result))
                  .thenThrow(RuntimeException.class);
  
          pool.submit(task);
      }
  }
  </code></pre>
  
  <p>I am getting compilation error at below line saying:</p>
  
  <blockquote>
    <p><code>reason: no instance(s) of type variable(s) T exist so that void conforms to T</code></p>
  </blockquote>
  
  <pre><code>Mockito.when(pool.getFinishHandler().processResult(result))
                  .thenThrow(RuntimeException.class);
  </code></pre>
  
  <p>How do we get around this? I have tried replacing <code>T</code> as <code>String</code> or any other class, but issue still exists. Passing <code>any()</code> as parameter to <code>processResult</code> does now work as well and I want that method call to throw an exception which assert on.</p>
  
  <p>Any help would be appreciated.</p>