PowerMock Static Spy
This post shows how to partially mock a class's static methods. Code Example See PowerMock Setup page to learn how to get started with PowerMock. UnderTest.java 1| package main; 2| 3| public class UnderTest { 4| public void foo() { 5| MockClass.foo(); 6| System.out.println("UnderTest!"); 7| MockClass.foo2(); 8| } 9| } MockClass.java 1 | package main; 2 | 4 | public class MockClass { 5 | public static void foo() { 6 | System.out.println("Mocked Method!"); 7 | } 9 | 10| public static void foo2() { 11| System.out.println("foo2!"); 12| } 13| } StaticSpyTest.java 1 | package test; 2 | import main.*; 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.powermock.api.mockito.PowerMockito; 6 | import org.powermock.core.classloader.annotations.PrepareForTest; 7 | import org.p...