title: Stubbing a method that takes Class<T> as parameter with Mockito
body: <p>There is a generic method that takes a class as parameter and I have problems stubbing it with Mockito. The method looks like this:</p>
  
  <pre><code>public &lt;U extends Enum&lt;U&gt; &amp; Error, T extends ServiceResponse&lt;U&gt;&gt; T validate(
      Object target, Validator validator, Class&lt;T&gt; responseClass,
      Class&lt;U&gt; errorEnum);
  </code></pre>
  
  <p>It's god awful, at least to me... I could imagine living without it, but the rest of the code base happily uses it...</p>
  
  <p>I was going to, in my unit test, stub this method to return a new empty object. But how do I do this with mockito? I tried:</p>
  
  <pre><code>when(serviceValidatorStub.validate(
      any(), 
      isA(UserCommentRequestValidator.class), 
      UserCommentResponse.class, 
      UserCommentError.class)
  ).thenReturn(new UserCommentResponse());
  </code></pre>
  
  <p>but since I am mixing and matching matchers and raw values, I get "org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers!"</p>