PageRenderTime 53ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/testng-6.0.1/src/main/java/org/testng/internal/invokers/InvokedMethodListenerSubtype.java

#
Java | 40 lines | 25 code | 7 blank | 8 comment | 3 complexity | 3ab611b56a3a84d2a54f415af07093d9 MD5 | raw file
Possible License(s): Apache-2.0
  1. package org.testng.internal.invokers;
  2. import org.testng.IInvokedMethodListener;
  3. import org.testng.IInvokedMethodListener2;
  4. import org.testng.TestNGException;
  5. /**
  6. * Indicates whether a {@link InvokedMethodListenerMethod} is to be called on a simple or an
  7. * extended invoked method listener. All {@link IInvokedMethodListener}s are considered
  8. * {@link #SIMPLE_LISTENER}, instances of {@link IInvokedMethodListener2} are all considered
  9. * {@link #EXTENDED_LISTENER}.
  10. *
  11. * @author Ansgar Konermann
  12. */
  13. enum InvokedMethodListenerSubtype {
  14. EXTENDED_LISTENER(IInvokedMethodListener2.class),
  15. SIMPLE_LISTENER(IInvokedMethodListener.class);
  16. private Class<? extends IInvokedMethodListener> m_matchingInterface;
  17. private InvokedMethodListenerSubtype(Class<? extends IInvokedMethodListener> listenerClass) {
  18. m_matchingInterface = listenerClass;
  19. }
  20. private boolean isInstance(IInvokedMethodListener listenerInstance) {
  21. return m_matchingInterface.isInstance(listenerInstance);
  22. }
  23. public static InvokedMethodListenerSubtype fromListener(IInvokedMethodListener listenerInstance) {
  24. if (EXTENDED_LISTENER.isInstance(listenerInstance)) {
  25. return EXTENDED_LISTENER;
  26. }
  27. else if (SIMPLE_LISTENER.isInstance(listenerInstance)) {
  28. return SIMPLE_LISTENER;
  29. }
  30. throw new TestNGException("Illegal " + IInvokedMethodListener.class.getSimpleName()
  31. + " instance: " + listenerInstance.getClass().getName() + ".");
  32. }
  33. }