[YANGTOOLS-1521] Migrate to JUnit5 Created: 04/Jul/23  Updated: 18/Oct/23  Resolved: 18/Oct/23

Status: Resolved
Project: yangtools
Component/s: None
Affects Version/s: None
Fix Version/s: 12.0.0

Type: Task Priority: Medium
Reporter: Robert Varga Assignee: Robert Varga
Resolution: Done Votes: 0
Labels: pt
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The following artifacts contain references to JUnit4:

codec/yang-data-codec-binfmt
codec/yang-data-codec-gson
codec/yang-data-codec-xml
common/util
data/yang-data-impl
data/yang-data-tree-ri
data/yang-data-tree-spi
parser/odlext-parser-support
parser/rfc6241-parser-support
parser/rfc6536-parser-support
parser/rfc6643-parser-support
parser/rfc7952-parser-support
parser/rfc8040-parser-support
parser/rfc8528-parser-support
parser/rfc8639-parser-support
parser/yang-parser-impl
parser/yang-parser-spi
plugin/yang-maven-plugin-it
yang/yang-repo-spi

Migrate them to JUnit5. This includes cleaning up things like assertThat(instanceOf()), assertTrue(foo instanceof x) to use assertInstanceOf(), etc.



 Comments   
Comment by Matúš Matok [ 11/Jul/23 ]

This is the plugin setup I was using for the refactoring, letting it live here for future references.

    <build>
        <plugins>
            <plugin>
                <groupId>org.openrewrite.maven</groupId>
                <artifactId>rewrite-maven-plugin</artifactId>
                <version>5.2.6</version>
                <configuration>
                    <activeRecipes>
                        <recipe>org.openrewrite.java.testing.hamcrest.HamcrestMatcherToJUnit5</recipe> <!-- my new recipe -->
                        <recipe>org.openrewrite.java.testing.hamcrest.AssertThatBooleanToJUnit5</recipe> <!-- my new recipe -->
                        <recipe>org.openrewrite.java.testing.junit5.MigrateJUnitTestCase</recipe>
                        <recipe>org.openrewrite.java.testing.junit5.AssertToAssertions</recipe>
                        <recipe>org.openrewrite.java.testing.junit5.UpdateTestAnnotation</recipe>
                        <recipe>org.openrewrite.java.testing.junit5.UpdateBeforeAfterAnnotations</recipe>
                        <recipe>org.openrewrite.java.testing.junit5.RemoveObsoleteRunners</recipe>
                        <recipe>org.openrewrite.java.testing.junit5.RunnerToExtension</recipe>
                        <recipe>org.openrewrite.java.testing.junit5.AssertTrueInstanceofToAssertInstanceOf</recipe> <!-- my new recipe, merged meanwhile-->
                    </activeRecipes>
                </configuration>
                <dependencies>   <!-- This part is necessary, as we need to use local maven repo when working with custom forked openrewrite project -->
                    <dependency>
                        <groupId>org.openrewrite.recipe</groupId>
                        <artifactId>rewrite-testing-frameworks</artifactId>
                        <version>0.1.0-SNAPSHOT</version> <!-- version yielded by ./gradlew publishToMavenLocal -->
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

 

I did not use org.openrewrite.java.testing.junit5.JUnit5BestPracticesRecipe nor JUnit4to5Migration as it produced an invalid code with a ton of checkstyle errors.
With having this plugin setup in module's pom.xml, we can simply run `mvn rewrite:run`, which will trigger the refactoring process.

Comment by Matúš Matok [ 30/Aug/23 ]

In case anyone will continue with this, the aforementioned recipes have not been merged yet, so here is the pull request containing them:
https://github.com/openrewrite/rewrite-testing-frameworks/pull/343

Generated at Wed Feb 07 20:56:23 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.