1 package test.objectfactory;
2 
3 import org.testng.Assert;
4 import org.testng.TestNG;
5 import org.testng.annotations.Test;
6 import org.testng.xml.XmlSuite;
7 
8 import test.TestHelper;
9 
10 /**
11  * Test IObjectFactory2, which is an object factory that receives just the Class in parameter.
12  *
13  * @author Cedric Beust <cedric@beust.com>
14  */
15 public class ObjectFactory2Test {
16 
testFactory(boolean onSuite)17   private void testFactory(boolean onSuite) {
18     XmlSuite suite = TestHelper.createSuite(ClassObjectFactorySampleTest.class.getName(),
19         "Test IObjectFactory2");
20     TestNG tng = TestHelper.createTestNG(suite);
21 
22     if (onSuite) suite.setObjectFactory(new ClassObjectFactory());
23     else tng.setObjectFactory(ClassObjectFactory.class);
24 
25     ClassObjectFactorySampleTest.m_n = 0;
26     tng.run();
27     Assert.assertEquals(ClassObjectFactorySampleTest.m_n, 42);
28   }
29 
30   @Test
factoryOnSuiteShouldWork()31   public void factoryOnSuiteShouldWork() {
32     testFactory(true /* on suite object */);
33   }
34 
35   @Test
factoryOnTestNGShouldWork()36   public void factoryOnTestNGShouldWork() {
37     testFactory(false /* on TestNG object */);
38   }
39 }
40