Skip to content

Commit 266c018

Browse files
committed
Document a complete isEqualTo migration
1 parent 83fd44e commit 266c018

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,6 @@ recipeList:
237237
notMatcher: emptyString
238238
assertion: isNotEmpty
239239

240-
241-
242240
# Add dependency if not already present
243241
- org.openrewrite.java.dependencies.AddDependency:
244242
groupId: org.assertj

src/test/java/org/openrewrite/java/testing/hamcrest/MigrateHamcrestToAssertJTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
*/
1616
package org.openrewrite.java.testing.hamcrest;
1717

18+
import org.junit.jupiter.api.Test;
1819
import org.junit.jupiter.params.ParameterizedTest;
1920
import org.junit.jupiter.params.provider.Arguments;
2021
import org.junit.jupiter.params.provider.MethodSource;
22+
import org.openrewrite.DocumentExample;
2123
import org.openrewrite.InMemoryExecutionContext;
2224
import org.openrewrite.Issue;
2325
import org.openrewrite.config.Environment;
@@ -45,6 +47,41 @@ public void defaults(RecipeSpec spec) {
4547
.activateRecipes("org.openrewrite.java.testing.hamcrest.MigrateHamcrestToAssertJ"));
4648
}
4749

50+
@Test
51+
@DocumentExample
52+
void isEqualTo() {
53+
rewriteRun(
54+
//language=java
55+
java("""
56+
import org.junit.jupiter.api.Test;
57+
import static org.hamcrest.MatcherAssert.assertThat;
58+
import static org.hamcrest.Matchers.is;
59+
import static org.hamcrest.Matchers.equalTo;
60+
61+
class ATest {
62+
@Test
63+
void testEquals() {
64+
String str1 = "Hello world!";
65+
String str2 = "Hello world!";
66+
assertThat(str1, is(equalTo(str2)));
67+
}
68+
}
69+
""", """
70+
import org.junit.jupiter.api.Test;
71+
72+
import static org.assertj.core.api.Assertions.assertThat;
73+
74+
class ATest {
75+
@Test
76+
void testEquals() {
77+
String str1 = "Hello world!";
78+
String str2 = "Hello world!";
79+
assertThat(str1).isEqualTo(str2);
80+
}
81+
}
82+
"""));
83+
}
84+
4885
private static Stream<Arguments> stringReplacements() {
4986
return Stream.of(
5087
Arguments.arguments("str1", "blankString", "", "isBlank"),

0 commit comments

Comments
 (0)