Search { public static <T extends Annotation> T getInheritedAnnotation(Class<?> clazz, Class<T> annotation) { Conditions.notNull(clazz, "clazz"); Conditions.notNull(annotation, "annotation"); if (clazz.isAssignableFrom(Object.class)) { return null; } T anno = clazz.getAnnotation(annotation); if (anno == null) { return getInheritedAnnotation(clazz.getSuperclass(), annotation); } return anno; } Search(); static T getInheritedAnnotation(Class<?> clazz, Class<T> annotation); static List<Field> getAllFields(Class<?> clazz); static List<Field> getAllFields(Class<?> clazz, SearchCriteria criteria); static List<Method> getAllMethods(Class<?> clazz);  }
@Test void getInheritedAnnotation() { assertThrows(IllegalArgumentException.class, () -> Search.getInheritedAnnotation(null, null)); assertThrows(IllegalArgumentException.class, () -> Search.getInheritedAnnotation(SuperClass.class, null)); assertThrows(IllegalArgumentException.class, () -> Search.getInheritedAnnotation(null, TestAnnotation.class)); Class<TestAnnotation> cls = TestAnnotation.class; TestAnnotation anno; anno = Search.getInheritedAnnotation(BaseAnnotatedClass.class, cls); assertNotNull(anno); assertEquals(0, anno.value()); anno = Search.getInheritedAnnotation(BaseEmptyClass.class, cls); assertNotNull(anno); assertEquals(1, anno.value()); anno = Search.getInheritedAnnotation(SuperClass.class, cls); assertNotNull(anno); assertEquals(1, anno.value()); anno = Search.getInheritedAnnotation(BaseSuperEmptyClass.class, cls); assertNull(anno); anno = Search.getInheritedAnnotation(SuperEmptyClass.class, cls); assertNull(anno); }