From 1653ec3b449ac81360dae9f916cc9aa18badea4c Mon Sep 17 00:00:00 2001 From: Park Sung Jun Date: Mon, 1 Sep 2025 00:06:56 +0900 Subject: [PATCH] Add tests for applyRelativePath method in StringUtils Closes gh-35397 Signed-off-by: Park Sung Jun --- .../util/StringUtilsTests.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spring-core/src/test/java/org/springframework/util/StringUtilsTests.java b/spring-core/src/test/java/org/springframework/util/StringUtilsTests.java index bdfd1ca82b5..0d9376bf74f 100644 --- a/spring-core/src/test/java/org/springframework/util/StringUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/util/StringUtilsTests.java @@ -794,6 +794,25 @@ class StringUtilsTests { assertThat(StringUtils.collectionToCommaDelimitedString(Collections.singletonList(null))).isEqualTo("null"); } + @Test + void applyRelativePath() { + // Basic combination + assertThat(StringUtils.applyRelativePath("mypath/myfile", "otherfile")).isEqualTo("mypath/otherfile"); + // Relative path starts with slash + assertThat(StringUtils.applyRelativePath("mypath/myfile", "/otherfile")).isEqualTo("mypath/otherfile"); + // Includes root path + assertThat(StringUtils.applyRelativePath("/mypath/myfile", "otherfile")).isEqualTo("/mypath/otherfile"); + assertThat(StringUtils.applyRelativePath("/mypath/myfile", "/otherfile")).isEqualTo("/mypath/otherfile"); + // When base path has no slash + assertThat(StringUtils.applyRelativePath("myfile", "otherfile")).isEqualTo("otherfile"); + // Keep parent directory token as-is + assertThat(StringUtils.applyRelativePath("mypath/myfile", "../otherfile")).isEqualTo("mypath/../otherfile"); + // Base path ends with slash + assertThat(StringUtils.applyRelativePath("mypath/", "otherfile")).isEqualTo("mypath/otherfile"); + // Empty relative path + assertThat(StringUtils.applyRelativePath("mypath/myfile", "")).isEqualTo("mypath/"); + } + @Test void truncatePreconditions() { assertThatIllegalArgumentException()