PowerMock & Java 11

Viewed 27508

We are using PowerMock in few of our historical projects. Unfortunately PowerMock is quite dead and is not compatible with Java 11.

And we are using mockStatic(). Yes, we know its considered harmful - its in the legacy code and we would prefer not to rewrite those classes now...

Are there any options how to tweak PowerMock to support Java 11? Or is it possible to easily replace it with some other Java 11 compatible framework? (Mockito does not support mockStatic)

5 Answers

After one year of no releases, things are really moving in PowerMock.

PowerMock 2.0.0-RC1 was released. And with PowerMockito 2.0.0-RC1 + @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "org.w3c.*"})

The tests work under Java 11.

Resolved with:

@PowerMockIgnore("jdk.internal.reflect.*")

Nothing else needed.

add the properties: org/powermock/extensions/configuration.properties

https://github.com/powermock/powermock/wiki/PowerMock-Configuration https://github.com/powermock/powermock-examples-maven/blob/master/global-ignore/src/test/resources/org/powermock/extensions/configuration.properties

e.g. for maven/gradle: src/test/resources/org/powermock/extensions/configuration.properties

powermock.global-ignore=javax.crypto.*,com.sun.xml.internal.stream.*,javax.xml.stream.*,javax.net.ssl.*,org.slf4j.*,javax.xml.parsers.*,ch.qos.logback.*,jdk.xml.internal.*,com.sun.org.apache.xerces.*,java.xml.*,org.xml.*,javax.management.*,org.w3c.dom.*

If there are a lot of test classes to migrate to Java 11, it is possible to configure the ignores globally (only once in a configuration file): org/powermock/exntensions/configuration.properties

powermock.global-ignore=com.sun.org.apache.xerces.*,javax.xml.*,org.xml.*,org.w3c.*
Related