PowerMock and Java 8 issue: InterfaceMethodrefInfo cannot be cast to MethodrefInfo

前端 未结 4 1626
长情又很酷
长情又很酷 2021-01-04 01:15

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

These are the versions I´m using:

相关标签:
4条回答
  • 2021-01-04 01:41

    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!

    0 讨论(0)
  • 2021-01-04 01:42
        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.22.0-GA</version>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.javassist</groupId>
                    <artifactId>javassist</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    
    0 讨论(0)
  • 2021-01-04 01:42

    A Red Herring?

    When I ran into this issue during Android development, I was a single test to an existing file.

    Removing the test and re-adding one line at a time, I found that the underlying issue had to do with how TreeSet and its comparator were being instantiated.

    YMMV.

    0 讨论(0)
  • 2021-01-04 02:00

    Following Francisco González's answer, this is what I had to do :

    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-module-junit4</artifactId>
        <version>1.5.5</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.javassist</groupId>
                    <artifactId>javassist</artifactId>
            </exclusion>
        </exclusions>      
    </dependency>
    <dependency>
        <groupId>org.javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.20.0-GA</version>
        <scope>test</scope>
    </dependency>
    
    0 讨论(0)
提交回复
热议问题