01: package test.factory;
02:
03: import static org.testng.Assert.assertEquals;
04: import static org.testng.Assert.assertTrue;
05:
06: import org.testng.annotations.Factory;
07: import org.testng.annotations.Test;
08:
09: public class NestedFactoryTest {
10: private int m_capacity = 2;
11: private float m_loadFactor = 0.4f;
12:
13: public class NestedFactory {
14: @Factory
15: public Object[] createInstances() {
16: return new NestedFactoryTest[] {
17: new NestedFactoryTest(1, 0.1f),
18: new NestedFactoryTest(10, 0.5f), };
19: }
20: };
21:
22: private static int m_instanceCount = 0;
23:
24: public NestedFactoryTest() {
25: m_instanceCount++;
26: }
27:
28: public NestedFactoryTest(int capacity, float loadFactor) {
29: m_instanceCount++;
30: this .m_capacity = capacity;
31: this .m_loadFactor = loadFactor;
32: }
33:
34: @Test
35: public void verify() {
36: // Should have three instances: the default one created by TestNG
37: // and two created by the factory
38: assertEquals(m_instanceCount, 3);
39: assertTrue((m_capacity == 1 && m_loadFactor == 0.1f)
40: || m_capacity == 10 && m_loadFactor == 0.5f);
41: }
42:
43: private static void ppp(String s) {
44: System.out.println("[NestedFactoryTest] " + s);
45: }
46: }
|