title: How can I mock a private static method with PowerMockito?
body: <p><a href="https://stackoverflow.com/questions/25594090/how-can-i-mock-private-static-method-with-powermockito">This is the same question as found here.</a> Unfortunately, the accepted answer isn't working for me.  I have a static utility class with private methods that I need to test.  I find that when I mock methods like this:</p>
  
  <pre><code>PowerMockito.spy(StaticUtil.class);
  PowerMockito.when(StaticUtil.class, "getSomethingMethod", someObjectArray, someStringArray, aBoolean, someList).thenReturn(anotherList);
  </code></pre>
  
  <p>I'm getting a null pointer exception because the <code>getSomethingMethod()</code> is actually being called.  When I debug, I see that it isn't being called when I run the method I'm trying to test, but it is running when I am setting up the mock.  <a href="http://www.stevenschwenke.de/spyingWithMockito" rel="nofollow noreferrer">Based on this site,</a> it looks like that is what is supposed to happen when you create the mock in this format.</p>
  
  <p>So then I try to set up the mock this way:</p>
  
  <pre><code>PowerMockito.spy(StaticUtil.class);        
  PowerMockito.doReturn(anotherList).when(StaticUtil.getSomethingMethod( someObjectArray, someStringArray, aBoolean, someList);
  </code></pre>
  
  <p>However, I am get an error from Eclipse that says I need to change the visibility of <code>getSomethingMethod()</code> to public.  Isn't one of the big benefits of using PowerMockito that you can mock private methods?  I need to mock this <code>private static</code> method (without actually calling the method during setup).</p>