PowerMock和Java 8问题:InterfaceMethodrefInfo无法强制转换为MethodrefInfo

编程入门 行业动态 更新时间:2024-10-18 14:13:37
本文介绍了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

本文发布于:2023-10-31 04:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545021.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   Java   PowerMock   MethodrefInfo   InterfaceMethodrefInfo

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!