1 package test.configuration;
2 
3 import org.testng.annotations.AfterClass;
4 import org.testng.annotations.AfterMethod;
5 import org.testng.annotations.AfterSuite;
6 import org.testng.annotations.BeforeClass;
7 import org.testng.annotations.BeforeMethod;
8 import org.testng.annotations.BeforeSuite;
9 import org.testng.annotations.Test;
10 
11 /**
12  * Test @Configuration
13  *
14  * @author cbeust
15  */
16 public class ConfigurationTest {
17   private boolean m_beforeSuite = false;
18   private boolean m_afterSuite = false;
19   private boolean m_beforeClass = false;
20   private boolean m_afterClass = false;
21   private boolean m_beforeMethod  = false;
22   private boolean m_afterMethod = false;
23 
24   @BeforeSuite
beforeSuite()25   public void beforeSuite() {
26     ppp("@@@@ BEFORE_SUITE");
27     assert ! m_afterSuite : "afterSuite shouldn't have run";
28     assert ! m_beforeClass : "beforeClass shouldn't have run";
29     assert ! m_afterClass : "afterClass shouldn't have run";
30     assert ! m_beforeMethod: "beforeMethod shouldn't have run";
31     assert ! m_afterMethod: "afterMethod shouldn't have run";
32     m_beforeSuite = true;
33   }
34 
35   @BeforeClass
beforeClass()36   public void beforeClass() {
37     ppp("@@@@ BEFORE_CLASS");
38     assert m_beforeSuite : "beforeSuite should have run";
39     assert ! m_afterSuite : "afterSuite shouldn't have run";
40     assert ! m_beforeClass : "beforeClass shouldn't have run";
41     assert ! m_afterClass : "afterClass shouldn't have run";
42     assert ! m_beforeMethod: "beforeMethod shouldn't have run";
43     assert ! m_afterMethod: "afterMethod shouldn't have run";
44     m_beforeClass = true;
45   }
46 
47   @BeforeMethod
beforeMethod()48   public void beforeMethod() {
49     ppp("@@@@ BEFORE_METHOD");
50     assert m_beforeSuite : "beforeSuite should have run";
51     assert m_beforeClass : "beforeClass have run";
52     assert ! m_afterSuite : "afterSuite shouldn't have run";
53     assert ! m_afterClass : "afterClass shouldn't have run";
54     assert ! m_beforeMethod: "beforeMethod shouldn't have run";
55     assert ! m_afterMethod: "afterMethod shouldn't have run";
56     m_beforeMethod = true;
57   }
58 
59   @AfterMethod
afterMethod()60   public void afterMethod() {
61     ppp("@@@@ AFTER_METHOD");
62     assert m_beforeSuite : "beforeSuite should have run";
63     assert m_beforeClass : "beforeClass have run";
64     assert m_beforeMethod: "beforeMethod should have run";
65     assert ! m_afterSuite : "afterSuite shouldn't have run";
66     assert ! m_afterClass : "afterClass shouldn't have run";
67     assert ! m_afterMethod: "afterMethod shouldn't have run";
68     m_afterMethod = true;
69   }
70 
71   @AfterClass
afterClass()72   public void afterClass() {
73     ppp("@@@@ AFTER_CLASS");
74     assert m_beforeSuite : "beforeSuite should have run";
75     assert m_beforeClass : "beforeClass have run";
76     assert m_beforeMethod: "beforeMethod should have run";
77     assert m_afterMethod: "afterMethod should have run";
78     assert ! m_afterClass : "afterClass shouldn't have run";
79     assert ! m_afterSuite : "afterSuite shouldn't have run";
80     m_afterClass = true;
81   }
82 
83   @AfterSuite
afterSuite()84   public void afterSuite() {
85     ppp("@@@@ AFTER_SUITE");
86     ppp(m_beforeSuite + " " + m_beforeClass + " " + m_beforeMethod
87         + " " + m_afterMethod + " " + m_afterClass + " " + m_afterSuite);
88     assert m_beforeSuite : "beforeSuite should have run";
89     assert m_beforeClass : "beforeClass have run";
90     assert m_beforeMethod: "beforeMethod should have run";
91     assert m_afterMethod: "afterMethod should have run";
92     assert m_afterClass : "afterClass should have run";
93     assert ! m_afterSuite : "afterSuite shouldn't have run";
94     m_afterSuite = true;
95   }
96 
97   @Test
verify()98   public void verify() {
99     ppp("@@@@ VERIFY");
100     assert m_beforeSuite : "beforeSuite should have run";
101     assert m_beforeClass : "beforeClass have run";
102     assert m_beforeMethod: "beforeMethod should have run";
103     assert ! m_afterSuite : "afterSuite shouldn't have run";
104     assert ! m_afterClass : "afterClass shouldn't have run";
105     assert ! m_afterMethod: "afterMethod shouldn't have run";
106   }
107 
ppp(String s)108   private static void ppp(String s) {
109     if (false) {
110       System.out.println("[ConfigurationTest] " + s);
111     }
112   }
113 
114 }
115