Skip to content

Commit b8a0425

Browse files
committed
AssertToAssertions should not swap arguments for fail methods
Fixes #804
1 parent 209e298 commit b8a0425

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/main/java/org/openrewrite/java/testing/junit5/AssertToAssertions.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
9696
return m;
9797
}
9898
}
99+
if ("fail".equals(m.getSimpleName())) {
100+
return m;
101+
}
99102

100103
if (TypeUtils.isString(firstArg.getType())) {
101104
// Move the first arg to be the last argument

src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.openrewrite.marker.BuildTool;
2727
import org.openrewrite.test.RecipeSpec;
2828
import org.openrewrite.test.RewriteTest;
29+
import org.openrewrite.test.TypeValidation;
2930

3031
import java.util.regex.Pattern;
3132

@@ -755,4 +756,54 @@ public void testMethod() {}
755756
);
756757
}
757758
}
759+
760+
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/804")
761+
@Test
762+
void dontSwapArgumentsForFailWithMissingTypeInformationInJavadoc() {
763+
rewriteRun(
764+
spec -> spec.typeValidationOptions(TypeValidation.none()),
765+
java(
766+
"""
767+
import org.junit.Assert;
768+
import org.junit.Test;
769+
770+
public class ReproductionTest {
771+
772+
public static void fail(String param1, String param2, String param3) {
773+
// No-op
774+
}
775+
776+
/**
777+
* Method documentation with a broken link to {@link #fail(String, String,
778+
* Integer)} (the types in the parameter list don't match).
779+
*/
780+
@Test
781+
public void test() {
782+
Assert.assertEquals(42, Integer.parseInt("2a", 16));
783+
}
784+
}
785+
""",
786+
"""
787+
import org.junit.jupiter.api.Assertions;
788+
import org.junit.jupiter.api.Test;
789+
790+
public class ReproductionTest {
791+
792+
public static void fail(String param1, String param2, String param3) {
793+
// No-op
794+
}
795+
796+
/**
797+
* Method documentation with a broken link to {@link #fail(String, String,
798+
* Integer)} (the types in the parameter list don't match).
799+
*/
800+
@Test
801+
public void test() {
802+
Assertions.assertEquals(42, Integer.parseInt("2a", 16));
803+
}
804+
}
805+
"""
806+
)
807+
);
808+
}
758809
}

0 commit comments

Comments
 (0)