openrewrite / rewrite-testing-frameworks

OpenRewrite recipes that perform common Java testing migration tasks.
Apache License 2.0
68 stars 58 forks source link

JUnit4to5Migration uses old mockito-junit-jupiter version #541

Open Saturas89 opened 3 days ago

Saturas89 commented 3 days ago

The added dependency from mockito-junit-jupiter could be upgraded to a newer one.

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a single module project.

<plugin>
  <groupId>org.openrewrite.maven</groupId>
  <artifactId>rewrite-maven-plugin</artifactId>
  <version>5.34.1</version>
  <configuration>
   <activeRecipes>
       <recipe>org.openrewrite.java.testing.junit5.JUnit4to5Migration</recipe>
    </activeRecipes>
   </configuration>
         <dependencies>
          <dependency>
           <groupId>org.openrewrite.recipe</groupId>
           <artifactId>rewrite-testing-frameworks</artifactId>
            <version>2.12.2</version>
           </dependency>
          </dependencies>
</plugin>

What did you expect to see?

      <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>5.12.0</version>
            <scope>test</scope>
        </dependency>

What did you see instead?

      <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>3.12.4</version>
            <scope>test</scope>
        </dependency>
timtebeek commented 3 days ago

Hi! Thanks for the report; looks like we indeed bump to 3.x in two locations:

Once as part of org.openrewrite.java.testing.junit5.JUnit4to5Migration https://github.com/openrewrite/rewrite-testing-frameworks/blob/fd0eb2d69a26a1d32b10b769644d9ae609937ae1/src/main/resources/META-INF/rewrite/junit5.yml#L130-L136

And once more via org.openrewrite.java.testing.mockito.Mockito1to3Migration https://github.com/openrewrite/rewrite-testing-frameworks/blob/fd0eb2d69a26a1d32b10b769644d9ae609937ae1/src/main/resources/META-INF/rewrite/mockito.yml#L136-L141

If you were to execute either of these recipes I think you should be upgraded to 4.x or 5.x

As per Mockito's 5.x release notes it seems that 5.x requires Java 11, whereas 4.x still works with Java 8. As our JUnit4to5Migration is intended to get you onto JUnit 5 without raising the required Java version just yet, I suppose we could only bump you up to Mockito 4.x, or make that conditional on the Java version in use.

In any case I believe we could fix all the above using only declarative Yaml recipes and preconditions. Would you want to help out making that a reality?

MBoegers commented 3 days ago

There is at least one more location in the recipeDependencies within https://github.com/openrewrite/rewrite-testing-frameworks/blob/fd0eb2d69a26a1d32b10b769644d9ae609937ae1/build.gradle.kts#L23