title: Mocking non-public static methods in abstract classes with JMockit?
body: <p>I have the following class:</p>
  
  <pre><code>public abstract class AbstractParent {
      static String method() {
          return "OriginalOutput";
      }
  }
  </code></pre>
  
  <p>I want to mock this method. I decide to use <a href="http://jmockit.dev.java.net" rel="noreferrer">JMockit</a>. So I create a mock class:</p>
  
  <pre><code>public class MockParent {
      static String method() {
          return "MOCK";
      }
  }
  </code></pre>
  
  <p>And my test code looks like this:</p>
  
  <pre><code>public class RealParentTest {
  
      @Before
      public void setUp() throws Exception {
          Mockit.redefineMethods( AbstractParent.class, MockParent.class );
      }
  
  
      @Test
      public void testMethod() {
          assertEquals(MockParent.method(),AbstractParent.method());
      }
  
  }
  </code></pre>
  
  <p>Unfortunately this test says that AbstractParent returns "OriginalOutput" instead of "MOCK". Any ideas why? Am I doing something wrong? I've tried declaring my mock class as abstract as well, to no avail.</p>
  
  <p><strong>Edit</strong> Note that making the method public causes the test to run without a problem... this is weird because with JMockit you are supposed to be able to mock methods of any scope.</p>
  
  <p><strong>Answer</strong> Only the mock method needs to be public, you can leave the original method as is.</p>