Skip to content

Commit

Permalink
AssertJ assertions not collapsed on Integer (#604)
Browse files Browse the repository at this point in the history
* demo: add test

* Update src/test/java/org/openrewrite/java/testing/assertj/CollapseConsecutiveAssertThatStatementsTest.java

Co-authored-by: Tim te Beek <[email protected]>

* Update src/test/java/org/openrewrite/java/testing/assertj/CollapseConsecutiveAssertThatStatementsTest.java

Co-authored-by: Tim te Beek <[email protected]>

* Update src/test/java/org/openrewrite/java/testing/assertj/CollapseConsecutiveAssertThatStatementsTest.java

Co-authored-by: Tim te Beek <[email protected]>

* Disable test for now

---------

Co-authored-by: Tim te Beek <[email protected]>
Co-authored-by: Tim te Beek <[email protected]>
  • Loading branch information
3 people authored Dec 15, 2024
1 parent 1ac86cf commit 89516ea
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
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

0 comments on commit 89516ea

Please sign in to comment.