title: Mocking member variables of a class using Mockito
body: <p>I am a newbie to development and to unit tests in particular . 
  I guess my requirement is pretty simple, but  I am keen to know others thoughts on this. </p>
  
  <p>Suppose I have two classes like so - </p>
  
  <pre><code>public class First {
  
      Second second ;
  
      public First(){
          second = new Second();
      }
  
      public String doSecond(){
          return second.doSecond();
      }
  }
  
  class Second {
  
      public String doSecond(){
          return "Do Something";
      }
  }
  </code></pre>
  
  <p>Let's say I am writing unit test to test <code>First.doSecond()</code> method. However, suppose, i want to Mock <code>Second.doSecond()</code> class like so.  I am using Mockito to do this. </p>
  
  <pre><code>public void testFirst(){
      Second sec = mock(Second.class);
      when(sec.doSecond()).thenReturn("Stubbed Second");
  
      First first = new First();
      assertEquals("Stubbed Second", first.doSecond());
  }
  </code></pre>
  
  <p>I am seeing that the mocking does not take effect and the assertion fails. 
  Is there no way to mock the member variables of a class that I want to test . ? </p>