Skip to content

Commit

Permalink
Prevent incorrect change from IsEqualToBoolean
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Jul 10, 2024
1 parent dc5e689 commit a79dc45
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
String methodName;
if (J.Literal.isLiteralValue(mi.getArguments().get(0), true)) {
methodName = "isTrue";
} else {
} else if (J.Literal.isLiteralValue(mi.getArguments().get(0), false)) {
methodName = "isFalse";
} else {
return mi;
}
Method isBooleanMethod = mi.getMethodType().withName(methodName);
return mi.withName(mi.getName().withSimpleName(methodName).withType(isBooleanMethod))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,28 @@ void test() {
}
}
""",
"""
"""
import static org.assertj.core.api.Assertions.assertThat;
class Test {
void test() {
assertThat(false).isFalse();
}
}
"""
)
);
}

@Test
void noChangeOnVariable() {
rewriteRun(
// language=java
java(
"""
import static org.assertj.core.api.Assertions.assertThat;
class Test {
void test() {
assertThat(false).isFalse();
void test(boolean b) {
assertThat(false).isEqualTo(b);
}
}
"""
Expand Down

0 comments on commit a79dc45

Please sign in to comment.