diff --git a/src/main/resources/META-INF/rewrite/assertj.yml b/src/main/resources/META-INF/rewrite/assertj.yml index f60e3cc07..18cac7ae6 100644 --- a/src/main/resources/META-INF/rewrite/assertj.yml +++ b/src/main/resources/META-INF/rewrite/assertj.yml @@ -346,6 +346,8 @@ tags: - testing - assertj recipeList: + # First improve the assertions for JUnit, to fix inverted expected/actual values + - org.openrewrite.java.testing.junit5.CleanupAssertions - org.openrewrite.java.testing.assertj.JUnitAssertArrayEqualsToAssertThat - org.openrewrite.java.testing.assertj.JUnitAssertEqualsToAssertThat - org.openrewrite.java.testing.assertj.JUnitAssertFalseToAssertThat diff --git a/src/test/java/org/openrewrite/java/testing/junit5/CleanupAssertionsTest.java b/src/test/java/org/openrewrite/java/testing/junit5/CleanupAssertionsTest.java index 45efe2db4..0553fe906 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/CleanupAssertionsTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/CleanupAssertionsTest.java @@ -32,10 +32,7 @@ class CleanupAssertionsTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) - .recipe(Environment.builder() - .scanRuntimeClasspath("org.openrewrite.java.testing.junit5") - .build() - .activateRecipes("org.openrewrite.java.testing.junit5.CleanupAssertions")); + .recipeFromResources("org.openrewrite.java.testing.junit5.CleanupAssertions"); } @DocumentExample @@ -130,4 +127,43 @@ void test() { ) ); } + + @Test + void assertNotEqualsInverted() { + //language=java + rewriteRun( + java( + """ + import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; + + class A { + class B {} + + @Test + public void FlippedParams(){ + B myVariable = new B(); + + Assertions.assertNotEquals(myVariable, null); + } + } + """, + """ + import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; + + class A { + class B {} + + @Test + public void FlippedParams(){ + B myVariable = new B(); + + Assertions.assertNotEquals(null, myVariable); + } + } + """ + ) + ); + } }