Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove classifier on dependency added migrating LocalServerPort #544

Merged
merged 2 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
"""
)
)
);
}
}