1 package test.inject; 2 3 import org.testng.ITestContext; 4 import org.testng.annotations.DataProvider; 5 import org.testng.annotations.Test; 6 7 import test.dataprovider.MyIterator; 8 9 import java.util.Iterator; 10 11 /** 12 * Test that injection works for data providers. 13 * 14 * @author Cedric Beust, Mar 3, 2010 15 * 16 */ 17 public class InjectDataProviderTest { 18 19 @DataProvider dp1()20 public Object[][] dp1() { 21 return new Object[][] { 22 new Object[] { 1, "a" }, 23 new Object[] { 2, "b" }, 24 }; 25 } 26 27 @Test(dataProvider = "dp1", enabled = true) dpObject1(Integer n, ITestContext ctx, String a)28 public void dpObject1(Integer n, ITestContext ctx, String a) { 29 } 30 31 @Test(dataProvider = "dp1", enabled = true) dpObject2(ITestContext ctx, Integer n, String a)32 public void dpObject2(ITestContext ctx, Integer n, String a) { 33 } 34 35 @Test(dataProvider = "dp1", enabled = true) dpObject3(Integer n, String a, ITestContext ctx)36 public void dpObject3(Integer n, String a, ITestContext ctx) { 37 } 38 39 @DataProvider dp2()40 public Iterator<Object[]> dp2() { 41 return new MyIterator( 42 new Object[][] { 43 new Object[] { 1, "a" }, 44 new Object[] { 2, "b" }, 45 }); 46 } 47 48 @Test(dataProvider = "dp2", enabled = false) dpIterator1(Integer n, ITestContext ctx, String a)49 public void dpIterator1(Integer n, ITestContext ctx, String a) { 50 } 51 52 @Test(dataProvider = "dp2", enabled = false) dpIterator2(ITestContext ctx, Integer n, String a)53 public void dpIterator2(ITestContext ctx, Integer n, String a) { 54 } 55 56 @Test(dataProvider = "dp2", enabled = false) dpIterator3(Integer n, String a, ITestContext ctx)57 public void dpIterator3(Integer n, String a, ITestContext ctx) { 58 } 59 } 60