title: How to use expectNew for constructor with generic parameter?
body: <p>I need to inject a mock object into a method where a new <code>MyClass</code> object is instantiated.</p>
  
  <pre><code>private MyClass&lt;?&gt; c;
  
  public void myMethod(final String s) {
  
     c = new MyClass&lt;&gt;(s);
  
     c.callToMock();
  }
  </code></pre>
  
  <p>And the class I'm mocking has a constructor with a generic parameter.</p>
  
  <pre><code>public class MyClass&lt;T&gt; {
  
     public MyClass(final T t) {
        // do whatever
     }
  }
  </code></pre>
  
  <p>Now, in my test, I've created a mock for the class.
  When <code>new</code> is called, it should inject that mock.</p>
  
  <pre><code>@RunWith (PowerMockRunner.class)
  public class TestClass {
  
     @SuppressWarnings ("unchecked")
     public void myMethodTest() throws Exception {
  
        MyClass&lt;String&gt; myMock = (MyClass&lt;String&gt;) EasyMock.createMock(MyClass.class);
  
        PowerMock.expectNew(MyClass.class, "my argument")
                 .andReturn(myMock);
        myMock.callToMock();
        EasyMock.expectLastCall().once();
  
        EasyMock.replay(myMock);
        PowerMock.replayAll();
  
        ...
  
     }
  </code></pre>
  
  <p>When I run the test, it doesn't catch the <code>new</code> call and just instantiates an actual <code>MyClass</code> object.
  I don't know if it's not able to match the constructor or what.</p>
  
  <p>Any help would be appreciated, thanks.</p>