AnnotationUtil { static <T extends Annotation> List<T> findAll(AnnotatedElement element, Class<T> annotationType) { return find(element, annotationType, EnumSet.of(FindOption.LOOKUP_SUPER_CLASSES, FindOption.LOOKUP_META_ANNOTATIONS)); } private  AnnotationUtil();   }
@Test public void findAll_includingRepeatable() { List<TestMetaAnnotation> list; list = findAll(SingleRepeatableTestClass.class, TestMetaAnnotation.class); assertThat(list).hasSize(1); assertThat(list.get(0).value()).isEqualTo("TestRepeatable"); list = findAll(SingleRepeatableTestChildClass.class, TestMetaAnnotation.class); assertThat(list).hasSize(2); assertThat(list.get(0).value()).isEqualTo("TestRepeatable"); assertThat(list.get(1).value()).isEqualTo("TestRepeatable"); list = findAll(SingleRepeatableTestGrandChildClass.class, TestMetaAnnotation.class); assertThat(list).hasSize(3); assertThat(list.get(0).value()).isEqualTo("TestRepeatable"); assertThat(list.get(1).value()).isEqualTo("TestRepeatable"); assertThat(list.get(2).value()).isEqualTo("TestRepeatable"); }
@Test public void findAll_includingRepeatable_multi() { List<TestMetaAnnotation> list; list = findAll(TestClass.class, TestMetaAnnotation.class); assertThat(list).hasSize(2); assertThat(list.get(0).value()).isEqualTo("TestRepeatables"); assertThat(list.get(1).value()).isEqualTo("TestAnnotation"); list = findAll(TestChildClass.class, TestMetaAnnotation.class); assertThat(list).hasSize(4); assertThat(list.get(0).value()).isEqualTo("TestRepeatables"); assertThat(list.get(1).value()).isEqualTo("TestAnnotation"); assertThat(list.get(2).value()).isEqualTo("TestRepeatables"); assertThat(list.get(3).value()).isEqualTo("TestAnnotation"); list = findAll(TestGrandChildClass.class, TestMetaAnnotation.class); assertThat(list).hasSize(6); assertThat(list.get(0).value()).isEqualTo("TestRepeatables"); assertThat(list.get(1).value()).isEqualTo("TestAnnotation"); assertThat(list.get(2).value()).isEqualTo("TestRepeatables"); assertThat(list.get(3).value()).isEqualTo("TestAnnotation"); assertThat(list.get(4).value()).isEqualTo("TestRepeatables"); assertThat(list.get(5).value()).isEqualTo("TestAnnotation"); }
@Test public void findAll_interfaces() { List<TestAnnotation> list; list = findAll(TestClassWithIface.class, TestAnnotation.class); assertThat(list).hasSize(3); assertThat(list.get(0).value()).isEqualTo("TestClassWithIface"); assertThat(list.get(1).value()).isEqualTo("TestChildIface"); assertThat(list.get(2).value()).isEqualTo("TestIface"); list = findAll(TestChildClassWithIface.class, TestAnnotation.class); assertThat(list).hasSize(5); assertThat(list.get(0).value()).isEqualTo("TestChildClassWithIface"); assertThat(list.get(1).value()).isEqualTo("TestAnotherIface"); assertThat(list.get(2).value()).isEqualTo("TestClassWithIface"); assertThat(list.get(3).value()).isEqualTo("TestChildIface"); assertThat(list.get(4).value()).isEqualTo("TestIface"); }
@Test public void findAll_metaAnnotationOfMetaAnnotation() { List<TestMetaOfMetaAnnotation> list; list = findAll(TestClass.class, TestMetaOfMetaAnnotation.class); assertThat(list).hasSize(2); list = findAll(TestChildClass.class, TestMetaOfMetaAnnotation.class); assertThat(list).hasSize(4); list = findAll(TestGrandChildClass.class, TestMetaOfMetaAnnotation.class); assertThat(list).hasSize(6); }
@Test public void findAll_cyclic() throws Exception { List<CyclicAnnotation> list = findAll(TestClassWithCyclicAnnotation.class, CyclicAnnotation.class); assertThat(list).hasSize(1); assertThat(list.get(0)).isInstanceOf(CyclicAnnotation.class); list = findAll(TestClassWithCyclicAnnotation.class.getDeclaredMethod("foo"), CyclicAnnotation.class); assertThat(list).hasSize(1); assertThat(list.get(0)).isInstanceOf(CyclicAnnotation.class); }