private boolean isAnnotated(Class<?> realClass) { Listeners listeners = realClass.getAnnotation(Listeners.class); if (listeners == null) { return false; } for (Class<? extends ITestNGListener> listenerClass : listeners.value()) { if (listenerClass.equals(MockitoTestNgListener.class)) { return true; } } return false; }
@SuppressWarnings("unchecked") static boolean shouldBeInvoked(Class testClass, Class<? extends ITestNGListener> listener){ if(!testClass.isAnnotationPresent(Listeners.class)) return false; if(asList(((Listeners) testClass.getAnnotation(Listeners.class)).value()).contains(listener)) return true; return shouldBeInvoked(testClass.getSuperclass(), listener); }
protected boolean hasMockitoTestNGListener(Class<?> clazz) { Listeners listeners = clazz.getAnnotation(Listeners.class); if (listeners == null) { return false; } for (Class<? extends ITestNGListener> listenerClass : listeners.value()) { if (listenerClass() == listenerClass) { return true; } } return false; }
public boolean shouldIntercept(Class testClass, Class annotation) { Listeners listenersAnnotation = getListenersAnnotation(testClass); return listenersAnnotation != null && asList(listenersAnnotation.value()).contains(annotation); }
private Listeners getListenersAnnotation(Class testClass) { Annotation annotation = testClass.getAnnotation(Listeners.class); return annotation != null ? (Listeners) annotation : testClass.getSuperclass() != null ? getListenersAnnotation(testClass.getSuperclass()) : null; }