PS!您还可以模拟对getSecurityManager()方法的静态方法调用。
模拟静态方法请参见maunal,网址为http://pre.google.com/p/powermock/wiki/MockitoUsage
在类级别添加@PrepareForTest。
@PrepareForTest(System.class); // System.class contains static methods
调用PowerMockito.mockStatic()模拟一个静态类(使用PowerMockito.mockStaticPartial(class,method)模拟一个特定方法):
PowerMockito.mockStatic(System.class);
只需使用Mockito.when()来设置您的期望:
Mockito.when(System.getSecurityManager()).thenReturn(securityManagerMock);



