ClassIndex { public static Iterable<Class<?>> getPackageClasses(String packageName) { return getPackageClasses(packageName, Thread.currentThread().getContextClassLoader()); } private  ClassIndex(); @SuppressWarnings("unchecked") static Iterable<Class<? extends T>> getSubclasses(Class<T> superClass); @SuppressWarnings("unchecked") static Iterable<Class<? extends T>> getSubclasses(Class<T> superClass, ClassLoader classLoader); @SuppressWarnings("unchecked") static Iterable<String> getSubclassesNames(Class<T> superClass); @SuppressWarnings("unchecked") static Iterable<String> getSubclassesNames(Class<T> superClass, ClassLoader classLoader); static Iterable<Class<?>> getPackageClasses(String packageName); static Iterable<Class<?>> getPackageClasses(String packageName, ClassLoader classLoader); static Iterable<String> getPackageClassesNames(String packageName); static Iterable<String> getPackageClassesNames(String packageName, ClassLoader classLoader); static Iterable<Class<?>> getAnnotated(Class<? extends Annotation> annotation); static Iterable<Class<?>> getAnnotated(Class<? extends Annotation> annotation, ClassLoader classLoader); static Iterable<String> getAnnotatedNames(Class<? extends Annotation> annotation); static Iterable<String> getAnnotatedNames(Class<? extends Annotation> annotation, ClassLoader classLoader); static String getClassSummary(Class<?> klass); static String getClassSummary(Class<?> klass, ClassLoader classLoader); static final String SUBCLASS_INDEX_PREFIX; static final String ANNOTATED_INDEX_PREFIX; static final String PACKAGE_INDEX_NAME; static final String JAVADOC_PREFIX; }
@Test public void shouldIndexClassesInsidePackage() { Iterable<Class<?>> packageSubclasses = ClassIndex.getPackageClasses( ClassIndexTest.class.getPackage().getName()); assertThat(packageSubclasses).contains(FirstComponent.class, Component.class); assertThat(packageSubclasses).doesNotContain(Important.class); }
@Test public void shouldReadJaxbIndexCreatedByOlderVersions() { Iterable<Class<?>> packageSubclasses = ClassIndex.getPackageClasses(ExtraPlugin.class.getPackage().getName()); assertThat(packageSubclasses).contains(ExtraPlugin.class); }
@Test public void customProcessorShouldIndexPackages() { Iterable<Class<?>> classes = ClassIndex.getPackageClasses(ExtraPlugin.class.getPackage().getName()); assertThat(classes).containsOnly(ExtraPlugin.class); }