Skip to content

Commit 6698943

Browse files
committed
Introduce unit tests for spring-projectsgh-29275
1 parent 23b3fc7 commit 6698943

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

spring-core/src/test/java/org/springframework/core/io/ResourceTests.java

+21
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,27 @@ void readableChannelProvidesContent() throws Exception {
252252
}
253253
}
254254

255+
@Test
256+
void urlAndUriAreNormalizedWhenCreatedFromFile() throws Exception {
257+
Path path = Path.of("src/test/resources/scanned-resources/resource#test1.txt").toAbsolutePath();
258+
assertUrlAndUriBehavior(new FileSystemResource(path.toFile()));
259+
}
260+
261+
@Test
262+
void urlAndUriAreNormalizedWhenCreatedFromPath() throws Exception {
263+
Path path = Path.of("src/test/resources/scanned-resources/resource#test1.txt").toAbsolutePath();
264+
assertUrlAndUriBehavior(new FileSystemResource(path));
265+
}
266+
267+
/**
268+
* The following assertions serve as regression tests for the lack of the
269+
* "authority component" (//) in the returned URI/URL. For example, we are
270+
* expecting file:/my/path (or file:/C:/My/Path) instead of file:///my/path.
271+
*/
272+
private void assertUrlAndUriBehavior(Resource resource) throws IOException {
273+
assertThat(resource.getURL().toString()).matches("^file:\\/[^\\/].+test1\\.txt$");
274+
assertThat(resource.getURI().toString()).matches("^file:\\/[^\\/].+test1\\.txt$");
275+
}
255276
}
256277

257278
@Nested

0 commit comments

Comments
 (0)