PowerMock和Java 8问题:InterfaceMethodrefInfo无法强制转换为MethodrefInfo [英] PowerMock and Java 8 issue: InterfaceMethodrefInfo cannot be cast to MethodrefInfo

查看:801
本文介绍了PowerMock和Java 8问题:InterfaceMethodrefInfo无法强制转换为MethodrefInfo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用PowerMock和Mockito执行单元测试时遇到了问题。我需要PowerMockito来模拟静态方法。

I´m having issues while trying to execute a unit test using PowerMock with Mockito. I need PowerMockito to mock an static method.

这些是我使用的版本:

PowerMock 1.6.2
Mockito 1.10.19
JUnit 4.12
Java 8

当我添加注释@PrepareForTest(Graph.class)时,我收到以下错误:

When I add the annotation @PrepareForTest(Graph.class) I get the following error:

java.lang.IllegalStateException: Failed to transform class with name     name.of.my.package.GraphUtil. Reason: javassist.bytecode.InterfaceMethodrefInfo cannot be cast to javassist.bytecode.MethodrefInfo

我已阅读过这是与javassist相关的官方PowerMock Google页面。但我有点失落,我不知道如何解决它。

I have read in the official PowerMock Google page that this is related to javassist. But I´m a bit lost and I don´t know how to fix it.

为了以防万一,我也尝试下载最新的Powermock SNAPSHOT(1.6.3-SNAPSHOT),但也没有用。

Just in case, I also tried downloading the latest SNAPSHOT of Powermock (1.6.3-SNAPSHOT) but did not work either.

有人可以帮助我吗?

提前致谢

推荐答案

是的,这就是问题所在。 PowerMock依赖于javassist,因此我只需在我的pom中排除该传递依赖,然后将依赖包含在javassist的固定版本中。这对我有用。谢谢!

Yes, that was the problem. PowerMock has a dependency to javassist, so I just had to exclude that transitive dependency in my pom and later include the dependency to the fixed version of javassist. And that worked for me. Thanks!

这篇关于PowerMock和Java 8问题:InterfaceMethodrefInfo无法强制转换为MethodrefInfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆