mock System class with powermock
- Use the
@RunWith(PowerMockRunner.class)annotation at the class-level of the test case. - Use the
@PrepareForTest({ClassThatCallsTheSystemClass.class})annotation at the class-level of the test case. - Use
mockStatic(SystemClass.class)to mock the system class then setup the expectations as normally. - EasyMock only: Use
PowerMock.replayAll()to change to replay mode. - EasyMock only: Use
PowerMock.verifyAll()to change to verify mode.