title: PowerMockito mocking static method fails when calling method on parameter
body: <p>I'm trying to test a class which uses a calculator class with a number of static methods.  I've successfully mocked another class in a similar way, but this one is proving more stubborn.</p>
  
  <p>It seems that if the mocked method contains a method call on one of the passed in arguments the static method is not mocked (and the test breaks).  Removing the internal call is clearly not an option.  Is there something obvious I'm missing here?</p>
  
  <p>Here's a condensed version which behaves the same way...</p>
  
  <pre><code>public class SmallCalculator {
  
      public static int getLength(String string){
  
          int length = 0;
  
          //length = string.length(); // Uncomment this line and the mocking no longer works... 
  
          return length;
      }
  }
  </code></pre>
  
  <p>And here's the test...</p>
  
  <pre><code>import static org.junit.Assert.assertEquals;
  import static org.mockito.BDDMockito.given;
  import static org.mockito.Matchers.any;
  
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.powermock.api.mockito.PowerMockito;
  import org.powermock.core.classloader.annotations.PrepareForTest;
  import org.powermock.modules.junit4.PowerMockRunner;
  
  import com.solveit.aps.transport.model.impl.SmallCalculator;
  
  @RunWith(PowerMockRunner.class)
  @PrepareForTest({ SmallCalculator.class})
  public class SmallTester {
  
      @Test
      public void smallTest(){
  
          PowerMockito.spy(SmallCalculator.class);
          given(SmallCalculator.getLength(any(String.class))).willReturn(5);
  
          assertEquals(5, SmallCalculator.getLength(""));
      }
  }
  </code></pre>
  
  <p>It seems there's some confusion about the question, so I've contrived a more 'realistic' example.  This one adds a level of indirection, so that it doesn't appear that I'm testing the mocked method directly.  The SmallCalculator class is unchanged:</p>
  
  <pre><code>public class BigCalculator {
  
      public int getLength(){
  
          int length  = SmallCalculator.getLength("random string");
  
          // ... other logic
  
          return length;
      }
  
      public static void main(String... args){
  
          new BigCalculator();
      }
  }
  </code></pre>
  
  <p>And here's the new test class...</p>
  
  <pre><code>import static org.junit.Assert.assertEquals;
  import static org.mockito.BDDMockito.given;
  import static org.mockito.Matchers.any;
  
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.powermock.api.mockito.PowerMockito;
  import org.powermock.core.classloader.annotations.PrepareForTest;
  import org.powermock.modules.junit4.PowerMockRunner;
  
  import com.solveit.aps.transport.model.impl.BigCalculator;
  import com.solveit.aps.transport.model.impl.SmallCalculator;
  
  @RunWith(PowerMockRunner.class)
  @PrepareForTest({ SmallCalculator.class})
  public class BigTester {
  
      @Test
      public void bigTest(){
  
          PowerMockito.spy(SmallCalculator.class);
          given(SmallCalculator.getLength(any(String.class))).willReturn(5);
  
          BigCalculator bigCalculator = new BigCalculator();
          assertEquals(5, bigCalculator.getLength());
      }
  }
  </code></pre>