Skip to content

Test verifies pom with empty properties section can be parsed #769

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

Merged
Merged
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 @@ -21,6 +21,7 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.sbm.GitHubIssue;
import org.springframework.sbm.build.api.BuildFile;
import org.springframework.sbm.build.api.DependenciesChangedEvent;
import org.springframework.sbm.build.api.Dependency;
Expand Down Expand Up @@ -2655,26 +2656,27 @@ void hasParentWithParentShouldReturnParent() {

@Test
void upgradeParentVersion() {
String pomXml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" +
" <modelVersion>4.0.0</modelVersion>\n" +
" <parent>\n" +
" <groupId>org.springframework.boot</groupId>\n" +
" <artifactId>spring-boot-starter-parent</artifactId>\n" +
" <version>2.4.12</version>\n" +
" <relativePath/> <!-- lookup parent from repository -->\n" +
" </parent>\n" +
" <groupId>com.example</groupId>\n" +
" <artifactId>spring-boot-24-to-25-example</artifactId>\n" +
" <version>0.0.1-SNAPSHOT</version>\n" +
" <name>spring-boot-2.4-to-2.5-example</name>\n" +
" <description>spring-boot-2.4-to-2.5-example</description>\n" +
" <properties>\n" +
" <java.version>11</java.version>\n" +
" </properties>\n" +
"</project>\n";
String pomXml = """
<?xml version="1.0" encoding="UTF-8"?>
<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.4.12</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>spring-boot-24-to-25-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-2.4-to-2.5-example</name>
<description>spring-boot-2.4-to-2.5-example</description>
<properties>
<java.version>11</java.version>
</properties>
</project>
""";

BuildFile openRewriteMavenBuildFile = TestProjectContext.buildProjectContext().withMavenRootBuildFileSource(pomXml).build().getBuildFile();

Expand All @@ -2683,4 +2685,25 @@ void upgradeParentVersion() {
assertThat(openRewriteMavenBuildFile.getParentPomDeclaration()).isNotEmpty();
assertThat(openRewriteMavenBuildFile.getParentPomDeclaration().get().getVersion()).isEqualTo("2.5.6");
}

@GitHubIssue("https://github.com/spring-projects-experimental/spring-boot-migrator/issues/55")
@Test
void parsingPomWithEmptyPropertiesSectionShouldSucceed() {
String pomXml = """
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.12</version>
<properties>

</properties>
</project>
""";

ProjectContext projectContext = TestProjectContext.buildProjectContext().withMavenRootBuildFileSource(pomXml).build();
assertThat(projectContext.getApplicationModules().getRootModule().getBuildFile()).isNotNull();
}
}