AnnotationUtils { public static <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T> annotationType) { T an = clazz.getDeclaredAnnotation(annotationType); if (an == null && isProxy(clazz)) { an = clazz.getSuperclass().getDeclaredAnnotation(annotationType); } return an; }  static T getAnnotation(Class<?> clazz, Class<T> annotationType); static boolean hasAnnotation(Class<?> clazz, Class<T> annotationType); static T getAnnotation(Method method, Class<T> annotationType); static boolean hasAnnotation(Method method, Class<T> annotationType); static boolean hasAnnotationOnClassOrMethod(Class<?> clazz, Class<T> annotationType);  }
@Test public void getAnnotation() { Path path = AnnotationUtils.getAnnotation(someController.getClass(), Path.class); assertThat(path.value(), is("start")); Named named = AnnotationUtils.getAnnotation(someBean.getClass(), Named.class); assertThat(named.value(), is("someBean")); assertThat(AnnotationUtils.getAnnotation(BaseController.class, Controller.class), is(notNullValue())); assertThat(AnnotationUtils.getAnnotation(InheritedController.class, Controller.class), is(nullValue())); assertThat(AnnotationUtils.getAnnotation(ControllerImpl.class, Controller.class), is(nullValue())); }
@Test public void getAnnotationOnMethod() throws NoSuchMethodException { View view = AnnotationUtils.getAnnotation(someController.getClass().getMethod("start"), View.class); assertThat(view.value(), is("start.jsp")); NotNull notNull = AnnotationUtils.getAnnotation(someBean.getClass().getMethod("notNull"), NotNull.class); assertThat(notNull.message(), is("notNull")); assertThat(AnnotationUtils.getAnnotation(BaseController.class.getMethod("start"), View.class), is(notNullValue())); assertThat(AnnotationUtils.getAnnotation(InheritedController.class.getMethod("start"), View.class), is(notNullValue())); assertThat(AnnotationUtils.getAnnotation(ControllerImpl.class.getMethod("start"), View.class), is(notNullValue())); View inheritedView = AnnotationUtils.getAnnotation(InheritedControllerImpl.class.getMethod("start"), View.class); assertThat(inheritedView.value(), is("start-base.jsp")); assertThat(AnnotationUtils.getAnnotation(NoInheritanceController.class.getMethod("start"), Path.class), is(nullValue())); }