title: How to mock classes with constructor injection
body: <p>How to get constructor injection in <a href="https://site.mockito.org/" rel="noreferrer">Mockito</a></p>
  <p>I have the following class:</p>
  <pre><code>class A {
  
    private B mB;
  
    A(B b) {
       mB = b;
    }
  
   void String someMethod() {
       mB.execute();
    }
  }
  </code></pre>
  <p>how do I test <code>someMethod</code> using a mock class <code>A</code> and class <code>B</code> using</p>
  <pre><code>B b = Mockito.mock(B.class)
  Mockito.when(b.execute()).thenReturn(&quot;String&quot;)
  
  A a = Mockito.mock(A.class)
  //somehow inject b into A and make the below statement run
  Mockito.when(a.someMethod()).check(equals(&quot;String&quot;))
     
  </code></pre>