title: Mock a constructor with parameter
body: <p>I have a class as below:</p>
  
  <pre><code>public class A {
      public A(String test) {
          bla bla bla
      }
  
      public String check() {
          bla bla bla
      }
  }
  </code></pre>
  
  <p>The logic in the constructor <code>A(String test)</code> and <code>check()</code> are the things I am trying to mock. I want any calls like: <code>new A($$$any string$$$).check()</code> returns a dummy string <code>"test"</code>.</p>
  
  <p>I tried:</p>
  
  <pre><code> A a = mock(A.class); 
   when(a.check()).thenReturn("test");
  
   String test = a.check(); // to this point, everything works. test shows as "tests"
  
   whenNew(A.class).withArguments(Matchers.anyString()).thenReturn(rk);
   // also tried:
   //whenNew(A.class).withParameterTypes(String.class).withArguments(Matchers.anyString()).thenReturn(rk);
  
   new A("random string").check();  // this doesn't work
  </code></pre>
  
  <p>But it doesn't seem to be working. <code>new A($$$any string$$$).check()</code> is still going through the constructor logic instead of fetch the mocked object of <code>A</code>.</p>