### Question:
ClassLoaderUtilities { public static List<Class<?>> loadRegisteredImplementations(String resourceName, ClassLoader classLoader) throws EngineException { return loadRegisteredImplementations(resourceName, Object.class, classLoader); }  static List<String> allResourceLines(ClassLoader classLoader,
                                              String resourceName); static List<Class<?>> loadRegisteredImplementations(String resourceName,
                                  ClassLoader classLoader); static List<Class<? extends T>> loadRegisteredImplementations(String resourceName,
                                  Class<T> cls); @SuppressWarnings("unchecked") static List<Class<? extends T>> loadRegisteredImplementations(String resourceName,
                                  Class<T> cls,
                                  ClassLoader classLoader);  }### Answer:
@Test public void testUnknownImplementation() throws Exception { final File path = new File(getDirectory(), "cp"); final String RESOURCE_NAME = "my.resource"; createFile(new File(path, RESOURCE_NAME), "bobbins"); final List<URL> additionalClasspath = asList(new File(getDirectory(), "cp").toURI().toURL()); final ClassLoader blockingLoader = new BlockingClassLoader( additionalClasspath, Collections.<String>emptySet(), new HashSet<String>( asList(RESOURCE_NAME)), Collections.<String>emptySet(), true); try { loadRegisteredImplementations(RESOURCE_NAME, Object.class, blockingLoader); fail("Expected EngineException"); } catch (EngineException e) { assertTrue(e.getCause() instanceof ClassNotFoundException); } }
@Test public void testBadImplementation() throws Exception { final File path = new File(getDirectory(), "cp"); final String RESOURCE_NAME = "my.resource"; createFile(new File(path, RESOURCE_NAME), "java.lang.Object"); final List<URL> additionalClasspath = asList(new File(getDirectory(), "cp").toURI().toURL()); final ClassLoader blockingLoader = new BlockingClassLoader( additionalClasspath, Collections.<String>emptySet(), new HashSet<String>( asList(RESOURCE_NAME)), Collections.<String>emptySet(), true); try { loadRegisteredImplementations(RESOURCE_NAME, Integer.class, blockingLoader); fail("Expected EngineException"); } catch (EngineException e) { assertContains(e.getMessage(), "does not implement"); } }
@SuppressWarnings("unchecked") @Test public void testGoodImplementations() throws Exception { final File path = new File(getDirectory(), "cp"); final String RESOURCE_NAME = "my.resource"; createFile(new File(path, RESOURCE_NAME), "java.lang.Integer", "# hello", "java.lang.Long", "java.lang.Long", "java.lang.Integer"); final List<URL> additionalClasspath = asList(new File(getDirectory(), "cp").toURI().toURL()); final ClassLoader blockingLoader = new BlockingClassLoader( additionalClasspath, Collections.<String>emptySet(), new HashSet<String>( asList(RESOURCE_NAME)), Collections.<String>emptySet(), true); final List<Class<? extends Number>> classes = loadRegisteredImplementations(RESOURCE_NAME, Number.class, blockingLoader); assertEquals(asList(Integer.class, Long.class), classes); }