1 package test.listeners;
2 
3 import org.testng.IInvokedMethod;
4 import org.testng.IInvokedMethodListener;
5 import org.testng.ITestResult;
6 import org.testng.annotations.BeforeClass;
7 import org.testng.annotations.Listeners;
8 import org.testng.annotations.Test;
9 
10 import test.listeners.EndMillisShouldNotBeZeroTest.MyInvokedMethodListener;
11 import junit.framework.Assert;
12 
13 @Listeners(MyInvokedMethodListener.class)
14 public class EndMillisShouldNotBeZeroTest {
15   private static long m_end;
16 
17   public static class MyInvokedMethodListener implements IInvokedMethodListener {
18 
19     @Override
beforeInvocation(IInvokedMethod method, ITestResult testResult)20     public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
21     }
22 
23     @Override
afterInvocation(IInvokedMethod method, ITestResult testResult)24     public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
25       m_end = testResult.getEndMillis();
26     }
27 
28   }
29 
30   @BeforeClass
bm()31   public void bm() {
32     m_end = 0;
33   }
34 
35   @Test
f1()36   public void f1()
37   {
38     try {
39       Thread.sleep(1);
40     } catch (InterruptedException handled) {
41       Thread.currentThread().interrupt();
42     }
43   }
44 
45   @Test(description = "Make sure that ITestResult#getEndMillis is properly set",
46       dependsOnMethods = "f1")
f2()47   public void f2() {
48     Assert.assertTrue(m_end > 0);
49   }
50 }
51