ResolveClassAnnotation { public static Optional<Class<?>> getClassWithAnnotation(final Class<?> source, final Class<? extends Annotation> annotationClass) { Class<?> nextSource = source; while (nextSource != Object.class) { if (nextSource.isAnnotationPresent(annotationClass)) { return Optional.of(nextSource); } else { nextSource = nextSource.getSuperclass(); } } return Optional.empty(); }  static Optional<Class<?>> getClassWithAnnotation(final Class<?> source,
        final Class<? extends Annotation> annotationClass);  }
@Test public void should_get_annotation_from_class_level() { assertThat(ResolveClassAnnotation.getClassWithAnnotation(A.class, Pact.class)).isPresent(); }
@Test public void should_get_annotation_from_subclass() { assertThat(ResolveClassAnnotation.getClassWithAnnotation(B.class, Pact.class)).isPresent(); }