FeatureInterceptor extends HandlerInterceptorAdapter { protected static <A extends Annotation> A handlerAnnotation(HandlerMethod handlerMethod, Class<A> annotationClass) { A annotation = handlerMethod.getMethodAnnotation(annotationClass); if (annotation == null) { annotation = AnnotationUtils.findAnnotation(handlerMethod.getBeanType(), annotationClass); } return annotation; }  @Override boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler);  }
@Test public void handlerAnnotation_OnType() throws NoSuchMethodException { TestController controller = new TestController(); HandlerMethod handler = new HandlerMethod(controller, "classFeature"); FeaturesAreActive annotation = FeatureInterceptor.handlerAnnotation(handler, FeaturesAreActive.class); assertNotNull(annotation); assertEquals(TestFeatures.class, annotation.featureClass()); assertEquals(HttpStatus.NOT_FOUND.value(), annotation.responseStatus()); assertThat(annotation.features()).containsExactly("CLASS_FEATURE"); }
@Test public void handlerAnnotation_OnMethod() throws NoSuchMethodException { TestController controller = new TestController(); HandlerMethod handler = new HandlerMethod(controller, "methodFeatureTwo"); FeaturesAreActive annotation = FeatureInterceptor.handlerAnnotation(handler, FeaturesAreActive.class); assertNotNull(annotation); assertEquals(TestFeatures.class, annotation.featureClass()); assertEquals(302, annotation.responseStatus()); assertThat(annotation.features()).containsExactly("METHOD_FEATURE", "METHOD_FEATURE_TWO"); }