From bccb8107a56d21477c179b5baa3e5f5494a62ce2 Mon Sep 17 00:00:00 2001 From: sullis Date: Mon, 16 Dec 2024 13:38:21 -0800 Subject: [PATCH 1/6] add Mockito1to4MigrationTest --- build.gradle.kts | 1 + .../mockito/Mockito1to4MigrationTest.java | 102 ++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java diff --git a/build.gradle.kts b/build.gradle.kts index 404a51889..cff34a87e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -19,6 +19,7 @@ recipeDependencies { parserClasspath("org.mockito:mockito-all:1.10.19") parserClasspath("org.mockito:mockito-core:3.+") parserClasspath("org.mockito:mockito-core:5.+") + parserClasspath("org.mockito:mockito-junit-jupiter:5.+") parserClasspath("org.jmockit:jmockit:1.49") parserClasspath("org.jmockit:jmockit:1.22") // last version with NonStrictExpectations parserClasspath("org.mockito:mockito-junit-jupiter:3.+") diff --git a/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java b/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java new file mode 100644 index 000000000..777fce651 --- /dev/null +++ b/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java @@ -0,0 +1,102 @@ +/* + * Copyright 2024 the original author or authors. + *

+ * Licensed under the Moderne Source Available License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://docs.moderne.io/licensing/moderne-source-available-license + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.java.testing.mockito; + +import org.junit.jupiter.api.Test; +import org.openrewrite.InMemoryExecutionContext; +import org.openrewrite.config.Environment; +import org.openrewrite.java.JavaParser; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.gradle.Assertions.buildGradle; +import static org.openrewrite.gradle.toolingapi.Assertions.withToolingApi; +import static org.openrewrite.java.Assertions.java; + +public class Mockito1to4MigrationTest implements RewriteTest { + + @Override + public void defaults(RecipeSpec spec) { + spec + .beforeRecipe(withToolingApi()) + .parser(JavaParser.fromJavaVersion() + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api", "mockito-core", "mockito-junit-jupiter")) + .recipe(Environment.builder() + .scanRuntimeClasspath("org.openrewrite.java.testing") + .build() + .activateRecipes("org.openrewrite.java.testing.mockito.Mockito1to4Migration")); + } + + @Test + void modifyMockitoDependencies() { + //language=java + rewriteRun( + buildGradle( + """ + plugins { + id 'java-library' + } + repositories { + mavenCentral() + } + dependencies { + implementation("org.apache.commons:commons-lang3:3.17.0") + testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.4") + testImplementation("org.mockito:mockito-core:3.12.4") + testImplementation("org.mockito:mockito-junit-jupiter:3.12.4") + } + test { + useJUnitPlatform() + } + """, + """ + plugins { + id 'java-library' + } + repositories { + mavenCentral() + } + dependencies { + implementation("org.apache.commons:commons-lang3:3.17.0") + testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.4") + testImplementation("org.mockito:mockito-core:4.11.0") + testImplementation("org.mockito:mockito-junit-jupiter:4.11.0") + } + test { + useJUnitPlatform() + } + """ + ), + java( + """ + import org.junit.jupiter.api.Test; + import org.junit.jupiter.api.extension.ExtendWith; + import org.mockito.Mockito; + import org.mockito.junit.jupiter.MockitoExtension; + import java.util.List; + + @ExtendWith(MockitoExtension.class) + public class MyTest { + @Test + public void test() { + List list = Mockito.mock(List.class); + } + } + """ + ) + ); + } +} From ee07009db4fb527d022d554da8c7af5fc96f03b1 Mon Sep 17 00:00:00 2001 From: sullis Date: Tue, 17 Dec 2024 14:15:31 -0800 Subject: [PATCH 2/6] Update src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../java/testing/mockito/Mockito1to4MigrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java b/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java index 777fce651..1d638e0f5 100644 --- a/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java +++ b/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java @@ -26,7 +26,7 @@ import static org.openrewrite.gradle.toolingapi.Assertions.withToolingApi; import static org.openrewrite.java.Assertions.java; -public class Mockito1to4MigrationTest implements RewriteTest { +class Mockito1to4MigrationTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { From 21c123ba26d14c68a2a1ecbd4219466bf274933e Mon Sep 17 00:00:00 2001 From: sullis Date: Tue, 17 Dec 2024 14:15:39 -0800 Subject: [PATCH 3/6] Update src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../java/testing/mockito/Mockito1to4MigrationTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java b/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java index 1d638e0f5..a3fd00a8a 100644 --- a/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java +++ b/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java @@ -16,6 +16,7 @@ package org.openrewrite.java.testing.mockito; import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.config.Environment; import org.openrewrite.java.JavaParser; From f6d13f790046bc1310f13f9166e574e75fbf5f2e Mon Sep 17 00:00:00 2001 From: sullis Date: Tue, 17 Dec 2024 14:15:49 -0800 Subject: [PATCH 4/6] Update src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../java/testing/mockito/Mockito1to4MigrationTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java b/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java index a3fd00a8a..428938aac 100644 --- a/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java +++ b/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java @@ -41,6 +41,7 @@ public void defaults(RecipeSpec spec) { .activateRecipes("org.openrewrite.java.testing.mockito.Mockito1to4Migration")); } + @DocumentExample @Test void modifyMockitoDependencies() { //language=java From 20b9012af94b1fb8bb96335a8c072978c563a8a9 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Thu, 19 Dec 2024 09:31:25 +0100 Subject: [PATCH 5/6] Minor polish --- .../java/testing/mockito/Mockito1to4MigrationTest.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java b/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java index 428938aac..586434ca0 100644 --- a/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java +++ b/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java @@ -35,17 +35,14 @@ public void defaults(RecipeSpec spec) { .beforeRecipe(withToolingApi()) .parser(JavaParser.fromJavaVersion() .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api", "mockito-core", "mockito-junit-jupiter")) - .recipe(Environment.builder() - .scanRuntimeClasspath("org.openrewrite.java.testing") - .build() - .activateRecipes("org.openrewrite.java.testing.mockito.Mockito1to4Migration")); + .recipeFromResources("org.openrewrite.java.testing.mockito.Mockito1to4Migration"); } @DocumentExample @Test void modifyMockitoDependencies() { - //language=java rewriteRun( + //language=groovy buildGradle( """ plugins { @@ -82,6 +79,7 @@ void modifyMockitoDependencies() { } """ ), + //language=java java( """ import org.junit.jupiter.api.Test; From 77abe2cf59ffdbb58b39750d850af819f1fa13e4 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Thu, 19 Dec 2024 09:52:32 +0100 Subject: [PATCH 6/6] Update src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../java/testing/mockito/Mockito1to4MigrationTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java b/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java index 586434ca0..a21d95c5c 100644 --- a/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java +++ b/src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java @@ -18,7 +18,6 @@ import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; import org.openrewrite.InMemoryExecutionContext; -import org.openrewrite.config.Environment; import org.openrewrite.java.JavaParser; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest;