title: How to mock call on an attribute of class?
body: <p>I am trying to test the following class</p>
  <pre><code>public class MyClass {
      protected OtherClass other;
      public MyClass(String arg) {
          this.other = new OtherClass(arg);
      }
  
      public void doSomething() {
          String response = other.sendRequest(); // mock this call
          // ...
      }
  }
  </code></pre>
  <p>I want to test <code>doSomething()</code> and for this I need to mock the call <code>sendRequest()</code>. For this I tried the following, which did not work:</p>
  <pre><code>@Test
  public void doSomethingTest() {
      MyClass myClass = new MyClass(&quot;test&quot;);
      when(myClass.other.sendRequest()).thenReturn(&quot;response&quot;);
      myClass.doSomething();
  }
  </code></pre>
  <p>The real <code>sendRequest()</code> is still being called instead of returning the mock response.</p>
  <p>How can I mock the call to <code>sendRequest()</code> with Mockito?</p>