1 package test.inject; 2 3 import org.testng.Assert; 4 import org.testng.annotations.AfterMethod; 5 import org.testng.annotations.BeforeMethod; 6 import org.testng.annotations.DataProvider; 7 import org.testng.annotations.Test; 8 9 import java.lang.reflect.Method; 10 11 public class InjectBeforeMethodTest { 12 private int m_beforeIndex = 0; 13 private int m_afterIndex = 0; 14 private static final Object[][] DATA = { 15 new Object[] { "a" }, 16 new Object[] { "b" }, 17 }; 18 19 @BeforeMethod before(Object[] parameters)20 public void before(Object[] parameters) { 21 Assert.assertEquals(DATA[m_beforeIndex], parameters); 22 m_beforeIndex++; 23 } 24 25 @BeforeMethod before2(Object[] parameters, Method m)26 public void before2(Object[] parameters, Method m) { 27 } 28 29 @BeforeMethod before3(Method m, Object[] parameters)30 public void before3(Method m, Object[] parameters) { 31 } 32 33 @DataProvider dp()34 public Object[][] dp() { 35 return DATA; 36 } 37 38 @AfterMethod after(Object[] parameters)39 public void after(Object[] parameters) { 40 Assert.assertEquals(DATA[m_afterIndex], parameters); 41 m_afterIndex++; 42 } 43 44 @Test(dataProvider = "dp") f(String a)45 public void f(String a) { 46 } 47 48 } 49