title: How to mock a generic parameter for a unit test in Java?
body: <p>I have a function signature I'd like to mock of an External Service.</p>
  
  <pre><code>public &lt;T&gt; void save(T item, AnotherClass anotherClassObject);
  </code></pre>
  
  <p>Given this function signature, and class name <code>IGenericService</code> how could one mock it with PowerMock? 
  Or Mockito? </p>
  
  <p>For this generic, I'm using: Class <code>Theodore</code> for the T in <code>T item</code>. For example, I tried using: </p>
  
  <pre><code>doNothing().when(iGenericServiceMock.save(any(Theodore.class),
                      any(AnotherClass.class));
  </code></pre>
  
  <p>IntelliJ cranks this: </p>
  
  <pre><code>save(T, AnotherClass) cannot be applied to 
  (org.Hamcrest.Matcher&lt;Theodore&gt;, org.Hamcrest.Matcher&lt;AnotherClass&gt;)
  </code></pre>
  
  <p>And it cites the following reason: </p>
  
  <pre><code>reason: No instance(s) of type variable T exist 
  so that Matcher&lt;T&gt; conforms to AnotherClass
  </code></pre>
  
  <p>First, the issue ought to solve if the generics argument is handled properly. What are some things one could do in such situations?</p>
  
  <p>UPDATE: As ETO shared: </p>
  
  <pre><code>doNothing().when(mockedObject).methodToMock(argMatcher); 
  </code></pre>
  
  <p>shares the same fate. </p>