ReflectUtil { public static boolean isAnyAnnotationPresent(Field field, Collection<Class<? extends Annotation>> annotations) { for (Class<? extends Annotation> annotation : annotations) { if (field.isAnnotationPresent(annotation)) { return true; } } return false; }  static List<Field> getAllDeclaredFields(Class<?> clazz); static List<Method> getAllDeclaredMethods(Class<?> clazz); static @Nullable Annotation findQualifierAnnotation(Field field); static @Nullable Annotation findQualifierAnnotation(Annotation[] annotations, String description); static boolean isAnyAnnotationPresent(Field field, Collection<Class<? extends Annotation>> annotations); static boolean isAnyAnnotationPresent(Method method, Collection<Class<? extends Annotation>> annotations);  }
@Test public void testIsAnyAnnotationPresent() { Field field = prop("testProp4"); boolean result1 = ReflectUtil.isAnyAnnotationPresent(field, Arrays.asList(Spy.class, TestQualifierAnnotation.class, Mock.class)); boolean result2 = ReflectUtil.isAnyAnnotationPresent(field, Arrays.asList(Spy.class, Mock.class)); boolean result3 = ReflectUtil.isAnyAnnotationPresent(field, Arrays.asList(Mock.class, TestSimpleAnnotation.class)); assertThat(result1).isTrue(); assertThat(result2).isFalse(); assertThat(result3).isTrue(); }
@Test public void testIsAnyAnnotationPresentMethod() throws NoSuchMethodException { Method method = ClassWithMethodWithAnnotation.class.getDeclaredMethod("doNothing"); boolean result1 = ReflectUtil.isAnyAnnotationPresent(method, Arrays.asList(Spy.class, TestQualifierAnnotation.class, Mock.class)); boolean result2 = ReflectUtil.isAnyAnnotationPresent(method, Arrays.asList(Spy.class, Mock.class)); boolean result3 = ReflectUtil.isAnyAnnotationPresent(method, Arrays.asList(Mock.class, Inject.class)); assertThat(result1).isTrue(); assertThat(result2).isFalse(); assertThat(result3).isTrue(); }