### Question:
AnnotationResolver { public static <T extends Annotation> List<T> findAllAnnotationsByType(final Method method, final Class<T> annotationType) { final var annotations = new ArrayList<T>(); annotations.addAll(Arrays.asList(method.getDeclaredAnnotationsByType(annotationType))); annotations.addAll(findAllAnnotationsByType(method.getDeclaredAnnotations(), annotationType)); return annotations; }  static boolean isAnnotationOfType(final Annotation annotation,
                                             final Class<?> type); static boolean isAnnotationContainer(final Class<? extends Annotation> annotationType); static List<Annotation> findAllAnnotations(final Class<?> cls); static List<T> findAllAnnotationsByType(final Method method,
                                                                          final Class<T> annotationType); static List<T> findAllAnnotationsByType(final Class<?> cls,
                                                                          final Class<T> annotationType); static boolean isAnnotatedWith(final Method method,
                                                                 final Class<A> annotation); static boolean isAnnotatedWith(final Class<?> component,
                                                                 final Class<A> annotation);  }### Answer:
@Test public void shouldResolvedRepeatableAnnotationGivenClass() { final List<String> annotations = AnnotationResolver.findAllAnnotationsByType( RepeatableTestClass.class, AnnotationResolverTest.TestAnnotation.class ).stream().map(AnnotationResolverTest.TestAnnotation::value).collect(Collectors.toList()); assertEquals(2, annotations.size()); assertTrue(annotations.containsAll(Arrays.asList("child1", "child2"))); }
@Test public void shouldResolvedInheritedAnnotationGivenClass() { final List<String> annotations = AnnotationResolver.findAllAnnotationsByType( InheritedTestClass.class, AnnotationResolverTest.TestAnnotation.class ).stream().map(AnnotationResolverTest.TestAnnotation::value).collect(Collectors.toList()); assertEquals(1, annotations.size()); assertTrue(annotations.contains("inherited")); }
@Test public void shouldResolvedAnnotatedAnnotationGivenClass() { final List<String> annotations = AnnotationResolver.findAllAnnotationsByType( CustomTestClass.class, TestAnnotation.class ).stream().map(TestAnnotation::value).collect(Collectors.toList()); assertEquals(1, annotations.size()); assertTrue(annotations.contains("custom")); }
@Test @CustomAnnotation public void shouldResolvedAnnotatedAnnotationGivenMethod() throws NoSuchMethodException { final List<String> annotations = AnnotationResolver.findAllAnnotationsByType( AnnotationResolverTest.class.getMethod("shouldResolvedAnnotatedAnnotationGivenMethod"), TestAnnotation.class ).stream().map(TestAnnotation::value).collect(Collectors.toList()); assertEquals(1, annotations.size()); assertTrue(annotations.contains("custom")); }
@Test @TestAnnotation("child1") @TestAnnotation("child2") public void shouldResolvedRepeatableAnnotationGivenMethod() throws NoSuchMethodException { final List<String> annotations = AnnotationResolver.findAllAnnotationsByType( AnnotationResolverTest.class.getMethod("shouldResolvedRepeatableAnnotationGivenMethod"), AnnotationResolverTest.TestAnnotation.class ).stream().map(AnnotationResolverTest.TestAnnotation::value).collect(Collectors.toList()); assertEquals(2, annotations.size()); assertTrue(annotations.containsAll(Arrays.asList("child1", "child2"))); }