ClassFilter { public static UnionBuilder only() { return new Builder(); } private  ClassFilter(); static UnionBuilder only(); static FilterBuilder any(final Predicate... alternatives);  }
@Test public void shouldNotFilterWithAlwaysTruePredicate() { Iterable<Class<?>> result = ClassFilter.only().satisfying(new ClassFilter.Predicate() { @Override public boolean matches(Class<?> klass) { return true; } }).from(list); assertThat(result).hasSize(6); }
@Test public void shouldReturnOnlyInterfaces() { Iterable<Class<?>> result = ClassFilter.only().interfaces().from(list); assertThat(result).containsOnly(Service.class); }
@Test public void shouldReturnOnlyClasses() { Iterable<Class<?>> result = ClassFilter.only().classes().from(list); assertThat(result).containsOnly(FirstComponent.class, SecondComponent.class, InnerClasses.InnerComponent.class, InnerClasses.InnerComponent.InnerInnerComponent.class, InnerClasses.InnerModule.class); }
@Test public void shouldReturnTopLevelClasses() { Iterable<Class<?>> result = ClassFilter.only().topLevel().from(list); assertThat(result).containsOnly(FirstComponent.class, SecondComponent.class, Service.class); }
@Test public void shouldReturnTopLevelOrStaticNestedClasses() { Iterable<Class<?>> result = ClassFilter.only().topLevelOrStaticNested().from(list); assertThat(result).containsOnly(FirstComponent.class, SecondComponent.class, InnerClasses.InnerComponent.class, Service.class); }
@Test public void shouldReturnOnlyEnclosedInGivenClass() { Iterable<Class<?>> result = ClassFilter.only().enclosedIn(InnerClasses.class).from(list); assertThat(result).containsOnly(InnerClasses.InnerComponent.class, InnerClasses.InnerModule.class, InnerClasses.InnerComponent.InnerInnerComponent.class); }
@Test public void shouldReturnOnlyEnclosedDirectlyInGivenClass() { Iterable<Class<?>> result = ClassFilter.only().enclosedDirectlyIn(InnerClasses.class).from(list); assertThat(result).containsOnly(InnerClasses.InnerComponent.class, InnerClasses.InnerModule.class); }
@Test public void shouldReturnOnlyAnnotatedWith() { Iterable<Class<?>> result = ClassFilter.only().annotatedWith(Component.class).from(list); assertThat(result).containsOnly(FirstComponent.class, SecondComponent.class, InnerClasses.InnerComponent.class, InnerClasses.InnerComponent.InnerInnerComponent.class); }
@Test(expected = IllegalStateException.class) public void shouldFailWhenUsingAnnotationWithoutRuntimeRetention() { ClassFilter.only().annotatedWith(InheritedAnnotation.class); }
@Test public void shouldReturnOnlyWithModifiers() { Iterable<Class<?>> result = ClassFilter.only().withModifiers(Modifier.STATIC).from(list); assertThat(result).containsOnly(InnerClasses.InnerComponent.class); }
@Test public void shouldReturnOnlyWithoutModifiers() { Iterable<Class<?>> result = ClassFilter.only().withoutModifiers(Modifier.STATIC).from(list); assertThat(result).containsOnly(FirstComponent.class, SecondComponent.class, InnerClasses.InnerComponent.InnerInnerComponent.class, InnerClasses.InnerModule.class, Service.class); }
@Test public void shouldReturnOnlyWithPublicDefaultConstructor() { Iterable<Class<?>> result = ClassFilter.only().withPublicDefaultConstructor().from(list); assertThat(result).containsOnly(FirstComponent.class, InnerClasses.InnerComponent.class); }