Skip to content

Commit

Permalink
Migrate all Hamcrest matchers from core package
Browse files Browse the repository at this point in the history
Fixes #519
  • Loading branch information
timtebeek committed Jun 13, 2024
1 parent 5f78370 commit 6f91c2f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/rewrite/hamcrest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ tags:
recipeList:
# First change `is(..)` to `Matchers.is(..)` for consistent matching
- org.openrewrite.java.ChangeMethodTargetToStatic:
methodPattern: org.hamcrest.core.Is is(..)
methodPattern: org.hamcrest.core.* *(..)
fullyQualifiedTargetTypeName: org.hamcrest.Matchers

# Then remove wrapping `is(Matcher)` calls such that further recipes will match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,4 +719,45 @@ void ba() {
)
);
}

@Test
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/519")
void isEqualMatcherFromCore() {
rewriteRun(
//language=java
java(
"""
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNot.not;
import static org.hamcrest.core.IsSame.sameInstance;
import org.junit.jupiter.api.Test;
class DebugTest {
@Test
void ba() {
assertThat(System.out, equalTo(System.out));
assertThat(System.out, not(System.out));
assertThat(System.out, sameInstance(System.out));
}
}
""",
"""
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
class DebugTest {
@Test
void ba() {
assertThat(System.out).isEqualTo(System.out);
assertThat(System.out).isNotEqualTo(System.out);
assertThat(System.out).isSameAs(System.out);
}
}
"""
)
);
}
}

0 comments on commit 6f91c2f

Please sign in to comment.