FeatureInterceptor extends HandlerInterceptorAdapter { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (handler instanceof HandlerMethod) { HandlerMethod handlerMethod = (HandlerMethod) handler; AnnotationHolder<FeaturesAreActive> annotationHolder = annotations.get(handlerMethod); if (annotationHolder == null) { FeaturesAreActive foundAnnotation = handlerAnnotation(handlerMethod, FeaturesAreActive.class); annotations.putIfAbsent(handlerMethod, new AnnotationHolder<FeaturesAreActive>(foundAnnotation)); annotationHolder = annotations.get(handlerMethod); } if (annotationHolder.hasAnnotation()) { FeaturesAreActive featuresAreActiveAnnotation = annotationHolder.getAnnotation(); if (!Enum.class.isAssignableFrom(featuresAreActiveAnnotation.featureClass())) { throw new IllegalArgumentException("The featureClass of the " + FeaturesAreActive.class.getSimpleName() + " annotation must be an enum"); } for (String f : featuresAreActiveAnnotation.features()) { @SuppressWarnings("unchecked") Feature feature = (Feature) enumFrom(f, (Class<? extends Enum<?>>) featuresAreActiveAnnotation.featureClass()); if (feature != null && !FeatureContext.getFeatureManager().isActive(feature)) { response.sendError(featuresAreActiveAnnotation.responseStatus()); return false; } } } } return super.preHandle(request, response, handler); }  @Override boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler);  }
@Test public void preHandle_noAnnotations() throws Exception { FeatureInterceptor featureInterceptor = new FeatureInterceptor(); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); NonAnnotatedTestController controller = new NonAnnotatedTestController(); HandlerMethod handler = new HandlerMethod(controller, "doit"); assertEquals(true, featureInterceptor.preHandle(request, response, handler)); assertEquals(200, response.getStatus()); }