01: package test.factory;
02:
03: import org.testng.Assert;
04: import org.testng.IInstanceInfo;
05:
06: public class IInstanceFactory {
07: private static boolean m_invoked = false;
08:
09: /**
10: * @testng.factory
11: */
12: public Object[] createObjects() {
13: return new IInstanceInfo[] { new MyInstanceInfo(
14: TestInterface.class, new TestInterfaceImpl()) };
15: }
16:
17: /**
18: * @testng.after-test
19: */
20: public void afterVerification() {
21: Assert
22: .assertTrue(m_invoked,
23: "implementation of TestInterface test method should have been invoked");
24: }
25:
26: public static class MyInstanceInfo implements IInstanceInfo {
27: private Class m_clazz;
28: private Object m_instance;
29:
30: public MyInstanceInfo(Class clazz, Object instance) {
31: m_clazz = clazz;
32: m_instance = instance;
33: }
34:
35: public Object getInstance() {
36: return m_instance;
37: }
38:
39: public Class getInstanceClass() {
40: return m_clazz;
41: }
42: }
43:
44: public static interface TestInterface {
45: /**
46: * @testng.test
47: */
48: void testMethod();
49: }
50:
51: public static class TestInterfaceImpl implements TestInterface {
52:
53: public void testMethod() {
54: m_invoked = true;
55: }
56:
57: }
58: }
|