-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate Hamcrest to JUnit 5 #343
Conversation
Work in progress implementation of a recipe which migrates Hamcrest test matchers to JUnit5 test assertions. Signed-off-by: matus.matok <[email protected]>
src/main/java/org/openrewrite/java/testing/junit5/MigrateFromHamcrest.java
Outdated
Show resolved
Hide resolved
Added a prototype-y implementation of translation from hamcrest's equalTo to JUnit5's assertEquals. Should be easy to add more of the simple hamcrest matchers to this implementation. \TODO the import is not being added Signed-off-by: matus.matok <[email protected]>
src/main/java/org/openrewrite/java/testing/junit5/MigrateFromHamcrest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/junit5/MigrateFromHamcrest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/junit5/MigrateFromHamcrest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/testing/junit5/MigrateFromHamcrestTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/testing/junit5/MigrateFromHamcrestTest.java
Outdated
Show resolved
Hide resolved
Another iteration of the prototype. Adapted it to be based on the up-to-date main. Added a proposal of how similar simple matchers could be translated to junit assertion methods. Signed-off-by: matus.matok <[email protected]>
Hello, got back to this. Noticed that the code base updated a little so I ammended my prototype. The tests dont run however, I am getting a bunch of error messages and I have not figured out how they are related to my changes, so if anyone could take a look, that would be appreciated. |
Appreciate you getting back to this! I've asked @knutwannheden to have a look as I'm caught up in other work this week; from the failures it appears your recipe might not apply or make changes. Did you already try to step through with the debugger? |
Yes I did. Seemingly, the recipe instantiates alright, but during the run phase it fails and I don't understand why. Wanted to double check it so I inserted some console prints into the recipe and they are printed as expected when the test is run. I will add some more simple matcher-to-method cases while I wait for the review. |
src/main/java/org/openrewrite/java/testing/junit5/MigrateFromHamcrest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/junit5/MigrateFromHamcrest.java
Outdated
Show resolved
Hide resolved
Sorry about the delays in getting you feedback; It's been pretty busy with the new 8.0 release coming up. I've posted two suggestions to get your first tests passing; That should help to start iterating by adding options, configuring those from Yaml, and see how far we can get with covering different Hamcrest matchers. Hope that helps! |
Added translations for matchers closeTo, containsString, empty, emptyArray, emptyIterable, emptyCollectionOf, emptyIterableOf, endsWith. Tests need to be added for each matcher. Signed-off-by: matus.matok <[email protected]>
No problem with the delays. Here is some further progress. Some tests -- those that are supposed to add import of |
src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5Test.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
I don't have the permission to push to the fork, but it looks like this patch would fix the compilation error. Maybe that is something you can apply, @timtebeek ? Index: src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java b/src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java
--- a/src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java (revision a18e7aceb1905fdd14a790899626ab2b875f19b3)
+++ b/src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java (revision 0a4ef0be250926b82829d816d981d9d9e422dd0b)
@@ -34,8 +34,6 @@
}
@DocumentExample
- java(
- """
void nestedNotMatcher() {
rewriteRun(
//language=java
@@ -44,7 +42,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
-
+
class ATest {
@Test
void testEquals() {
@@ -58,7 +56,7 @@
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
-
+
class ATest {
@Test
void testEquals() {
@@ -79,7 +77,7 @@
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.not;
-
+
class ATest {
@Test
void testEquals() {
@@ -93,7 +91,7 @@
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
-
+
class ATest {
@Test
void testEquals() { |
src/main/java/org/openrewrite/java/testing/hamcrest/AssertThatBooleanToJUnit5.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/testing/hamcrest/AssertThatBooleanToJUnit5Test.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5Test.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/testing/hamcrest/AssertThatBooleanToJUnit5Test.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5Test.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
To avoid misuse
src/main/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherVisitor.java
Show resolved
Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for these recipes @matusmatokpt ; The review & polish took way longer than I had hoped, but I'm glad to get them in now. I look forward to folks using your recipes to move off of Hamcrest towards JUnit 5.
This is a draft pull request for