### Question:
Scanner { public void scanClasspath(ClassLoader classLoader) throws IOException { if (!(classLoader instanceof URLClassLoader)) { LOGGER.warn("Not scanning classpath for ClassLoader '" + classLoader.getClass().getName() + "'. ClassLoader must implement '" + URLClassLoader.class.getName() + "'."); return; } URL[] urls = ((URLClassLoader) classLoader).getURLs(); Set<String> alreadyScanned = new HashSet<String>(); for (URL url : urls) { String urlPath = url.getFile(); urlPath = URLDecoder.decode(urlPath, "UTF-8"); if (urlPath.startsWith("file:")) { urlPath = urlPath.substring(5); } if (urlPath.indexOf('!') > 0) { urlPath = urlPath.substring(0, urlPath.indexOf('!')); } File file = new File(urlPath); if(alreadyScanned.contains(file.getAbsolutePath())) { LOGGER.debug("Ignoring classpath URL '" + file.getAbsolutePath() + "'. Already scanned this URL."); continue; } if (file.isDirectory()) { handleDirectory(file, null); } else { handleArchive(file); } alreadyScanned.add(file.getAbsolutePath()); } } Scanner(Filter filter); void scanClasspath(ClassLoader classLoader);  }### Answer:
@Test public void test_instanceof_has_include() throws IOException { InstanceOfFilter filter = new InstanceOfFilter(Filter.class, null, new String[] {"org/smooks"}); Scanner scanner = new Scanner(filter); long start = System.currentTimeMillis(); scanner.scanClasspath(classLoader); LOGGER.debug("Took: " + (System.currentTimeMillis() - start)); List<Class> classes = filter.getClasses(); LOGGER.debug(classes.toString()); assertEquals(4, classes.size()); assertTrue(classes.contains(InstanceOfFilter.class)); assertTrue(classes.contains(IsAnnotationPresentFilter.class)); assertTrue(classes.contains(AbstractFilter.class)); assertTrue(classes.contains(Filter.class)); }
@Test public void test_annotated_has_include() throws IOException { IsAnnotationPresentFilter filter = new IsAnnotationPresentFilter(TestAnnotation.class, null, new String[] {"org/smooks"}); Scanner scanner = new Scanner(filter); long start = System.currentTimeMillis(); scanner.scanClasspath(classLoader); LOGGER.debug("Took: " + (System.currentTimeMillis() - start)); List<Class> classes = filter.getClasses(); LOGGER.debug(classes.toString()); assertEquals(2, classes.size()); assertTrue(classes.contains(AnnotatedClass1.class)); assertTrue(classes.contains(AnnotatedClass1.class)); }
@Test public void test_instanceof_no_include() throws IOException { InstanceOfFilter filter = new InstanceOfFilter(Filter.class); Scanner scanner = new Scanner(filter); long start = System.currentTimeMillis(); scanner.scanClasspath(classLoader); LOGGER.debug("Took: " + (System.currentTimeMillis() - start)); List<Class> classes = filter.getClasses(); LOGGER.debug(classes.toString()); assertEquals(4, classes.size()); assertTrue(classes.contains(InstanceOfFilter.class)); assertTrue(classes.contains(IsAnnotationPresentFilter.class)); assertTrue(classes.contains(AbstractFilter.class)); assertTrue(classes.contains(Filter.class)); }