Skip to content

Commit

Permalink
Remove classifier on dependency added migrating LocalServerPort (#544)
Browse files Browse the repository at this point in the history
* Remove classifier on dependency added migrating LocalServerPort

Fixes #541

* Verify dependency is added

---------

Co-authored-by: Tim te Beek <tim@moderne.io>
  • Loading branch information
eocantu and timtebeek authored Jun 23, 2024
1 parent 1687fe9 commit 62e0194
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public List<Recipe> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -46,7 +47,7 @@ public class RandomTestClass {
""",
"""
import org.springframework.boot.web.server.LocalServerPort;
public class RandomTestClass {
@LocalServerPort
private int port;
Expand All @@ -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(
"""
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.9.RELEASE</version>
<relativePath/>
</parent>
<groupId>com.example</groupId>
<artifactId>acme</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>
</project>
""",
"""
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.9.RELEASE</version>
<relativePath/>
</parent>
<groupId>com.example</groupId>
<artifactId>acme</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
"""
)
)
);
}
}

0 comments on commit 62e0194

Please sign in to comment.