-
Notifications
You must be signed in to change notification settings - Fork 103
SimplifyChainedAssertJAssertion drops method call in replacement #628
Copy link
Copy link
Closed
Labels
Description
What version of OpenRewrite are you using?
I am using
- OpenRewrite v5.43.3
- Maven/Gradle plugin v5.43.3
- rewrite-testing-frameworks v2.21.0
How are you running OpenRewrite?
I am using the Maven plugin, and my project is a single module project.
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-testing-frameworks:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.testing.assertj.Assertj -Drewrite.exportDatatables=trueWhat is the smallest, simplest way to reproduce the problem?
I recreated this with a test, basically copying the existing stringContains() test. This shows the expectation:
@Test
void stringContainsObjectMethod() {
rewriteRun(
spec -> spec.recipes(
new SimplifyChainedAssertJAssertion("contains", "isTrue", "contains", "java.lang.String"),
new SimplifyChainedAssertJAssertion("contains", "isFalse", "doesNotContain", "java.lang.String")
),
//language=java
java(
"""
import static org.assertj.core.api.Assertions.assertThat;
class Pojo {
public String getString() {
return "lo wo";
}
}
class MyTest {
void testMethod() {
var pojo = new Pojo();
assertThat("hello world".contains(pojo.getString())).isTrue();
assertThat("hello world".contains("lll")).isFalse();
}
}
""",
"""
import static org.assertj.core.api.Assertions.assertThat;
class Pojo {
public String getString() {
return "lo wo";
}
}
class MyTest {
void testMethod() {
var pojo = new Pojo();
assertThat("hello world").contains(pojo.getString());
assertThat("hello world").doesNotContain("lll");
}
}
"""
)
);
}What did you expect to see?
import static org.assertj.core.api.Assertions.assertThat;
class Pojo {
public String getString() {
return "lo wo";
}
}
class MyTest {
void testMethod() {
var pojo = new Pojo();
assertThat("hello world").contains(pojo.getString());
assertThat("hello world").doesNotContain("lll");
}
}What did you see instead?
import static org.assertj.core.api.Assertions.assertThat;
class Pojo {
public String getString() {
return "lo wo";
}
}
class MyTest {
void testMethod() {
var pojo = new Pojo();
assertThat("hello world").contains(pojo);
assertThat("hello world").doesNotContain("lll");
}
}What is the full stack trace of any errors you encountered?
No stack, just incorrect replacement.
It appears to be related to the SimplifyChainedAssertJAssertion.extractEitherArgument method where getSelect() is chosen.
Are you interested in contributing a fix to OpenRewrite?
Yes, if I understand the requirements around the use of getSelect() instead of the full J.MethodInvocation.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done