Skip to content

Commit a79dc45

Browse files
committed
Prevent incorrect change from IsEqualToBoolean
1 parent dc5e689 commit a79dc45

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/main/java/org/openrewrite/java/testing/assertj/IsEqualToBoolean.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
6060
String methodName;
6161
if (J.Literal.isLiteralValue(mi.getArguments().get(0), true)) {
6262
methodName = "isTrue";
63-
} else {
63+
} else if (J.Literal.isLiteralValue(mi.getArguments().get(0), false)) {
6464
methodName = "isFalse";
65+
} else {
66+
return mi;
6567
}
6668
Method isBooleanMethod = mi.getMethodType().withName(methodName);
6769
return mi.withName(mi.getName().withSimpleName(methodName).withType(isBooleanMethod))

src/test/java/org/openrewrite/java/testing/assertj/IsEqualToBooleanTest.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,28 @@ void test() {
7272
}
7373
}
7474
""",
75-
"""
75+
"""
76+
import static org.assertj.core.api.Assertions.assertThat;
77+
class Test {
78+
void test() {
79+
assertThat(false).isFalse();
80+
}
81+
}
82+
"""
83+
)
84+
);
85+
}
86+
87+
@Test
88+
void noChangeOnVariable() {
89+
rewriteRun(
90+
// language=java
91+
java(
92+
"""
7693
import static org.assertj.core.api.Assertions.assertThat;
7794
class Test {
78-
void test() {
79-
assertThat(false).isFalse();
95+
void test(boolean b) {
96+
assertThat(false).isEqualTo(b);
8097
}
8198
}
8299
"""

0 commit comments

Comments
 (0)