From 62e0194aa16638027ab9409fb7cbcb0e15dab4f5 Mon Sep 17 00:00:00 2001 From: eocantu Date: Sun, 23 Jun 2024 04:58:28 -0500 Subject: [PATCH] Remove classifier on dependency added migrating LocalServerPort (#544) * Remove classifier on dependency added migrating LocalServerPort Fixes https://github.com/openrewrite/rewrite-spring/issues/541 * Verify dependency is added --------- Co-authored-by: Tim te Beek --- .../MigrateLocalServerPortAnnotation.java | 2 +- .../MigrateLocalServerPortAnnotationTest.java | 85 ++++++++++++++++++- 2 files changed, 83 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/openrewrite/java/spring/boot2/MigrateLocalServerPortAnnotation.java b/src/main/java/org/openrewrite/java/spring/boot2/MigrateLocalServerPortAnnotation.java index a21d84c1..b77adaef 100644 --- a/src/main/java/org/openrewrite/java/spring/boot2/MigrateLocalServerPortAnnotation.java +++ b/src/main/java/org/openrewrite/java/spring/boot2/MigrateLocalServerPortAnnotation.java @@ -68,7 +68,7 @@ public List getRecipeList() { "2.0.x", null, "org.springframework.boot.web.server.LocalServerPort", - "org.springframework.boot.web.server.LocalServerPort", + null, null, null, null, null, null, null, null, null)); } diff --git a/src/testWithSpringBoot_1_5/java/org/openrewrite/java/spring/boot2/MigrateLocalServerPortAnnotationTest.java b/src/testWithSpringBoot_1_5/java/org/openrewrite/java/spring/boot2/MigrateLocalServerPortAnnotationTest.java index 738ac328..f29305c5 100644 --- a/src/testWithSpringBoot_1_5/java/org/openrewrite/java/spring/boot2/MigrateLocalServerPortAnnotationTest.java +++ b/src/testWithSpringBoot_1_5/java/org/openrewrite/java/spring/boot2/MigrateLocalServerPortAnnotationTest.java @@ -21,7 +21,8 @@ import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; -import static org.openrewrite.java.Assertions.java; +import static org.openrewrite.java.Assertions.*; +import static org.openrewrite.maven.Assertions.pomXml; class MigrateLocalServerPortAnnotationTest implements RewriteTest { @Override @@ -32,7 +33,7 @@ public void defaults(RecipeSpec spec) { @Issue("https://github.com/openrewrite/rewrite-spring/issues/116") @Test - void givenHasStringVariableWhenRemovingDeprecatedThenReplacesAddEnvironmentWithSetProperties() { + void shouldReplaceType() { //language=java rewriteRun( java( @@ -46,7 +47,7 @@ public class RandomTestClass { """, """ import org.springframework.boot.web.server.LocalServerPort; - + public class RandomTestClass { @LocalServerPort private int port; @@ -55,4 +56,82 @@ public class RandomTestClass { ) ); } + + @Issue("https://github.com/openrewrite/rewrite-spring/issues/541") + @Test + void shouldAddDependencyCorrectly() { + rewriteRun( + spec -> spec.expectedCyclesThatMakeChanges(2), + mavenProject("project", + srcMainJava( + //language=Java + java( + """ + import org.springframework.boot.context.embedded.LocalServerPort; + + class RandomTestClass { + @LocalServerPort + private int port; + } + """, + """ + import org.springframework.boot.web.server.LocalServerPort; + + class RandomTestClass { + @LocalServerPort + private int port; + } + """ + ) + ), + //language=XML + pomXml( + """ + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.0.9.RELEASE + + + com.example + acme + 0.0.1-SNAPSHOT + + + org.springframework.boot + spring-boot-starter + + + + """, + """ + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.0.9.RELEASE + + + com.example + acme + 0.0.1-SNAPSHOT + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-web + + + + """ + ) + ) + ); + } }