Skip to content

Commit 8caed88

Browse files
committed
Test status quo for URI/URL for scanned filesystem resources
See gh-29275
1 parent 3dc60f1 commit 8caed88

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ void usingFileProtocol() {
108108
assertExactFilenames(pattern, "resource#test1.txt", "resource#test2.txt");
109109
assertExactSubPaths(pattern, pathPrefix, "resource#test1.txt", "resource#test2.txt");
110110
}
111+
112+
@Test
113+
void usingFileProtocolAndAssertingUrlAndUriSyntax() throws Exception {
114+
Path testResourcesDir = Paths.get("src/test/resources").toAbsolutePath();
115+
String pattern = String.format("file:%s/scanned-resources/**/resource#test1.txt", testResourcesDir);
116+
Resource[] resources = resolver.getResources(pattern);
117+
assertThat(resources).hasSize(1);
118+
Resource resource = resources[0];
119+
assertThat(resource.getFilename()).isEqualTo("resource#test1.txt");
120+
// The following assertions serve as regression tests for the lack of the
121+
// "authority component" (//) in the returned URI/URL. For example, we are
122+
// expecting file:/my/path (or file:/C:/My/Path) instead of file:///my/path.
123+
assertThat(resource.getURL().toString()).matches("^file:\\/[^\\/].+test1\\.txt$");
124+
assertThat(resource.getURI().toString()).matches("^file:\\/[^\\/].+test1\\.txt$");
125+
}
111126
}
112127
}
113128

0 commit comments

Comments
 (0)