AnnotationUtil { static List<Annotation> getAllAnnotations(AnnotatedElement element) { return getAnnotations(element, EnumSet.of(FindOption.LOOKUP_SUPER_CLASSES, FindOption.LOOKUP_META_ANNOTATIONS)); } private  AnnotationUtil();   }
@Test public void getAnnotations_all() { final List<Annotation> list = getAllAnnotations(TestGrandChildClass.class); assertThat(list).hasSize(18); for (int i = 0; i < 3 * 6;) { assertThat(list.get(i++)).isInstanceOf(TestMetaOfMetaAnnotation.class); assertThat(list.get(i)).isInstanceOf(TestMetaAnnotation.class); assertThat(((TestMetaAnnotation) list.get(i++)).value()).isEqualTo("TestRepeatables"); assertThat(list.get(i++)).isInstanceOf(TestRepeatables.class); assertThat(list.get(i++)).isInstanceOf(TestMetaOfMetaAnnotation.class); assertThat(list.get(i)).isInstanceOf(TestMetaAnnotation.class); assertThat(((TestMetaAnnotation) list.get(i++)).value()).isEqualTo("TestAnnotation"); assertThat(list.get(i++)).isInstanceOf(TestAnnotation.class); } }
@Test public void getAnnotations_all_cyclic() throws Exception { List<Annotation> list = getAllAnnotations(TestClassWithCyclicAnnotation.class); assertThat(list).hasSize(1); assertThat(list.get(0)).isInstanceOf(CyclicAnnotation.class); list = getAllAnnotations(TestClassWithCyclicAnnotation.class.getDeclaredMethod("foo")); assertThat(list).hasSize(1); assertThat(list.get(0)).isInstanceOf(CyclicAnnotation.class); }