title: Testing util class with method dependency
body: <p>I have a utility class that I need to do some unit testing, but within this utility class I have methods that depend on others in that same utility class.</p>
  
  <p>For that I'm using the following dependencies:</p>
  
  <ul>
  <li>jUnit:4.12</li>
  <li>Mockito: 2.8</li>
  <li>Powermock: 1.7</li>
  </ul>
  
  <p>As it's already evident that I am using Java to perform my code.</p>
  
  <p>Now go to the example code:</p>
  
  <pre><code>public final class AppUtils {
  
      private AppUtils () {
          throw new UnsupportedOperationException("This class is not instantiable.");
      }
  
      public static int plus(int a, int b) {
          return a + b;
      }
  
      public static float average(int a, int b) {
          return ((float) AppUtils.plus(a, b)) / 2;
      }
  }
  </code></pre>
  
  <p>And the unit test:</p>
  
  <pre><code>@RunWith(PowerMockRunner.class)
  @PrepareForTest({AppUtils.class})
  public class AppUtilsTest {
  
      @Test
      public void testPlus() { //This test must be good.
          assertEquals(6, AppUtils.plus(4, 2));
      }
  
      @Test
      public void testAverage() {
          PowerMockito.mockStatic(AppUtils.classs);
          when(AppUtils.plus(anyInt())).thenReturn(6);
          assertEquals(3f, AppUtils.average(4, 3), 1e-2d);
      }
  
  }
  </code></pre>
  
  <p>That way I did my unit test, but this throws me an error because it tells me that the expected result does not correspond to the actual one.</p>
  
  <pre><code>expected: 3.000f
  actual: 0
  </code></pre>
  
  <p>This is because <code>PowerMock</code> by using the <code>mockStatic()</code> method replaces all static implementations for your defines, but if you do not define the result of one static method then it returns 0.</p>
  
  <p>If anyone can help me, I thank you.</p>