/** * Invoke the given {@code listenerInstance}, calling the method specified in the constructor of * this {@link InvokedMethodListenerInvoker}. * * @param listenerInstance the listener instance which should be invoked. * @param invokedMethod the {@link IInvokedMethod} instance which should be passed to the * {@link IInvokedMethodListener#beforeInvocation(IInvokedMethod, ITestResult)}, * {@link IInvokedMethodListener#afterInvocation(IInvokedMethod, ITestResult)}, * {@link IInvokedMethodListener2#beforeInvocation(IInvokedMethod, ITestResult, ITestContext)} * or {@link IInvokedMethodListener2#afterInvocation(IInvokedMethod, ITestResult, ITestContext)} * method. */ @SuppressWarnings("unchecked") public void invokeListener(IInvokedMethodListener listenerInstance, IInvokedMethod invokedMethod) { final InvocationStrategy strategy = obtainStrategyFor(listenerInstance, m_listenerMethod); strategy.callMethod(listenerInstance, invokedMethod, m_testResult, m_testContext); }
private void runInvokedMethodListeners(InvokedMethodListenerMethod listenerMethod, IInvokedMethod invokedMethod, ITestResult testResult) { if (noListenersPresent()) { return; } InvokedMethodListenerInvoker invoker = new InvokedMethodListenerInvoker(listenerMethod, testResult, m_testContext); for (IInvokedMethodListener currentListener : m_invokedMethodListeners) { invoker.invokeListener(currentListener, invokedMethod); } }
private InvocationStrategy obtainStrategyFor(IInvokedMethodListener listenerInstance, InvokedMethodListenerMethod listenerMethod) { InvokedMethodListenerSubtype invokedMethodListenerSubtype = InvokedMethodListenerSubtype .fromListener(listenerInstance); Map<InvokedMethodListenerMethod, InvocationStrategy> strategiesForListenerType = strategies .get(invokedMethodListenerSubtype); InvocationStrategy invocationStrategy = strategiesForListenerType.get(listenerMethod); return invocationStrategy; }
@Test public void testFromListenerUsingExtendedListenerInstance() { IInvokedMethodListener extendedListenerInstance = new ExtendedInvokedMethodListenerDummy(); InvokedMethodListenerSubtype listenerSubtype = InvokedMethodListenerSubtype.fromListener(extendedListenerInstance); Assert.assertEquals(listenerSubtype, InvokedMethodListenerSubtype.EXTENDED_LISTENER); }
@Test public void testFromListenerUsingSimpleListenerInstance() { final IInvokedMethodListener simpleListenerInstance = new SimpleInvokedMethodListenerDummy(); InvokedMethodListenerSubtype listenerSubtype = InvokedMethodListenerSubtype.fromListener(simpleListenerInstance); Assert.assertEquals(listenerSubtype, InvokedMethodListenerSubtype.SIMPLE_LISTENER); }
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() + "."); } }
/** * Invoke the given {@code listenerInstance}, calling the method specified in the constructor of * this {@link InvokedMethodListenerInvoker}. * * @param listenerInstance the listener instance which should be invoked. * @param invokedMethod the {@link IInvokedMethod} instance which should be passed to the {@link * IInvokedMethodListener#beforeInvocation(IInvokedMethod, ITestResult)}, {@link * IInvokedMethodListener#afterInvocation(IInvokedMethod, ITestResult)}, {@link * IInvokedMethodListener#beforeInvocation(IInvokedMethod, ITestResult, ITestContext)} or * {@link IInvokedMethodListener#afterInvocation(IInvokedMethod, ITestResult, ITestContext)} * method. */ @SuppressWarnings("unchecked") public void invokeListener( IInvokedMethodListener listenerInstance, IInvokedMethod invokedMethod) { final InvocationStrategy strategy = obtainStrategyFor(listenerInstance, m_listenerMethod); strategy.callMethod(listenerInstance, invokedMethod, m_testResult, m_testContext); }
protected void runInvokedMethodListeners( InvokedMethodListenerMethod listenerMethod, IInvokedMethod invokedMethod, ITestResult testResult) { if (noListenersPresent()) { return; } InvokedMethodListenerInvoker invoker = new InvokedMethodListenerInvoker(listenerMethod, testResult, m_testContext); for (IInvokedMethodListener currentListener : m_invokedMethodListeners) { invoker.invokeListener(currentListener, invokedMethod); } }
private InvocationStrategy obtainStrategyFor( IInvokedMethodListener listenerInstance, InvokedMethodListenerMethod listenerMethod) { InvokedMethodListenerSubtype invokedMethodListenerSubtype = InvokedMethodListenerSubtype.fromListener(listenerInstance); Map<InvokedMethodListenerMethod, InvocationStrategy> strategiesForListenerType = strategies.get(invokedMethodListenerSubtype); return strategiesForListenerType.get(listenerMethod); }
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() + "."); } }