Deprecated as of 4.3.13, in favor of selective use of ClassPathResource.ClassPathResource(String, ClassLoader) vs ClassPathResource.ClassPathResource(String, Class)
@Test(expected = FileNotFoundException.class) public void testInputStreamNotFoundOnClassPathResource() throws IOException { new ClassPathResource("Resource.class", getClass()).createRelative("X").getInputStream(); }
@Test(expected = FileNotFoundException.class) public void testReadableChannelNotFoundOnClassPathResource() throws IOException { new ClassPathResource("Resource.class", getClass()).createRelative("X").readableChannel(); }
@Test public void testClassPathResource() throws IOException { Resource resource = new ClassPathResource("org/springframework/core/io/Resource.class"); doTestResource(resource); Resource resource2 = new ClassPathResource("org/springframework/core/../core/io/./Resource.class"); assertEquals(resource, resource2); Resource resource3 = new ClassPathResource("org/springframework/core/").createRelative("../core/io/./Resource.class"); assertEquals(resource, resource3); // Check whether equal/hashCode works in a HashSet. HashSet<Resource> resources = new HashSet<>(); resources.add(resource); resources.add(resource2); assertEquals(1, resources.size()); }
@Test public void preserveLeadingSlashForClassRelativeAccess() { assertEquals("/test.html", new ClassPathResource("/test.html", getClass()).getPath()); assertEquals("/test.html", ((ClassPathResource) new ClassPathResource("", getClass()).createRelative("/test.html")).getPath()); }
@Test public void dropLeadingSlashForClassLoaderAccess() { assertEquals("test.html", new ClassPathResource("/test.html").getPath()); assertEquals("test.html", ((ClassPathResource) new ClassPathResource("").createRelative("/test.html")).getPath()); }
public Resource createRelative(String relativePath) throws IOException { // delegate to ClassPathResource return classPathResource.createRelative(relativePath); }