Hot Posts

PowerMock and Java8 Streams

Java 8 Streams

Recently I was writing some units tests, as all good developers should, and ran into an issue with a test that made use of the IntStream of(int t) method. The test execution failed and throw the following exception:

java.lang.IllegalStateException: Failed to transform class with name com.readlearncode.ServiceTest. Reason: javassist.bytecode.InterfaceMethodrefInfo cannot be cast to javassist.bytecode.MethodrefInfo

After googling for the solution I found that others had had the same issue. A StackOverflow question and answer gave me the solution. As this is issue could cause someone quite a lot of pain I thought I would reproduce it below:

Answer

PowerMock has a dependency on javassist, exclude the transitive dependency in my POM and include the dependency separately.

Here is the POM snippet:

<dependency>
    <groupId>org.powermock</groupId>
    <artifactId>powermock-module-junit4</artifactId>
    <version>1.6.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>

 

 

 

 

 

About Alex (67 Articles)
Enterprise Developer. Passionate about the Java EE eco-system, Java 8 and microservices. Author, trainer, conference speaker and blogger. Oracle certified.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: