AnnotationUtil { static <T extends Annotation> List<T> findDeclared( AnnotatedElement element, Class<T> annotationType) { return find(element, annotationType, EnumSet.noneOf(FindOption.class)); } private  AnnotationUtil();   }
@Test public void declared() throws NoSuchMethodException { List<TestAnnotation> list; list = findDeclared(TestClass.class.getMethod("directlyPresent"), TestAnnotation.class); assertThat(list).hasSize(1); assertThat(list.get(0).value()).isEqualTo("method-level:directlyPresent"); list = findDeclared(TestClass.class, TestAnnotation.class); assertThat(list).hasSize(1); assertThat(list.get(0).value()).isEqualTo("class-level:TestClass"); list = findDeclared(TestChildClass.class, TestAnnotation.class); assertThat(list).hasSize(1); assertThat(list.get(0).value()).isEqualTo("class-level:TestChildClass"); list = findDeclared(TestGrandChildClass.class, TestAnnotation.class); assertThat(list).hasSize(1); assertThat(list.get(0).value()).isEqualTo("class-level:TestGrandChildClass"); }
@Test public void declared_repeatable() throws NoSuchMethodException { List<TestRepeatable> list; list = findDeclared(TestClass.class.getMethod("directlyPresentRepeatableSingle"), TestRepeatable.class); assertThat(list).hasSize(1); assertThat(list.get(0).value()).isEqualTo("method-level:directlyPresentRepeatableSingle"); list = findDeclared(SingleRepeatableTestClass.class, TestRepeatable.class); assertThat(list).hasSize(1); assertThat(list.get(0).value()).isEqualTo("class-level:SingleRepeatableTestClass"); list = findDeclared(SingleRepeatableTestChildClass.class, TestRepeatable.class); assertThat(list).hasSize(1); assertThat(list.get(0).value()).isEqualTo("class-level:SingleRepeatableTestChildClass"); list = findDeclared(SingleRepeatableTestGrandChildClass.class, TestRepeatable.class); assertThat(list).hasSize(1); assertThat(list.get(0).value()).isEqualTo("class-level:SingleRepeatableTestGrandChildClass"); }
@Test public void declared_repeatable_multi() throws NoSuchMethodException { List<TestRepeatable> list; list = findDeclared(TestClass.class.getMethod("directlyPresentRepeatableMulti"), TestRepeatable.class); assertThat(list).hasSize(3); assertThat(list.get(0).value()).isEqualTo("method-level:directlyPresentRepeatableMulti:1"); assertThat(list.get(1).value()).isEqualTo("method-level:directlyPresentRepeatableMulti:2"); assertThat(list.get(2).value()).isEqualTo("method-level:directlyPresentRepeatableMulti:3"); list = findDeclared(TestClass.class, TestRepeatable.class); assertThat(list).hasSize(2); assertThat(list.get(0).value()).isEqualTo("class-level:TestClass:Repeatable1"); assertThat(list.get(1).value()).isEqualTo("class-level:TestClass:Repeatable2"); list = findDeclared(TestChildClass.class, TestRepeatable.class); assertThat(list).hasSize(2); assertThat(list.get(0).value()).isEqualTo("class-level:TestChildClass:Repeatable1"); assertThat(list.get(1).value()).isEqualTo("class-level:TestChildClass:Repeatable2"); list = findDeclared(TestGrandChildClass.class, TestRepeatable.class); assertThat(list).hasSize(2); assertThat(list.get(0).value()).isEqualTo("class-level:TestGrandChildClass:Repeatable1"); assertThat(list.get(1).value()).isEqualTo("class-level:TestGrandChildClass:Repeatable2"); }