ReflectUtil { public static @Nullable Annotation findQualifierAnnotation(Field field) { return findQualifierAnnotation(field.getDeclaredAnnotations(), "field: " + field.getName()); }  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 testFindQualifierAnnotation() throws IllegalAccessException, InstantiationException { Annotation found1 = ReflectUtil.findQualifierAnnotation(prop("testProp1")); Annotation found2 = ReflectUtil.findQualifierAnnotation(prop("testProp2")); Annotation found3 = ReflectUtil.findQualifierAnnotation(prop("testProp3")); Annotation found4 = ReflectUtil.findQualifierAnnotation(prop("testProp4")); Annotation found5 = ReflectUtil.findQualifierAnnotation(prop("testProp5")); assertTrue(found1.annotationType() == Named.class); assertTrue(found2.annotationType() == Named.class); assertTrue(found3.annotationType() == Named.class); assertTrue(found4.annotationType() == TestQualifierAnnotation.class); assertTrue(found5.annotationType() == Named.class); assertThat(found1) .isNotEqualTo(found2) .isEqualTo(found5); assertThat(found2) .isNotEqualTo(found1) .isEqualTo(found3); assertThat(((Named)found1).value()).isEqualTo("test1"); }
@Test(expected = MultipleQualifierAnnotationException.class) public void testMultipleQualifiersFailure() { ReflectUtil.findQualifierAnnotation(prop("badTestProp")); }