1 package test.configuration; 2 3 import org.testng.Assert; 4 import org.testng.annotations.AfterClass; 5 import org.testng.annotations.AfterMethod; 6 import org.testng.annotations.BeforeMethod; 7 import org.testng.annotations.Test; 8 9 import java.lang.reflect.Method; 10 import java.util.HashMap; 11 import java.util.Map; 12 13 14 /** 15 * This class/interface 16 */ 17 public class ReflectMethodParametrizedConfigurationMethodTest { 18 private Map<String, String> m_before= new HashMap<>(); 19 private Map<String, String> m_after= new HashMap<>(); 20 21 @BeforeMethod beforeMethod(Method tobeInvokedTestMethod)22 public void beforeMethod(Method tobeInvokedTestMethod) { 23 m_before.put(tobeInvokedTestMethod.getName(), tobeInvokedTestMethod.getName()); 24 } 25 26 @Test test1()27 public void test1() {} 28 29 @Test test2()30 public void test2() {} 31 32 @AfterMethod afterMethod(Method invokedTestMethod)33 public void afterMethod(Method invokedTestMethod) { 34 m_after.put(invokedTestMethod.getName(), invokedTestMethod.getName()); 35 } 36 37 @AfterClass assertBeforeAfterMethodsInvocations()38 public void assertBeforeAfterMethodsInvocations() { 39 Assert.assertTrue(m_before.containsKey("test1"), "@Test method should have been passed to @BeforeMethod"); 40 Assert.assertTrue(m_before.containsKey("test2"), "@Test method should have been passed to @BeforeMethod"); 41 Assert.assertTrue(m_after.containsKey("test1"), "@Test method should have been passed to @AfterMethod"); 42 Assert.assertTrue(m_before.containsKey("test2"), "@Test method should have been passed to @AfterMethod"); 43 } 44 } 45