1 package test.listeners;
2 
3 import org.testng.Assert;
4 import org.testng.IInvokedMethod;
5 import org.testng.IInvokedMethodListener;
6 import org.testng.ISuite;
7 import org.testng.ISuiteListener;
8 import org.testng.ITestResult;
9 import org.testng.annotations.Listeners;
10 import org.testng.annotations.Test;
11 
12 import test.listeners.SuiteAndInvokedMethodListenerTest.MyListener;
13 
14 /**
15  * Make sure that if a listener implements both IInvokedMethodListener
16  * and ISuiteListener, both listeners get invoked.
17  *
18  * @author Cedric Beust <cedric@beust.com>
19  */
20 @Listeners(MyListener.class)
21 public class SuiteAndInvokedMethodListenerTest {
22   public static class MyListener implements IInvokedMethodListener, ISuiteListener {
23 
24     private static boolean m_before = false;
25     private static boolean m_start = false;
26 
MyListener()27     public MyListener() {
28     }
29 
30     @Override
beforeInvocation(IInvokedMethod method, ITestResult result)31     public void beforeInvocation(IInvokedMethod method, ITestResult result) {
32       m_before = true;
33     }
34 
35     @Override
afterInvocation(IInvokedMethod method, ITestResult result)36     public void afterInvocation(IInvokedMethod method, ITestResult result) {
37     }
38 
39     @Override
onStart(ISuite suite)40     public void onStart(ISuite suite) {
41       m_start = true;
42     }
43 
44     @Override
onFinish(ISuite suite)45     public void onFinish(ISuite suite) {
46     }
47 
48   }
49 
50   @Test
bothListenersShouldRun()51   public void bothListenersShouldRun() {
52     Assert.assertTrue(MyListener.m_before, "IInvokedMethodListener was not invoked");
53     Assert.assertTrue(MyListener.m_start, "ISuiteListener was not invoked");
54   }
55 
56 }
57