TechGoose
TechGoose

Reputation: 29

Power Mock and Mockito Version Incompatible

I'm working on a legacy code base using JDK 1.8. For one of my unit tests, I want to use PowerMock so that I can call the PowerMock.mockStatic() method on a static method (Provider.provider()) from the the javax.xml.ws.spi package. However, as soon as I added the powermock-api-mockito2 dependency into my pom.xml, I got the following error when trying to execute my unit tests. java.lang.NoSuchMethodError: org.mockito.Mockito.framework()Lorg/mockito/MockitoFramework;

So far, this is the first instance in the unit tests where there's a need for Power Mock and the rest of the tests have already been written using mockito-all. These are the dependencies from my pom.xml

Is there a version of mockito-all I can upgrade to resolve this dependency issue, or is there an older version of powermock-api-mockito2 I could use? I would greatly appreciate any help or feedback on this. Thank you.

<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-all</artifactId>
    <version>1.10.19</version>
    <scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.powermock/powermock-module-testng -->
<dependency>
    <groupId>org.powermock</groupId>
    <artifactId>powermock-module-testng</artifactId>
    <version>2.0.9</version>
    <scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.powermock/powermock-module-junit4 -->
<dependency>
    <groupId>org.powermock</groupId>
    <artifactId>powermock-module-junit4</artifactId>
    <version>2.0.9</version>
    <scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito2 -->
<dependency>
    <groupId>org.powermock</groupId>
    <artifactId>powermock-api-mockito2</artifactId>
    <version>2.0.9</version>
    <scope>test</scope>
</dependency>

Upvotes: 0

Views: 565

Answers (1)

TechGoose
TechGoose

Reputation: 29

As an update. I was able to get this to work by replacing mockito-all with mockito-inline. This didn't affect any of my old tests. mockito-inline dropped jdk 1.8 support after version 5. However, version 4 has static mock methods and still supports JDK 1.8.

Upvotes: 0

Related Questions