1 package test.factory; 2 3 import static org.testng.Assert.assertFalse; 4 5 import org.testng.IInstanceInfo; 6 import org.testng.annotations.BeforeSuite; 7 import org.testng.annotations.Factory; 8 import org.testng.annotations.Parameters; 9 import org.testng.internal.InstanceInfo; 10 11 public class FactoryWithInstanceInfoTest { 12 static boolean m_invoked = false; 13 14 @Parameters({ "factory-param" }) 15 @Factory createObjectsWithInstanceInfo(String param)16 public IInstanceInfo[] createObjectsWithInstanceInfo(String param) 17 { 18 assert "FactoryParam".equals(param) : "Incorrect param: " + param; 19 20 assertFalse(m_invoked, "Should only be invoked once"); 21 m_invoked = true; 22 23 return new IInstanceInfo[] { 24 new InstanceInfo(FactoryWithInstanceInfoTest2.class, 25 new FactoryWithInstanceInfoTest2(42)), 26 new InstanceInfo(FactoryWithInstanceInfoTest2.class, 27 new FactoryWithInstanceInfoTest2(43)), 28 }; 29 } 30 31 @BeforeSuite beforeSuite()32 public void beforeSuite() { 33 m_invoked = false; 34 } 35 ppp(String s)36 private static void ppp(String s) { 37 System.out.println("[FactoryWithInstanceInfoTest] " + s); 38 } 39 }