1 package test.factory; 2 3 import org.testng.annotations.DataProvider; 4 import org.testng.annotations.Factory; 5 6 import java.util.ArrayList; 7 import java.util.List; 8 9 public class FactoryWithDataProvider { 10 11 @DataProvider dp()12 public Object[][] dp() { 13 return new Object[][] { 14 new Object[] { new int[] { 3, 5 } }, 15 new Object[] { new int [] { 7, 9 } }, 16 }; 17 } 18 19 @Factory(dataProvider = "dp") factory(int[] array)20 public Object[] factory(int[] array) { 21 List<Object> result = new ArrayList<>(); 22 for (int n : array) { 23 result.add(new OddTest(n)); 24 } 25 26 return result.toArray(); 27 } 28 ppp(String s)29 private static void ppp(String s) { 30 System.out.println("[FactoryWithDataProvider] " + s); 31 } 32 33 } 34