diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/AssertEqualsBooleanToAssertBoolean.java b/src/main/java/org/openrewrite/java/testing/cleanup/AssertEqualsBooleanToAssertBoolean.java index dd0f354cc..0ebbd75db 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/AssertEqualsBooleanToAssertBoolean.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/AssertEqualsBooleanToAssertBoolean.java @@ -57,7 +57,8 @@ public TreeVisitor getVisitor() { @Override public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { J.MethodInvocation mi = (J.MethodInvocation) super.visitMethodInvocation(method, ctx); - if (ASSERT_EQUALS.matches(mi) && isBooleanLiteral(mi)) { + if (ASSERT_EQUALS.matches(mi) && isBooleanLiteral(mi) && + JavaType.Primitive.Boolean.equals(mi.getArguments().get(1).getType())) { StringBuilder sb = new StringBuilder(); String assertMethod = Boolean.parseBoolean(((J.Literal) mi.getArguments().get(0)).getValueSource()) ? "assertTrue" : "assertFalse"; diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/AssertEqualsBooleanToAssertBooleanTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/AssertEqualsBooleanToAssertBooleanTest.java index 4d39ff54e..13bbaf4ae 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/AssertEqualsBooleanToAssertBooleanTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/AssertEqualsBooleanToAssertBooleanTest.java @@ -105,4 +105,23 @@ void test() { ) ); } + + @Test + @Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/587") + void assertTrueWithNonBoolean() { + rewriteRun( + spec -> spec.recipe(new AssertEqualsBooleanToAssertBoolean()), + // language=java + java( + """ + import static org.junit.jupiter.api.Assertions.assertEquals; + class Main { + void foo() { + assertEquals(true, new Object()); + } + } + """ + ) + ); + } }