### Question:
BlockingClassLoader extends URLClassLoader { @Override public URL getResource(String name) { if (!m_shared.matches(name, true)) { if (m_respectGrandparents) { final URL grandParentResult = getParent().getParent().getResource(name); if (grandParentResult != null) { return grandParentResult; } } if (m_blocked.matches(name, true)) { return null; } if (m_isolated.matches(name, true)) { return findResource(name); } } return super.getResource(name); } BlockingClassLoader(URLClassLoader parent,
                             List<URL> additionalClassPath,
                             Set<String> blocked,
                             Set<String> isolated,
                             Set<String> shared,
                             boolean respectGrandparents);  BlockingClassLoader(List<URL> additionalClassPath,
                             Set<String> blocked,
                             Set<String> isolated,
                             Set<String> shared,
                             boolean respectGrandparents);  BlockingClassLoader(Set<String> blocked,
                             Set<String> isolated,
                             Set<String> shared,
                             boolean respectGrandparents); @Override URL getResource(String name); @Override Enumeration<URL> getResources(String name);  }### Answer:
@Test public void testGetResource() throws Exception { final String resourceName = "TestResources.properties"; assertNotNull(getClass().getClassLoader().getResource(resourceName)); final BlockingClassLoader cl = new BlockingClassLoader(singleton(resourceName), Collections.<String>emptySet(), Collections.<String>emptySet(), false); assertNull(cl.getResource(resourceName)); assertNull(cl.getResource("Something else")); }
@Test public void testGetResource2() throws Exception { final String resourceName = "TestResources.properties"; assertNotNull(getClass().getClassLoader().getResource(resourceName)); final URLClassLoader grandParentLoader = (URLClassLoader)getClass().getClassLoader(); final URLClassLoader parentLoader = new URLClassLoader(grandParentLoader.getURLs(), grandParentLoader); final BlockingClassLoader cl = new BlockingClassLoader(parentLoader, Collections.<URL>emptyList(), singleton(resourceName), Collections.<String>emptySet(), Collections.<String>emptySet(), true); assertNotNull(cl.getResource(resourceName)); assertNull(cl.getResource("Something else")); }
@Test public void testGetResource3() throws Exception { final String resourceName = "TestResources.properties"; assertNotNull(getClass().getClassLoader().getResource(resourceName)); final BlockingClassLoader cl = new BlockingClassLoader(singleton(resourceName), singleton(resourceName), singleton(resourceName), false); assertNotNull(cl.getResource(resourceName)); assertNull(cl.getResource("Something else")); }