powermock

wiki: https://code.google.com/p/powermock/w/list

Demo:

@RunWith(PowerMockRunner.class)
@PrepareForTest( { SystemClassUser.class })
public class SystemClassUserTest {

    @Test
    public void assertThatMockingOfNonFinalSystemClassesWorks() throws Exception {
        mockStatic(URLEncoder.class);

        expect(URLEncoder.encode("string", "enc")).andReturn("something");
        replayAll();

        assertEquals("something", new SystemClassUser().performEncode());

        verifyAll();
    }
}


你可能感兴趣的:(Test,powermock,mock,java,test,junit)