Skip to content

Commit aefb2a6

Browse files
authored
Do not ChangeMethodTargetToStatic for AssertJ's AssertionsFor...Types (#693)
Fixes #664
1 parent 365b782 commit aefb2a6

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

src/main/resources/META-INF/rewrite/assertj.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ tags:
6060
- testing
6161
- assertj
6262
recipeList:
63-
- org.openrewrite.java.ChangeMethodTargetToStatic:
64-
methodPattern: "org.assertj.core.api.AssertionsForClassTypes assertThat(..)"
65-
fullyQualifiedTargetTypeName: "org.assertj.core.api.Assertions"
66-
- org.openrewrite.java.ChangeMethodTargetToStatic:
67-
methodPattern: "org.assertj.core.api.AssertionsForInterfaceTypes assertThat(..)"
68-
fullyQualifiedTargetTypeName: "org.assertj.core.api.Assertions"
63+
# https://github.com/openrewrite/rewrite-testing-frameworks/issues/664
64+
# - org.openrewrite.java.ChangeMethodTargetToStatic:
65+
# methodPattern: "org.assertj.core.api.AssertionsForClassTypes assertThat(..)"
66+
# fullyQualifiedTargetTypeName: "org.assertj.core.api.Assertions"
67+
# - org.openrewrite.java.ChangeMethodTargetToStatic:
68+
# methodPattern: "org.assertj.core.api.AssertionsForInterfaceTypes assertThat(..)"
69+
# fullyQualifiedTargetTypeName: "org.assertj.core.api.Assertions"
6970
- org.openrewrite.java.ChangeMethodTargetToStatic:
7071
methodPattern: "org.assertj.core.api.Fail fail(..)"
7172
fullyQualifiedTargetTypeName: "org.assertj.core.api.Assertions"

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

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
package org.openrewrite.java.testing.assertj;
1717

1818

19+
import org.junit.jupiter.api.Disabled;
1920
import org.junit.jupiter.api.Test;
2021
import org.openrewrite.DocumentExample;
2122
import org.openrewrite.InMemoryExecutionContext;
23+
import org.openrewrite.Issue;
2224
import org.openrewrite.config.Environment;
2325
import org.openrewrite.java.JavaParser;
2426
import org.openrewrite.test.RecipeSpec;
@@ -41,7 +43,47 @@ public void defaults(RecipeSpec spec) {
4143

4244
@DocumentExample
4345
@Test
44-
void useAssertionsStaticImport() {
46+
void useStaticImports() {
47+
//language=java
48+
rewriteRun(
49+
java(
50+
"""
51+
import java.util.List;
52+
import org.assertj.core.api.Assertions;
53+
import static org.assertj.core.api.Fail.fail;
54+
55+
public class Test {
56+
List<String> exampleList;
57+
void method() {
58+
Assertions.assertThat(true).isTrue();
59+
Assertions.assertThat(exampleList).hasSize(0);
60+
fail("This is a failure");
61+
}
62+
}
63+
""",
64+
"""
65+
import java.util.List;
66+
67+
import static org.assertj.core.api.Assertions.assertThat;
68+
import static org.assertj.core.api.Assertions.fail;
69+
70+
public class Test {
71+
List<String> exampleList;
72+
void method() {
73+
assertThat(true).isTrue();
74+
assertThat(exampleList).hasSize(0);
75+
fail("This is a failure");
76+
}
77+
}
78+
"""
79+
)
80+
);
81+
}
82+
83+
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/664")
84+
@Test
85+
@Disabled("Requires changes in AssertJ to adopt `assertThatClass` and `assertThatInterface`")
86+
void assertionsForClassTypes() {
4587
//language=java
4688
rewriteRun(
4789
java(
@@ -51,7 +93,6 @@ void useAssertionsStaticImport() {
5193
import org.assertj.core.api.AssertionsForInterfaceTypes;
5294
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
5395
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
54-
import static org.assertj.core.api.Fail.fail;
5596
5697
public class Test {
5798
List<String> exampleList;
@@ -60,15 +101,13 @@ void method() {
60101
AssertionsForClassTypes.assertThat(true).isTrue();
61102
assertThat(true).isTrue();
62103
assertThat(exampleList).hasSize(0);
63-
fail("This is a failure");
64104
}
65105
}
66106
""",
67107
"""
68108
import java.util.List;
69109
70110
import static org.assertj.core.api.Assertions.assertThat;
71-
import static org.assertj.core.api.Assertions.fail;
72111
73112
public class Test {
74113
List<String> exampleList;
@@ -77,7 +116,6 @@ void method() {
77116
assertThat(true).isTrue();
78117
assertThat(true).isTrue();
79118
assertThat(exampleList).hasSize(0);
80-
fail("This is a failure");
81119
}
82120
}
83121
"""

0 commit comments

Comments
 (0)