1package test.inject;
2
3import org.testng.Assert;
4import org.testng.annotations.AfterMethod;
5import org.testng.annotations.BeforeMethod;
6import org.testng.annotations.DataProvider;
7import org.testng.annotations.Test;
8
9import java.lang.reflect.Method;
10
11public 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
20  public void before(Object[] parameters) {
21    Assert.assertEquals(DATA[m_beforeIndex], parameters);
22    m_beforeIndex++;
23  }
24
25  @BeforeMethod
26  public void before2(Object[] parameters, Method m) {
27  }
28
29  @BeforeMethod
30  public void before3(Method m, Object[] parameters) {
31  }
32
33  @DataProvider
34  public Object[][] dp() {
35    return DATA;
36  }
37
38  @AfterMethod
39  public void after(Object[] parameters) {
40    Assert.assertEquals(DATA[m_afterIndex], parameters);
41    m_afterIndex++;
42  }
43
44  @Test(dataProvider = "dp")
45  public void f(String a) {
46  }
47
48}
49