blob: 2fdfa0e94fbfb364b2313362ba01572df01daa31 [file] [log] [blame]
package org.testng.internal.invokers;
import org.testng.IInvokedMethodListener;
import org.testng.IInvokedMethodListener2;
import org.testng.TestNGException;
public enum InvokedMethodListenerSubtype {
SIMPLE_LISTENER(IInvokedMethodListener.class),
EXTENDED_LISTENER(IInvokedMethodListener2.class);
private Class<? extends IInvokedMethodListener> matchingInterface;
private InvokedMethodListenerSubtype(Class<? extends IInvokedMethodListener> listenerClass) {
this.matchingInterface = listenerClass;
}
private boolean isInstance(IInvokedMethodListener listenerInstance) {
return matchingInterface.isInstance(listenerInstance);
}
public static InvokedMethodListenerSubtype fromListener(IInvokedMethodListener listenerInstance) {
if (EXTENDED_LISTENER.isInstance(listenerInstance)) {
return EXTENDED_LISTENER;
}
else if (SIMPLE_LISTENER.isInstance(listenerInstance)) {
return SIMPLE_LISTENER;
}
throw new TestNGException("Illegal " + IInvokedMethodListener.class.getSimpleName() + " instance: " + listenerInstance.getClass().getName() + ".");
}
}