ResourceLoader { public URL getResource(String resource) { resource = resource.trim(); URL result = Thread.currentThread().getContextClassLoader().getResource(resource); if (result == null) { ClassLoader classLoader = ResourceLoader.class.getClassLoader(); if (classLoader != null) { result = classLoader.getResource(resource); } } if (result == null) { result = ClassLoader.getSystemResource(resource); } if (result == null && StringUtils.contains(resource, ":")) { try { result = new URL(resource); } catch (MalformedURLException e) { MappingUtils.throwMappingException(e); } } return result; } ResourceLoader(ClassLoader classLoader); URL getResource(String resource);  }
@Test public void testResourceNotFound() { assertNull("file URL should not have been found", loader.getResource(String.valueOf(System.currentTimeMillis()))); }
@Test public void testGetResourceWithWhitespace() { URL url = loader.getResource("mappings/contextMapping.xml "); assertNotNull("URL should not be null", url); }
@Test public void testGetResource_FileOutsideOfClasspath() throws Exception { File temp = File.createTempFile("dozerfiletest", ".txt"); temp.deleteOnExit(); String resourceName = "file:" + temp.getAbsolutePath(); URL url = loader.getResource(resourceName); assertNotNull("URL should not be null", url); InputStream is = url.openStream(); assertNotNull("input stream should not be null", is); }
@Test(expected = MappingException.class) public void testGetResouce_MalformedUrl() { loader.getResource("foo:bar"); }
@Test(expected = IOException.class) public void testGetResource_FileOutsideOfClasspath_NotFound() throws Exception { URL url = loader.getResource("file:" + System.currentTimeMillis()); assertNotNull("URL should not be null", url); url.openStream(); }
@Test public void testGetResource_FileOutsideOfClasspath_InvalidFormat() { URL url = loader.getResource(String.valueOf(System.currentTimeMillis())); assertNull("URL should be null", url); }