title: Mockito: using a method in "thenReturn" to return a mock doesn't work
body: <p>I have encountered what I assume might be a bug with Mockito, but was wondering if anyone else can shed light as to why this test doesn't work. </p>
  
  <p>Basically, I have two objects, like this:</p>
  
  <pre><code>public class FirstObject {
      private SecondObject secondObject;
      public SecondObject getSecondObject() { return secondObject; }
  }
  
  public class SecondObject {
      private String name;
      public String getName() { return name; }
  }
  </code></pre>
  
  <p>The first object is mocked via annotation and the before method:</p>
  
  <pre><code>@Mock
  FirstObject mockedFirstObject;
  
  @Before
  public void setup() {
      MockitoAnnotations.initMocks(this);
  }
  </code></pre>
  
  <p>The second object is mocked in a method:</p>
  
  <pre><code>public SecondObject setupMockedSecondObject() {
      SecondObject secondObject = Mockito.mock(SecondObject.class);
      Mockito.when(secondObject.getName()).thenReturn("MockObject");
      return secondObject;
  }
  </code></pre>
  
  <p>When <code>thenReturn</code> contains a direct call to this method to setup and obtain a mock of the second object, it fails:</p>
  
  <pre><code>@Test
  public void notWorkingTest() {
      Mockito.when(mockedFirstObject.getSecondObject()).thenReturn(setupMockedSecondObject());
      Assert.assertEquals(mockedFirstObject.getSecondObject().getName(), "MockObject");
  }
  </code></pre>
  
  <p>But, when the mock returned by the same method is assigned to a local variable, which is used in <code>thenReturn</code>, it works:</p>
  
  <pre><code>@Test
  public void workingTest() {
      SecondObject mockedSecondObject = setupMockedSecondObject();
      Mockito.when(mockedFirstObject.getSecondObject()).thenReturn(mockedSecondObject);
      Assert.assertEquals(mockedFirstObject.getSecondObject().getName(), "MockObject");
  }
  </code></pre>
  
  <p>Are we doing something wrong or is this indeed a bug/limitation in Mockito? Is there a deliberate reason for this not working?</p>