FeatureInterceptor extends HandlerInterceptorAdapter { protected static <T extends Enum<?>> T enumFrom(String name, Class<T> enumType) { if (name != null) { for (T item : enumType.getEnumConstants()) { if (name.equals(item.name())) { return item; } } } return null; }  @Override boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler);  }
@Test public void enumFrom() { assertEquals(TestFeatures.CLASS_FEATURE, FeatureInterceptor.enumFrom("CLASS_FEATURE", TestFeatures.class)); assertEquals(TestFeatures.METHOD_FEATURE, FeatureInterceptor.enumFrom("METHOD_FEATURE", TestFeatures.class)); assertNull(FeatureInterceptor.enumFrom("FOO", TestFeatures.class)); assertNull(FeatureInterceptor.enumFrom(null, TestFeatures.class)); }