AnnotationUtils { @SuppressWarnings("unchecked") public static <T extends Annotation> T findAnnotation(Annotation parentAnnotation, Class<T> annotationType) { for (Annotation childAnnotation : parentAnnotation.annotationType().getAnnotations()) { if (childAnnotation.annotationType().equals(annotationType)) { return (T) childAnnotation; } } return null; } private  AnnotationUtils(); static List<T> findNestedAnnotations(AnnotatedElement annotatedElement, Class<T> annotationType); @SuppressWarnings("unchecked") static T findAnnotation(Annotation parentAnnotation, Class<T> annotationType);  }
@Test public void testFindAnnotation() throws Exception { Method action = SimpleActionClass.class.getDeclaredMethod("nonDefaultAction", String.class); Authorized authorizedAnnotation = action.getAnnotation(Authorized.class); Intercept nestedAnnotation = AnnotationUtils.findAnnotation(authorizedAnnotation, Intercept.class); assertNotNull(nestedAnnotation); }