From 2b93850e367e8f74cd14f8a16903118cf6da1927 Mon Sep 17 00:00:00 2001 From: Tyler Van Gorder Date: Tue, 29 Jun 2021 17:00:04 -0700 Subject: [PATCH] Adding UnnecessarySpringExtension to boot migration. --- .../META-INF/rewrite/spring-boot2.yml | 2 + .../spring/boot2/SpringBootMigrationTest.kt | 81 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/test/kotlin/org/openrewrite/java/spring/boot2/SpringBootMigrationTest.kt diff --git a/src/main/resources/META-INF/rewrite/spring-boot2.yml b/src/main/resources/META-INF/rewrite/spring-boot2.yml index 927c795fa..d67e522b1 100644 --- a/src/main/resources/META-INF/rewrite/spring-boot2.yml +++ b/src/main/resources/META-INF/rewrite/spring-boot2.yml @@ -38,6 +38,7 @@ recipeList: # There is a third variant of this class in spring-cloud-commons and there is not yet a suitable migration # path. Once one exists, this can likely be added for removal as well. #- org.springframework.cloud.test.ModifiedClassPathRunner + - org.openrewrite.java.spring.boot2.UnnecessarySpringExtension - org.openrewrite.maven.AddDependency: groupId: org.springframework.boot artifactId: spring-boot-tools @@ -56,6 +57,7 @@ tags: recipeList: - org.openrewrite.java.spring.NoRequestMappingAnnotation - org.openrewrite.java.spring.ImplicitWebAnnotationNames + - org.openrewrite.java.spring.boot2.UnnecessarySpringExtension --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.spring.boot2.SpringBoot1To2Migration diff --git a/src/test/kotlin/org/openrewrite/java/spring/boot2/SpringBootMigrationTest.kt b/src/test/kotlin/org/openrewrite/java/spring/boot2/SpringBootMigrationTest.kt new file mode 100644 index 000000000..cf501c777 --- /dev/null +++ b/src/test/kotlin/org/openrewrite/java/spring/boot2/SpringBootMigrationTest.kt @@ -0,0 +1,81 @@ +/* + * Copyright 2020 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.spring.org.openrewrite.java.spring.boot2 + +import org.junit.jupiter.api.Test +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.ValueSource +import org.openrewrite.Issue +import org.openrewrite.Parser +import org.openrewrite.Recipe +import org.openrewrite.config.Environment +import org.openrewrite.java.JavaParser +import org.openrewrite.java.JavaRecipeTest +import org.openrewrite.java.spring.boot2.UnnecessarySpringExtension + +class SpringBootMigrationTest : JavaRecipeTest { + + override val recipe: Recipe + get() = Environment.builder() + .scanRuntimeClasspath("org.openrewrite.java.spring") + .build() + .activateRecipes("org.openrewrite.java.spring.boot2.SpringBoot1To2Migration") + + @Issue("https://github.com/openrewrite/rewrite-spring/issues/43") + @Test + fun springBootRunWithRemovedNoExtension() = assertChanged( + parser = JavaParser.fromJavaVersion() + .classpath("spring-boot-test", "junit-jupiter-api", "junit", "spring-test") + .logCompilationWarningsAndErrors(true) + + .build(), + recipe = Environment.builder() + .scanRuntimeClasspath("org.openrewrite.java.spring") + .build() + .activateRecipes("org.openrewrite.java.spring.boot2.SpringBoot1To2Migration"), + before = """ + package org.springframework.samples.petclinic.system; + + import org.junit.Test; + import org.junit.runner.RunWith; + import org.springframework.boot.test.context.SpringBootTest; + import org.springframework.test.context.junit4.SpringRunner; + + @SpringBootTest + @RunWith(SpringRunner.class) + public class ProductionConfigurationTests { + + @Test + public void testFindAll() { + } + } + """, + after = """ + package org.springframework.samples.petclinic.system; + + import org.junit.jupiter.api.Test; + import org.springframework.boot.test.context.SpringBootTest; + + @SpringBootTest + public class ProductionConfigurationTests { + + @Test + public void testFindAll() { + } + } + """ + ) +}