openrewrite / rewrite-testing-frameworks

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

Issue discovered on `core/src/testFixtures/java/org/assertj/core/api/IdListAssert.java` with `Simplify AssertJ chained assertions` #509

Open timtebeek opened 7 months ago

timtebeek commented 7 months ago

Problem

Describe the issue you are experiencing.

Expected behavior

Describe what you expected to see.

Example diff

From: core/src/testFixtures/java/org/assertj/core/api/IdListAssert.java

@Override
public IdListAssert<T> hasSize(int expected) {
-        return (IdListAssert<T>) super.hasSize(expected);
+        return (IdListAssert<T>) {{80000000-0000-005f-0000-000000000000}}super.hasSize(expected){{80000000-0000-005f-0000-000000000000}};
}

@Override

Recipes in example diff:

Error messages:

java.lang.ClassCastException: class org.openrewrite.java.tree.J$Identifier cannot be cast to class org.openrewrite.java.tree.J$MethodInvocation (org.openrewrite.java.tree.J$Identifier and org.openrewrite.java.tree.J$MethodInvocation are in unnamed module of loader 'app')
org.openrewrite.java.testing.assertj.SimplifyChainedAssertJAssertion$SimplifyChainedAssertJAssertionsVisitor.visitMethodInvocation(SimplifyChainedAssertJAssertion.java:105)
org.openrewrite.java.testing.assertj.SimplifyChainedAssertJAssertion$SimplifyChainedAssertJAssertionsVisitor.visitMethodInvocation(SimplifyChainedAssertJAssertion.java:90)
org.openrewrite.java.tree.J$MethodInvocation.acceptJava(J.java:3932)
org.openrewrite.java.tree.J.accept(J.java:59)
org.openrewrite.TreeVisitor.visit(TreeVisitor.java:283)
org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:366)
org.openrewrite.java.JavaVisitor.visitTypeCast(JavaVisitor.java:1229)
org.openrewrite.java.JavaIsoVisitor.visitTypeCast(JavaIsoVisitor.java:320)
org.openrewrite.java.JavaIsoVisitor.visitTypeCast(JavaIsoVisitor.java:30)
org.openrewrite.java.tree.J$TypeCast.acceptJava(J.java:5470)
org.openrewrite.java.tree.J.accept(J.java:59)
org.openrewrite.TreeVisitor.visit(TreeVisitor.java:283)
org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:366)
org.openrewrite.java.JavaVisitor.visitReturn(JavaVisitor.java:1102)
org.openrewrite.java.JavaIsoVisitor.visitReturn(JavaIsoVisitor.java:280)
org.openrewrite.java.JavaIsoVisitor.visitReturn(JavaIsoVisitor.java:30)
...

References:

timtebeek commented 7 months ago

Looks to be an odd case of an AssertJ class imported into the project itself: https://github.com/jobrunr/jobrunr/blob/v7.0.0/core/src/testFixtures/java/org/assertj/core/api/IdListAssert.java That would explain why we get super identifier instead of an assertThat methodInvocation here.