### Question:
ClassLoaderUtilities { public static List<String> allResourceLines(ClassLoader classLoader, String resourceName) throws IOException { final List<String> result = new ArrayList<String>(); final Enumeration<URL> resources = classLoader.getResources(resourceName); final Set<String> seenURLs = new HashSet<String>(); while (resources.hasMoreElements()) { final URL url = resources.nextElement(); final String urlString = url.toString(); if (seenURLs.contains(urlString)) { continue; } seenURLs.add(urlString); final InputStream in = url.openStream(); try { final BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8")); while (true) { String line = reader.readLine(); if (line == null) { break; } final int comment = line.indexOf('#'); if (comment >= 0) { line = line.substring(0, comment); } line = line.trim(); if (line.length() > 0) { result.add(line); } } reader.close(); } finally { in.close(); } } return result; }  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 testAllResourceLinesNoResources() throws Exception { final List<String> resourceLines = allResourceLines(getClass().getClassLoader(), "test/foo"); assertEquals(0, resourceLines.size()); }
@Test public void testAllResourceLinesResources() throws Exception { final File d1 = new File(getDirectory(), "one"); createFile(new File(d1, "test/foo"), "a", "# Some comment", "b", ""); final File d2 = new File(getDirectory(), "two"); createFile(new File(d2, "test/foo"), "a", "c # Another comment"); final ClassLoader cl1 = new URLClassLoader(new URL[] { d1.toURI().toURL() }); final ClassLoader cl2 = new URLClassLoader(new URL[] { d1.toURI().toURL(), d2.toURI().toURL()}); assertEquals(asList("a", "b"), allResourceLines(cl1, "test/foo")); assertEquals(asList("a", "b", "a", "c"), allResourceLines(cl2, "test/foo")); }
@Test public void filterDuplicateURLs() throws Exception { final File d1 = new File(getDirectory(), "one"); createFile(new File(d1, "test/foo"), "a"); final URLClassLoader cl1 = new URLClassLoader(new URL[] { d1.toURI().toURL() }); final URLClassLoader cl2 = new URLClassLoader(cl1.getURLs(), cl1); assertEquals(asList("a"), allResourceLines(cl2, "test/foo")); }