From 301858745b4eb290c09d0257a81c5f6e572b101a Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Fri, 17 Jan 2025 17:41:39 +0100 Subject: [PATCH] Suppress mutable execution context warnings for now (#668) - Following https://github.com/openrewrite/rewrite/pull/4879 --- .../java/testing/hamcrest/RemoveNotMatcherVisitor.java | 4 ++-- .../testing/hamcrest/HamcrestInstanceOfToJUnit5Test.java | 4 +++- .../java/testing/hamcrest/HamcrestMatcherToJUnit5Test.java | 3 +++ .../java/testing/hamcrest/MigrateHamcrestToJUnitTest.java | 2 ++ .../java/testing/hamcrest/RemoveNotMatcherTest.java | 5 ++++- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherVisitor.java b/src/main/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherVisitor.java index bd98f50f5..90c28170a 100644 --- a/src/main/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherVisitor.java +++ b/src/main/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherVisitor.java @@ -64,12 +64,12 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation mi, Execution result = template.apply(getCursor(), mi.getCoordinates().replace(), mi.getArguments().get(0)); } - ctx.putMessage(result.toString(), !logicalContext); + ctx.putMessage(result.toString(), !logicalContext); // FIXME Do not store on the use execution context return result; } else { if (ctx.pollMessage(mi.toString()) == null) { - ctx.putMessage(mi.toString(), true); + ctx.putMessage(mi.toString(), true); // FIXME Do not store on the use execution context } } return super.visitMethodInvocation(mi, ctx); diff --git a/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5Test.java b/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5Test.java index 5e19bb246..5cb3db550 100644 --- a/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5Test.java +++ b/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5Test.java @@ -23,6 +23,7 @@ import org.openrewrite.test.RewriteTest; import static org.openrewrite.java.Assertions.java; +import static org.openrewrite.test.TypeValidation.all; class HamcrestInstanceOfToJUnit5Test implements RewriteTest { @Override @@ -30,7 +31,8 @@ public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9", "hamcrest-2.2")) - .recipe(new HamcrestInstanceOfToJUnit5()); + .recipe(new HamcrestInstanceOfToJUnit5()) + .typeValidationOptions(all().immutableExecutionContext(false)); } @DocumentExample diff --git a/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5Test.java b/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5Test.java index e9e970813..e9c053289 100644 --- a/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5Test.java +++ b/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5Test.java @@ -23,6 +23,7 @@ import org.openrewrite.test.RewriteTest; import static org.openrewrite.java.Assertions.java; +import static org.openrewrite.test.TypeValidation.all; class HamcrestMatcherToJUnit5Test implements RewriteTest { @Override @@ -122,6 +123,7 @@ void testEquals() { void notEqualToString() { //language=java rewriteRun( + spec -> spec.typeValidationOptions(all().immutableExecutionContext(false)), java( """ import org.junit.jupiter.api.Test; @@ -464,6 +466,7 @@ void testNullValue() { void sameInstance() { //language=java rewriteRun( + spec -> spec.typeValidationOptions(all().immutableExecutionContext(false)), java( """ import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/openrewrite/java/testing/hamcrest/MigrateHamcrestToJUnitTest.java b/src/test/java/org/openrewrite/java/testing/hamcrest/MigrateHamcrestToJUnitTest.java index d81f56214..c6f153049 100644 --- a/src/test/java/org/openrewrite/java/testing/hamcrest/MigrateHamcrestToJUnitTest.java +++ b/src/test/java/org/openrewrite/java/testing/hamcrest/MigrateHamcrestToJUnitTest.java @@ -23,6 +23,7 @@ import org.openrewrite.test.RewriteTest; import static org.openrewrite.java.Assertions.java; +import static org.openrewrite.test.TypeValidation.all; class MigrateHamcrestToJUnitTest implements RewriteTest { @Override @@ -38,6 +39,7 @@ public void defaults(RecipeSpec spec) { void equalToString() { //language=java rewriteRun( + spec -> spec.typeValidationOptions(all().immutableExecutionContext(false)), java( """ import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java b/src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java index 9db9492b0..738894394 100644 --- a/src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java +++ b/src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java @@ -24,6 +24,7 @@ import static org.openrewrite.java.Assertions.java; import static org.openrewrite.test.RewriteTest.toRecipe; +import static org.openrewrite.test.TypeValidation.all; class RemoveNotMatcherTest implements RewriteTest { @Override @@ -31,10 +32,12 @@ public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9", "hamcrest-2.2")) - .recipe(toRecipe(RemoveNotMatcherVisitor::new)); + .recipe(toRecipe(RemoveNotMatcherVisitor::new)) + .typeValidationOptions(all().immutableExecutionContext(false)); } @DocumentExample + @Test void nestedNotMatcher() { rewriteRun( //language=java