Skip to content

Commit 5a3713b

Browse files
authored
Test verifies pom with empty properties section can be parsed (#769)
* style: Replace concatenated with multiline String * test: Test that verifies that #55 is fixed
1 parent b9ed487 commit 5a3713b

File tree

1 file changed

+43
-20
lines changed

1 file changed

+43
-20
lines changed

components/sbm-core/src/test/java/org/springframework/sbm/project/buildfile/OpenRewriteMavenBuildFileTest.java

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.mockito.ArgumentCaptor;
2222
import org.mockito.Mockito;
2323
import org.springframework.context.ApplicationEventPublisher;
24+
import org.springframework.sbm.GitHubIssue;
2425
import org.springframework.sbm.build.api.BuildFile;
2526
import org.springframework.sbm.build.api.DependenciesChangedEvent;
2627
import org.springframework.sbm.build.api.Dependency;
@@ -2655,26 +2656,27 @@ void hasParentWithParentShouldReturnParent() {
26552656

26562657
@Test
26572658
void upgradeParentVersion() {
2658-
String pomXml =
2659-
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
2660-
"<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
2661-
" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" +
2662-
" <modelVersion>4.0.0</modelVersion>\n" +
2663-
" <parent>\n" +
2664-
" <groupId>org.springframework.boot</groupId>\n" +
2665-
" <artifactId>spring-boot-starter-parent</artifactId>\n" +
2666-
" <version>2.4.12</version>\n" +
2667-
" <relativePath/> <!-- lookup parent from repository -->\n" +
2668-
" </parent>\n" +
2669-
" <groupId>com.example</groupId>\n" +
2670-
" <artifactId>spring-boot-24-to-25-example</artifactId>\n" +
2671-
" <version>0.0.1-SNAPSHOT</version>\n" +
2672-
" <name>spring-boot-2.4-to-2.5-example</name>\n" +
2673-
" <description>spring-boot-2.4-to-2.5-example</description>\n" +
2674-
" <properties>\n" +
2675-
" <java.version>11</java.version>\n" +
2676-
" </properties>\n" +
2677-
"</project>\n";
2659+
String pomXml = """
2660+
<?xml version="1.0" encoding="UTF-8"?>
2661+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2662+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2663+
<modelVersion>4.0.0</modelVersion>
2664+
<parent>
2665+
<groupId>org.springframework.boot</groupId>
2666+
<artifactId>spring-boot-starter-parent</artifactId>
2667+
<version>2.4.12</version>
2668+
<relativePath/> <!-- lookup parent from repository -->
2669+
</parent>
2670+
<groupId>com.example</groupId>
2671+
<artifactId>spring-boot-24-to-25-example</artifactId>
2672+
<version>0.0.1-SNAPSHOT</version>
2673+
<name>spring-boot-2.4-to-2.5-example</name>
2674+
<description>spring-boot-2.4-to-2.5-example</description>
2675+
<properties>
2676+
<java.version>11</java.version>
2677+
</properties>
2678+
</project>
2679+
""";
26782680

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

@@ -2683,4 +2685,25 @@ void upgradeParentVersion() {
26832685
assertThat(openRewriteMavenBuildFile.getParentPomDeclaration()).isNotEmpty();
26842686
assertThat(openRewriteMavenBuildFile.getParentPomDeclaration().get().getVersion()).isEqualTo("2.5.6");
26852687
}
2688+
2689+
@GitHubIssue("https://github.com/spring-projects-experimental/spring-boot-migrator/issues/55")
2690+
@Test
2691+
void parsingPomWithEmptyPropertiesSectionShouldSucceed() {
2692+
String pomXml = """
2693+
<?xml version="1.0" encoding="UTF-8"?>
2694+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2695+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2696+
<modelVersion>4.0.0</modelVersion>
2697+
<groupId>org.springframework.boot</groupId>
2698+
<artifactId>spring-boot-starter-parent</artifactId>
2699+
<version>2.4.12</version>
2700+
<properties>
2701+
2702+
</properties>
2703+
</project>
2704+
""";
2705+
2706+
ProjectContext projectContext = TestProjectContext.buildProjectContext().withMavenRootBuildFileSource(pomXml).build();
2707+
assertThat(projectContext.getApplicationModules().getRootModule().getBuildFile()).isNotNull();
2708+
}
26862709
}

0 commit comments

Comments
 (0)