Class<? extends ITestNGListenerFactory> listenerFactoryClass = null;
for (IClass cls : tr.getTestClasses()) {
IAnnotationFinder finder = m_configuration.getAnnotationFinder();
Class<? extends ITestNGListenerFactory> realClass = cls.getRealClass();
IListeners l = (IListeners) finder.findAnnotation(realClass, IListeners.class);
if (ITestNGListenerFactory.class.isAssignableFrom(realClass)) {
if (listenerFactoryClass == null) {
listenerFactoryClass = realClass;
}
else {
throw new TestNGException("Found more than one class implementing" +
"ITestNGListenerFactory:" + realClass + " and " + listenerFactoryClass);
}
}
if (l != null) {
listenerClasses.addAll(Arrays.asList(l.getValue()));
}
}
//
// Now we have all the listeners collected from @Listeners and at most one