From 266c018a1680400df1acc7cd263fd0a2cc1da897 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Thu, 29 Jun 2023 18:38:06 +0200 Subject: [PATCH] Document a complete isEqualTo migration --- .../resources/META-INF/rewrite/hamcrest.yml | 2 - .../MigrateHamcrestToAssertJTest.java | 37 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/main/resources/META-INF/rewrite/hamcrest.yml b/src/main/resources/META-INF/rewrite/hamcrest.yml index e3fa7b22e..510f34ce3 100644 --- a/src/main/resources/META-INF/rewrite/hamcrest.yml +++ b/src/main/resources/META-INF/rewrite/hamcrest.yml @@ -237,8 +237,6 @@ recipeList: notMatcher: emptyString assertion: isNotEmpty - - # Add dependency if not already present - org.openrewrite.java.dependencies.AddDependency: groupId: org.assertj diff --git a/src/test/java/org/openrewrite/java/testing/hamcrest/MigrateHamcrestToAssertJTest.java b/src/test/java/org/openrewrite/java/testing/hamcrest/MigrateHamcrestToAssertJTest.java index dd194cdaf..5a05547db 100644 --- a/src/test/java/org/openrewrite/java/testing/hamcrest/MigrateHamcrestToAssertJTest.java +++ b/src/test/java/org/openrewrite/java/testing/hamcrest/MigrateHamcrestToAssertJTest.java @@ -15,9 +15,11 @@ */ package org.openrewrite.java.testing.hamcrest; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import org.openrewrite.DocumentExample; import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.Issue; import org.openrewrite.config.Environment; @@ -45,6 +47,41 @@ public void defaults(RecipeSpec spec) { .activateRecipes("org.openrewrite.java.testing.hamcrest.MigrateHamcrestToAssertJ")); } + @Test + @DocumentExample + void isEqualTo() { + rewriteRun( + //language=java + java(""" + import org.junit.jupiter.api.Test; + import static org.hamcrest.MatcherAssert.assertThat; + import static org.hamcrest.Matchers.is; + import static org.hamcrest.Matchers.equalTo; + + class ATest { + @Test + void testEquals() { + String str1 = "Hello world!"; + String str2 = "Hello world!"; + assertThat(str1, is(equalTo(str2))); + } + } + """, """ + import org.junit.jupiter.api.Test; + + import static org.assertj.core.api.Assertions.assertThat; + + class ATest { + @Test + void testEquals() { + String str1 = "Hello world!"; + String str2 = "Hello world!"; + assertThat(str1).isEqualTo(str2); + } + } + """)); + } + private static Stream stringReplacements() { return Stream.of( Arguments.arguments("str1", "blankString", "", "isBlank"),