title: Mocking Nested Objects with Mockito
body: <p>We have a class like this :<br />
  ( Please Note that I do not have the freedom to change the class definition )</p>
  <pre><code>class X {
    private B b ;
    public X( C c ) {
       b = new B(c ) ;
    }
  }
  </code></pre>
  <p>How will I write junit test for the above class using Mockito ?</p>
  <p>I tried :</p>
  <pre><code> class XTest {
          @Mock
          private C c ;
          @InjectMocks
         private X x ;
      ...
      }
  </code></pre>
  <p>..Mockito is injecting a mock C. However the line <strong>new B(c)</strong> is throwing an exception as B - which is not a mock -  is not prepared to work with a mock c</p>