我一直在尝试创建一个模拟
oracle.adf.share.security.identitymanagement.UserProfile
例如
@Test
public void testMyTest(@Mocked final UserProfile userProfile) {
new Expectations() {
{
userProfile.getBusinessEmail();
result = "me@me.com";
}
};
unitUnderTest.methodUnderTest();
}
然而,我发现当JMockit试图构造mock时,会抛出异常
java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at oracle.jdevimpl.junit.runner.junit4.JUnit4Testable.run(JUnit4Testable.java:24)
at oracle.jdevimpl.junit.runner.TestExecution.run(TestExecution.java:27)
at oracle.jdevimpl.junit.runner.JUnitTestRunner.main(JUnitTestRunner.java:88)
Caused by: oracle.adf.share.security.ADFSecurityRuntimeException: EXC_FAILED_ID_STORE
at oracle.adf.share.security.identitymanagement.UserManager.<init>(UserManager.java:111)
at oracle.adf.share.security.identitymanagement.UserManager.<init>(UserManager.java:83)
at oracle.adf.share.security.identitymanagement.UserProfile.<clinit>(UserProfile.java:62)
反编译后
UserProfile
我看出来有点像这样
public class UserProfile implements Serializable {
...
private static UserManager _usrMgr = new UserManager();
...
}
这个
UserManager
构造函数如下所示
public UserManager() {
this((String) null);
}
public UserManager(String providerClassName) {
if (providerClassName != null) {
...
} else {
String clzName = ADFSecurityUtil.getIdentityManagementProviderClassName();
if (clzName != null) {
IdentityManagement provider = (IdentityManagement) createObject(clzName);
setIdentityManagementProvider(provider);
} else {
throw new ADFSecurityRuntimeException("EXC_FAILED_ID_STORE");
}
}
}
现在,我可以设置一个Expectation,当
ADFSecurityUtil.getIdentityManagementProviderClassName();
被调用,但当它尝试加载该类时,我预见到了进一步的问题。
解决这个问题的最佳方法是什么?