Skip to content

Commit

Permalink
Document a complete isEqualTo migration
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Jun 29, 2023
1 parent 83fd44e commit 266c018
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/main/resources/META-INF/rewrite/hamcrest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@ recipeList:
notMatcher: emptyString
assertion: isNotEmpty



# Add dependency if not already present
- org.openrewrite.java.dependencies.AddDependency:
groupId: org.assertj
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Arguments> stringReplacements() {
return Stream.of(
Arguments.arguments("str1", "blankString", "", "isBlank"),
Expand Down

0 comments on commit 266c018

Please sign in to comment.