title: PowerMock, mockito, verify static method
body: <p>I'm trying to get PowerMock to work with mockito, and I'm following the documentation here: <a href="http://code.google.com/p/powermock/wiki/MockitoUsage13" rel="noreferrer">http://code.google.com/p/powermock/wiki/MockitoUsage13</a>. </p>
  
  <p>To simplify a bit, lets say that I have a static method:</p>
  
  <pre><code>StaticObj.put(String key, String val) { ... }
  </code></pre>
  
  <p>And the class to be tested does something like this:</p>
  
  <pre><code>public class ClassToTest {
      public void doSomething(Params p) {
          if (StringUtils.isNotBlank(p.getK()) StaticObj.put("k1", p.getK());
          if (StringUtils.isNotBlank(p.getX()) StaticObj.put("x1", p.getX());
      }
  }
  </code></pre>
  
  <p>In my unit test I'd like to verify that StaticObj.put is called for K and X when they are not blank or null, so I do something like this:</p>
  
  <pre><code>public void testNormalCase() {
      // assume that mocking setup for statics already happened in some @Before function..
      Params params = new Params("k", "x");
      ClassToTest classToTest = new ClassToTest();
      classToTest.doSomething(params);
  
      // now I want to verify:
      PowerMockito.verifyStatic(times(1));
      StaticObj.put("k1", "k1");
  
      PowerMockito.verifyStatic(times(1));
      StaticObj.put("x1", "x");
  }
  </code></pre>
  
  <p>This works, and it's what I'd expect. What doesn't work, is if I comment out the verification for K, then the verification for X fails! The error message indicates that ("x1", "x") is expected but got ("k1", "k"). Why is this? Am I not coding this correctly?</p>
  
  <p>Also it leads me to believe that the following type of test, which passes, might pass for the wrong reason entirely:</p>
  
  <pre><code>public void testOtherCase() {
      // assume that mocking setup for statics already happened in some @Before function..
      Params params = new Params("k", null);
      ClassToTest classToTest = new ClassToTest();
      classToTest.doSomething();
  
      // now I want to verify:
  
      PowerMockito.verifyStatic(never());
      StaticObj.put(eq("x1"), anyString());
  }
  </code></pre>
  
  <p>E.g. I wonder if powermock sees "k1", decides that "x1" was never called, and passes. (?)</p>
  
  <p>To state it generally, I have a static method that is called N times (where N changes depending on the input params). And I want to verify that it was called in the correct cases (which can be determined by input params). It seems like powermock doesn't handle this well, unless I misunderstand.</p>
  
  <p>Thanks for any ideas!</p>