### Question:
Utils { static <A extends Annotation> A findAnnotation(final Class<A> targetAnnotation, final Class<?> annotatedType) { A foundAnnotation = annotatedType.getAnnotation(targetAnnotation); if (foundAnnotation == null) { for (Annotation annotation : annotatedType.getAnnotations()) { Class<? extends Annotation> annotationType = annotation.annotationType(); if (annotationType.isAnnotationPresent(targetAnnotation)) { foundAnnotation = annotationType.getAnnotation(targetAnnotation); break; } } } return foundAnnotation; } private  Utils();   }### Answer:
@Test public void findAnnotationWithClassWhereAnnotationIsPresent() { Annotation foo = Utils.findAnnotation(Foo.class, AnnotationIsPresent.class); assertCorrectAnnotationIsFound(Foo.class, foo); }
@Test public void findAnnotationWithClassWhereAnnotationIsPresentViaMetaAnnotation() { Annotation foo = Utils.findAnnotation(Foo.class, AnnotationIsPresentViaMetaAnnotation.class); assertCorrectAnnotationIsFound(Foo.class, foo); }
@Test public void findAnnotationWithClassWhereAnnotationIsNotPresent() { Annotation foo = Utils.findAnnotation(Foo.class, Object.class); assertNull(foo); }