我有一个带有多个插件的 Eclipse RCP 项目。我正在编写普通的 JUnit 测试(不依赖于 Eclipse/UI)作为被测插件的单独片段。
当使用 Mockito 并尝试从另一个插件(正确导出;我可以在我的代码中使用该接口)模拟接口时,我得到一个与类签名相关的 SecurityException:
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: interface ch.sbb.polar.client.communication.inf.service.IUserService
Mockito can only mock visible & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl$1.withBefores(JUnit45AndHigherRunnerImpl.java:27)
[...]
Caused by: org.mockito.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:238)
[...]
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[...]
Caused by: java.lang.SecurityException: Signers of 'ch.sbb.polar.client.communication.inf.service.IUserService$$EnhancerByMockitoWithCGLIB$$a8bfe723' do not match signers of other classes in package
at java.lang.ClassLoader.checkPackageSigners(ClassLoader.java:361)
at java.lang.ClassLoader.defineClass(ClassLoader.java:295)
... 40 more
当我将测试作为“JUnit 插件测试”运行时,即使用 OSGi 环境,一切都按预期工作。但由于速度的原因,我想使用普通的 JUnit 执行;在被测类中,我不需要 OSGi 环境。
有人知道这样做的方法吗?