Skip to content

Commit 1653ec3

Browse files
J-unStiNbclozel
authored andcommitted
Add tests for applyRelativePath method in StringUtils
Closes gh-35397 Signed-off-by: Park Sung Jun <[email protected]>
1 parent 746fc33 commit 1653ec3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

spring-core/src/test/java/org/springframework/util/StringUtilsTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,25 @@ void collectionToDelimitedStringWithNullValuesShouldNotFail() {
794794
assertThat(StringUtils.collectionToCommaDelimitedString(Collections.singletonList(null))).isEqualTo("null");
795795
}
796796

797+
@Test
798+
void applyRelativePath() {
799+
// Basic combination
800+
assertThat(StringUtils.applyRelativePath("mypath/myfile", "otherfile")).isEqualTo("mypath/otherfile");
801+
// Relative path starts with slash
802+
assertThat(StringUtils.applyRelativePath("mypath/myfile", "/otherfile")).isEqualTo("mypath/otherfile");
803+
// Includes root path
804+
assertThat(StringUtils.applyRelativePath("/mypath/myfile", "otherfile")).isEqualTo("/mypath/otherfile");
805+
assertThat(StringUtils.applyRelativePath("/mypath/myfile", "/otherfile")).isEqualTo("/mypath/otherfile");
806+
// When base path has no slash
807+
assertThat(StringUtils.applyRelativePath("myfile", "otherfile")).isEqualTo("otherfile");
808+
// Keep parent directory token as-is
809+
assertThat(StringUtils.applyRelativePath("mypath/myfile", "../otherfile")).isEqualTo("mypath/../otherfile");
810+
// Base path ends with slash
811+
assertThat(StringUtils.applyRelativePath("mypath/", "otherfile")).isEqualTo("mypath/otherfile");
812+
// Empty relative path
813+
assertThat(StringUtils.applyRelativePath("mypath/myfile", "")).isEqualTo("mypath/");
814+
}
815+
797816
@Test
798817
void truncatePreconditions() {
799818
assertThatIllegalArgumentException()

0 commit comments

Comments
 (0)