diff --git a/src/main/java/org/openrewrite/java/testing/junit5/AssertToAssertions.java b/src/main/java/org/openrewrite/java/testing/junit5/AssertToAssertions.java index feb63f35a..ba134c75e 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/AssertToAssertions.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/AssertToAssertions.java @@ -81,14 +81,15 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu doAfterVisit(new ChangeMethodTargetToStatic("org.junit.Assert " + m.getSimpleName() + "(..)", "org.junit.jupiter.api.Assertions", null, null, true) .getVisitor()); + List args = m.getArguments(); Expression firstArg = args.get(0); // Suppress arg-switching for Assertions.assertEquals(String, String) if (args.size() == 2) { if ("assertSame".equals(m.getSimpleName()) || - "assertNotSame".equals(m.getSimpleName()) || - "assertEquals".equals(m.getSimpleName()) || - "assertNotEquals".equals(m.getSimpleName())) { + "assertNotSame".equals(m.getSimpleName()) || + "assertEquals".equals(m.getSimpleName()) || + "assertNotEquals".equals(m.getSimpleName())) { return m; } } diff --git a/src/main/resources/META-INF/rewrite/junit5.yml b/src/main/resources/META-INF/rewrite/junit5.yml index cec127f92..99e58adb9 100755 --- a/src/main/resources/META-INF/rewrite/junit5.yml +++ b/src/main/resources/META-INF/rewrite/junit5.yml @@ -65,6 +65,9 @@ recipeList: - org.openrewrite.java.testing.junit5.UseMockitoExtension - org.openrewrite.java.testing.junit5.UseTestMethodOrder - org.openrewrite.java.testing.junit5.MigrateJUnitTestCase + - org.openrewrite.java.ChangeMethodName: + methodPattern: "org.junit.Assert assertEquals(.., Object[], Object[])" + newMethodName: assertArrayEquals - org.openrewrite.java.testing.junit5.AssertToAssertions - org.openrewrite.java.testing.junit5.CategoryToTag - org.openrewrite.java.testing.junit5.CleanupJUnitImports diff --git a/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java b/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java index 0750cc3c3..e3520de53 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java @@ -161,5 +161,33 @@ void upgradeMavenPluginVersions() { ); } - + // edge case for deprecated use of assertEquals + // https://junit.org/junit4/javadoc/4.13/org/junit/Assert.html#assertEquals(java.lang.Object%5B%5D,%20java.lang.Object%5B%5D) + @Issue("https://github.com/openrewrite/rewrite-testing-frameworks/pull/384") + @Test + void assertEqualsWithArrayArgumentToAssertArrayEquals() { + //language=java + rewriteRun( + java( + """ + import org.junit.Assert; + + class MyTest { + void test() { + Assert.assertEquals(new Object[1], new Object[1]); + } + } + """, + """ + import org.junit.jupiter.api.Assertions; + + class MyTest { + void test() { + Assertions.assertArrayEquals(new Object[1], new Object[1]); + } + } + """ + ) + ); + } }