FileSystemResource supports java.nio.file.Path based setup

Issue: SPR-16833
This commit is contained in:
Juergen Hoeller
2018-06-15 22:12:14 +02:00
parent bb6ab5dc91
commit 38f9a7b072
3 changed files with 86 additions and 36 deletions

View File

@@ -23,6 +23,8 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashSet;
import org.junit.Ignore;
@@ -128,6 +130,16 @@ public class ResourceTests {
assertEquals(resource2, new FileSystemResource("core/../core/io/./Resource.class"));
}
@Test
public void testFileSystemResourceWithFilePath() throws Exception {
Path filePath = Paths.get(getClass().getResource("Resource.class").toURI());
Resource resource = new FileSystemResource(filePath);
doTestResource(resource);
assertEquals(new FileSystemResource(filePath), resource);
Resource resource2 = new FileSystemResource("core/io/Resource.class");
assertEquals(resource2, new FileSystemResource("core/../core/io/./Resource.class"));
}
@Test
public void testUrlResource() throws IOException {
Resource resource = new UrlResource(getClass().getResource("Resource.class"));