title: How to mock a static method call on an object in a static method?
body: <p>I 'm a newie in Junit-testing but I have to test some code. I think now I know the basics of it, but I still got a problem on which I couldn't find anything on the Internet:</p>
  
  <p>Here's the class I want to test:</p>
  
  <pre><code>public static void methodToTest(Label l2, Label l3, User u) {
  
  
      int first = MyDB.someMethod(u.anotherMethod()).size();
      int second = MyDB.someOtherMethod(u).size();
  
  
      if (first == 1) {
          l2.setCaption("...");
      }
  
      ...
  }
  </code></pre>
  
  <p>I don't want the System to create the Integers 'first' and 'second'. Instead I just want them to be '1' so I can test if the last lines of code work properly.</p>
  
  <p>MyDB is a public class with static Methods (someMethod() and someOtherMethod())</p>
  
  <p>I want to test the Method methodToTest. I tried to call this method with parms and at the end compare the modified params to the expected ones.</p>
  
  <p>I use Mockito and PowerMockito.</p>
  
  <p>This is one of my tries:</p>
  
  <pre><code>@PrepareForTest({ClassToTest.class, MyDB.class })
  @RunWith(PowerMockRunner.class)
  public class Test extends PowerMockTestCase{
     PowerMockito.mockStatic(MyDB.class);
     PowerMockito.doReturn(1).when(MyDB.someMethod(u.anotherMethod()).size());
     PowerMockito.doReturn(1).when(MyDB.someOtherMethod(u).size());
     ClassToTest.methodToTest(l1, l2, u);
     assertTrue(l1.equals(l3) &amp;&amp; l2.equals(l4));
  }
  </code></pre>
  
  <p>The exception that I get is:
  'Argument passed to when() is not a mock!'</p>
  
  <p>I hope anyone can help me. I passed so many hours to solve this problem, without success.</p>
  
  <p>Thank you!!!</p>