File tree 1 file changed +21
-0
lines changed
spring-core/src/test/java/org/springframework/core/io
1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -252,6 +252,27 @@ void readableChannelProvidesContent() throws Exception {
252
252
}
253
253
}
254
254
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
+ }
255
276
}
256
277
257
278
@ Nested
You can’t perform that action at this time.
0 commit comments