ClassIndex { public static Iterable<Class<?>> getAnnotated(Class<? extends Annotation> annotation) { return getAnnotated(annotation, 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 shouldIndexAnnotated() { Iterable<Class<?>> annotated = ClassIndex.getAnnotated(Component.class); assertThat(annotated).containsOnly(FirstComponent.class, SecondComponent.class, InnerClasses.InnerComponent.class, InnerClasses.InnerComponent.InnerInnerComponent.class); }
@Test public void shouldIndexWhenAnnotationIsInherited() { Iterable<Class<?>> annotated = ClassIndex.getAnnotated(InheritedAnnotation.class); assertThat(annotated).containsOnly(Service.class, FirstService.class, SecondService.class, InnerClasses.InnerService.class); }
@Test public void customProcessorShouldIndexAnnotated() { Iterable<Class<?>> annotated = ClassIndex.getAnnotated(Important.class); assertThat(annotated).containsOnly(FirstComponent.class, FirstService.class); }
@Test public void shouldNotIndexNotAnnotated() { Iterable<Class<?>> annotated = ClassIndex.getAnnotated(Documented.class); assertThat(annotated).isEmpty(); }
@Test public void shouldIndexClassesWithRepeatedAnnotations() { Iterable<Class<?>> annotated = ClassIndex.getAnnotated(RepeatableAnnotation.class); assertThat(annotated).contains(StandardRepeated.class, Java8Repeated.class); }
@Test public void shouldNotIndexClassesWithNonRepeatedAnnotations() { Iterable<Class<?>> annotated = ClassIndex.getAnnotated(NonRepeatableAnnotation.class); assertThat(annotated).isEmpty(); }