### Question:
ReflectionUtil { public static Option<Method> getFirstMethodAnnotatedWith(final Class<?> type, final Class<? extends Annotation> annotation) { Class<?> klass = type; while (klass != Object.class) { final List<Method> allMethods = new ArrayList<Method>(Arrays.asList(klass.getDeclaredMethods())); for (final Method method : allMethods) { if (annotation == null || method.isAnnotationPresent(annotation)) { Annotation annotInstance = method.getAnnotation(annotation); return Option.of(method); } } klass = klass.getSuperclass(); } return Option.empty(); }  static Option<Method> getFirstMethodAnnotatedWith(final Class<?> type, final Class<? extends Annotation> annotation);  }### Answer:
@Test public void shouldReturnNotPresentIfNoMethodFound() { assertThat(ReflectionUtil.getFirstMethodAnnotatedWith(ClassWithOutAnnotation.class, MyAnnotation.class).isPresent()).isFalse(); }
@Test public void shouldFindMethodWithAnnotation() { Option<Method> method = ReflectionUtil.getFirstMethodAnnotatedWith(ClassWithAnnotation.class, MyAnnotation.class); assertThat(method.isPresent()).isTrue(); assertThat(method.get().getName()).isEqualTo("methodWithAnnotation"); }