AnnotationUtils { public static <T extends Annotation> boolean hasAnnotation(Class<?> clazz, Class<T> annotationType) { return getAnnotation(clazz, annotationType) != null; }  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 hasAnnotation() { assertTrue(AnnotationUtils.hasAnnotation(someController.getClass(), Path.class)); assertFalse(AnnotationUtils.hasAnnotation(someController.getClass(), Named.class)); assertTrue(AnnotationUtils.hasAnnotation(someBean.getClass(), Named.class)); assertFalse(AnnotationUtils.hasAnnotation(someBean.getClass(), Path.class)); assertTrue(AnnotationUtils.hasAnnotation(BaseController.class, Controller.class)); assertFalse(AnnotationUtils.hasAnnotation(InheritedController.class, Controller.class)); assertFalse(AnnotationUtils.hasAnnotation(ControllerImpl.class, Controller.class)); }
@Test public void hasAnnotationOnMethod() throws NoSuchMethodException { assertTrue(AnnotationUtils.hasAnnotation(someController.getClass().getMethod("start"), View.class)); assertFalse(AnnotationUtils.hasAnnotation(someController.getClass().getMethod("start"), NotNull.class)); assertTrue(AnnotationUtils.hasAnnotation(someBean.getClass().getMethod("notNull"), NotNull.class)); assertFalse(AnnotationUtils.hasAnnotation(someBean.getClass().getMethod("notNull"), View.class)); assertTrue(AnnotationUtils.hasAnnotation(BaseController.class.getMethod("start"), View.class)); assertTrue(AnnotationUtils.hasAnnotation(InheritedController.class.getMethod("start"), View.class)); assertTrue(AnnotationUtils.hasAnnotation(ControllerImpl.class.getMethod("start"), View.class)); assertFalse(AnnotationUtils.hasAnnotation(NoInheritanceController.class.getMethod("start"), Path.class)); }