title: Java Unit tests using Mockito. Function call within a function
body: <p>Suppose I have the following class : </p>
  
  <pre><code>public class Math {
  
      public int mult(int a, int b) {
          return 4;
      }
  
      public int mul (int a, int b) {
          return mult(a,b);   
      }
  
  }
  </code></pre>
  
  <p>And the following test class :</p>
  
  <pre><code>public class TestMockito {
  
      Math testMath;
  
      @Before
      public void create () {
          testMath = *mock*(Math.class);
          when(testMath.mult(1,2).thenReturn(2);
      }
  
      @Test
      public void test() {
          System.out.println(testMath.mul(1,2));
      }
  }
  </code></pre>
  
  <p>Why does <code>mul(1,2)</code> called in <code>test()</code> not use <code>when(testMath.mult(1,2).thenReturn(2);</code> ?</p>
  
  <p>Is there any other way to mock a method being used inside another method that is being tested ?</p>
  
  <p>Cheers</p>