AnnotationScanner { public Set<Class<?>> scanClasses() { final Set<Class<?>> classes = new HashSet<Class<?>>(); for (String pkg : packages) { final Reflections reflections = new Reflections(new ConfigurationBuilder() .addUrls(forClass(Path.class)) .addUrls(forPackage(pkg)) .setScanners(new SubTypesScanner(), new TypeAnnotationsScanner()) .filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(pkg)))); classes.addAll(reflections.getTypesAnnotatedWith(Path.class)); } return classes; } AnnotationScanner();  AnnotationScanner(Set<String> packages); Set<Class<?>> scanClasses();  }
@Test public void testScanningOnePackage() throws Exception { Collection<Class<?>> classes = new AnnotationScanner(new HashSet<String>( Arrays.asList("de.otto.jsonhome.fixtures.one"))).scanClasses(); assertEquals(2, classes.size()); }
@Test public void testScanningTwoPackages() throws Exception { Collection<Class<?>> classes = new AnnotationScanner(new HashSet<String>( Arrays. asList("de.otto.jsonhome.fixtures.one", "de.otto.jsonhome.fixtures.two"))).scanClasses(); assertEquals(4, classes.size()); }
@Test public void testScanningNotExistingPackage() throws Exception { Collection<Class<?>> classes = new AnnotationScanner(new HashSet<String>( Arrays. asList("de.otto.jsonhome.fixtures.none"))).scanClasses(); assertTrue(classes.isEmpty()); }