BindingConditions { public static <T> BindingCondition<T> anyAnnotationIsPresent(Class<? extends T> type, final Class<? extends Annotation>... annotations) { return new BindingCondition<T>() { @Override public boolean fulfilled(ClassInjector injector, Class<T> type, Map<String, Class<? extends T>[]> inheritanceTree, Annotation qualifier, ClassLoader classLoader) { boolean exists = false; if (type != null && annotations != null && annotations.length > 0) { for (Annotation annotation : type.getAnnotations()) { exists = false; for (Class<? extends Annotation> cmp : annotations) { if (annotation.annotationType().equals(cmp)) { exists = true; break; } } if (!exists) { return exists; } exists = true; } } return exists; } }; }  @SuppressWarnings("unchecked") static BindingCondition<T> annotationIsPresent(Class<? extends T> type, Class<? extends Annotation> annotation); static BindingCondition<T> qualifierIs(Class<? extends T> type, final Class<? extends Annotation> expectedQualifier); static BindingCondition<T> isNamed(Class<? extends T> type, final CharSequence value); static BindingCondition<T> isNamedIgnoringCase(Class<? extends T> type, final CharSequence value); static BindingCondition<T> allAnnotationsArePresent(Class<? extends T> type, final Class<? extends Annotation>... annotations); static BindingCondition<T> anyAnnotationIsPresent(Class<? extends T> type, final Class<? extends Annotation>... annotations); static BindingCondition<T> and(final BindingCondition<T>... conditions); static BindingCondition<T> or(final BindingCondition<T>... conditions); static BindingCondition<T> xor(final BindingCondition<T> condition1, final BindingCondition<T> condition2);  }
@SuppressWarnings("unchecked") @Test public void anyAnnotationsIsPresent() { assertTrue(BindingConditions.anyAnnotationIsPresent(Seat.class, Singleton.class, Inject.class).fulfilled(null, Seat.class, null, null, classLoader)); assertTrue(BindingConditions.anyAnnotationIsPresent(Seat.class, Singleton.class, Drivers.class).fulfilled(null, Seat.class, null, null, classLoader)); assertTrue(BindingConditions.anyAnnotationIsPresent(Seat.class, Singleton.class).fulfilled(null, Seat.class, null, null, classLoader)); }
@SuppressWarnings("unchecked") @Test public void anyAnnotationsIsNotPresent() { assertFalse(BindingConditions.anyAnnotationIsPresent(Seat.class, Inject.class, Qualifier.class).fulfilled(null, Seat.class, null, null, classLoader)); assertFalse(BindingConditions.anyAnnotationIsPresent(Seat.class, Drivers.class).fulfilled(null, Seat.class, null, null, classLoader)); assertFalse(BindingConditions.anyAnnotationIsPresent(Seat.class).fulfilled(null, Seat.class, null, null, classLoader)); }