【问题标题】:Mock class in a signed Jar file with Mockito使用 Mockito 在签名的 Jar 文件中模拟类
【发布时间】:2012-06-14 21:15:16
【问题描述】:

我正在尝试从已签名的 Jar 文件中部分模拟一个类(实际上,目标类在 Eclipse API 中)。

有没有办法用 Mockito 做到这一点?我尝试了几种解决方法,但结果总是这样:

org.mockito.cglib.core.CodeGenerationException: 
    java.lang.reflect.InvocationTargetException-->null
  ...
Caused by: java.lang.reflect.InvocationTargetException
  ...
Caused by: java.lang.SecurityException:
    class "org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate$$
           FastClassByMockitoWithCGLIB$$6e308a80"'s
    signer information does not match signer information of other classes
    in the same package
    ...

一点谷歌搜索告诉我PowerMock might help me,但我想避免为我的项目引入新的依赖项。

提前致谢!

【问题讨论】:

    标签: testing mocking eclipse-rcp mockito


    【解决方案1】:

    我相信 CGLIB 已经过调整以支持签名包,但可能存在一些问题。 你能做一个简单的项目,演示问题并在 mockito 项目上打开一个问题吗?

    您是否在 OSGI 中运行模拟?

    布莱斯

    【讨论】:

    • 感谢您的努力,布莱斯。基本上我正在开发一个 Eclipse 插件并做了这样的事情:val delegate = spy(new MySimpleLaunchDelegate); doReturn(Array("a", "b")).when(delegate).getClasspath(config)。将尝试通过一个最小的示例重现该问题。
    • 好的,谢谢。我不熟悉签名的罐子。但是你能检查 AbstractJavaLaunchConfigurationDelegate 的 ProtectionDomain 的值和 mock 的类吗?最终这个讨论可以继续关于 Mockito 问题:)
    • 我尝试使用多种方法(甚至混合 Scala/Java 代码)重现该问题,但我无法做到。这一定是我这边的配置问题。所有的 Mockito 版本都运行良好,即使是我最初使用的旧版本(1.8.5)。很抱歉误报。
    • @rlegendi 好的,然后开心地嘲笑 ;)
    猜你喜欢
    • 2011-09-17
    • 1970-01-01
    • 1970-01-01
    • 2020-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-07
    • 1970-01-01
    相关资源
    最近更新 更多