Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertJ assertions not collapsed on Integer #604

Merged
merged 7 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,13 @@ private boolean isGroupableAssertion(J.MethodInvocation assertion) {
// Only match method invocations where the select is an assertThat, containing a non-method call argument
if (ASSERT_THAT.matches(assertion.getSelect())) {
J.MethodInvocation assertThat = (J.MethodInvocation) assertion.getSelect();
if (assertThat != null && !(assertThat.getArguments().get(0) instanceof MethodCall)) {
return TypeUtils.isOfType(assertThat.getType(), assertion.getType());
if (assertThat != null) {
Expression assertThatArgument = assertThat.getArguments().get(0);
if (!(assertThatArgument instanceof MethodCall)) {
JavaType assertThatType = assertThat.getType();
JavaType assertionType = assertion.getType();
return TypeUtils.isOfType(assertThatType, assertionType);
}
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.openrewrite.java.testing.assertj;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.InMemoryExecutionContext;
Expand Down Expand Up @@ -192,6 +193,37 @@ private int[] notification() {
);
}

@Disabled("Not yet implemented")
@Test
void collapseAssertThatsOnInteger() {
//language=java
rewriteRun(
java(
"""
import static org.assertj.core.api.Assertions.assertThat;

class MyTest {
void test(Integer i) {
assertThat(i).isNotNull();
assertThat(i).isEqualTo(2);
}
}
""",
"""
import static org.assertj.core.api.Assertions.assertThat;

class MyTest {
void test(Integer i) {
assertThat(i)
.isNotNull()
.isEqualTo(2);
}
}
"""
)
);
}

@Test
void ignoreIfAssertThatOnDifferentVariables() {
//language=java
Expand Down
Loading