### Question:
AlternativeDirectoryResourceLoader implements AlternativeResourceLoader { public URL getResource(String path) { for (File dir : resourceDirectories) { File file = new File(dir, path); if (file.exists()) { try { return file.toURI().toURL(); } catch (MalformedURLException e) { log.error("Malformed URL: " + file.toString(), e); } } else { log.debug("File " + file + " not found, ignoring"); } } return null; } AlternativeDirectoryResourceLoader(); URL getResource(String path); InputStream getResourceAsStream(String name); List<File> getResourceDirectories(); static final String PLUGIN_RESOURCE_DIRECTORIES; }### Answer:
@Ignore @Test public void testGetResource() throws MalformedURLException { try { System.setProperty(AlternativeDirectoryResourceLoader.PLUGIN_RESOURCE_DIRECTORIES, base.getAbsolutePath()); AlternativeResourceLoader loader = new AlternativeDirectoryResourceLoader(); assertEquals(new File(base, "classes").toURI().toURL(), loader.getResource("classes")); assertNull(loader.getResource("asdfasdfasf")); } finally { System.getProperties().remove(AlternativeDirectoryResourceLoader.PLUGIN_RESOURCE_DIRECTORIES); } }
@Test public void testGetResourceNoProperty() throws MalformedURLException { AlternativeResourceLoader loader = new AlternativeDirectoryResourceLoader(); assertNull(loader.getResource("classes")); assertNull(loader.getResource("asdfasdfasf")); }
@Ignore @Test public void testGetResourceWithTwoDefined() throws MalformedURLException { try { File classesDir = new File(base, "classes"); System.setProperty(AlternativeDirectoryResourceLoader.PLUGIN_RESOURCE_DIRECTORIES, base.getAbsolutePath() + "," + classesDir.getAbsolutePath()); AlternativeResourceLoader loader = new AlternativeDirectoryResourceLoader(); assertEquals(new File(base, "classes").toURI().toURL(), loader.getResource("classes")); assertEquals(new File(classesDir, "com").toURI().toURL(), loader.getResource("com")); assertNull(loader.getResource("asdfasdfasf")); } finally { System.getProperties().remove(AlternativeDirectoryResourceLoader.PLUGIN_RESOURCE_DIRECTORIES); } }