package org.testng.internal;
import java.lang.reflect.Modifier;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.testng.IInstanceInfo;
import org.testng.ITestContext;
import org.testng.ITestNGMethod;
import org.testng.TestNGException;
import org.testng.collections.Lists;
import org.testng.collections.Maps;
import org.testng.internal.annotations.IAnnotationFinder;
import org.testng.xml.XmlTest;
/**
* This class represents a method annotated with @Factory
*
* @author Cedric Beust
*/
public class FactoryMethod extends BaseTestMethod {
/**
*
*/
private static final long serialVersionUID = -7329918821346197099L;
private Object m_instance = null;
private XmlTest m_xmlTest = null;
private ITestContext m_testContext = null;
public FactoryMethod(ConstructorOrMethod com,
Object instance,
XmlTest xmlTest,
IAnnotationFinder annotationFinder,
ITestContext testContext)
{
super(com.getName(), com, annotationFinder, instance);
Utils.checkInstanceOrStatic(instance, com.getMethod());
Utils.checkReturnType(com.getMethod(), Object[].class, IInstanceInfo[].class);
Class> declaringClass = com.getDeclaringClass();
if (instance != null && ! declaringClass.isAssignableFrom(instance.getClass())) {
throw new TestNGException("Mismatch between instance/method classes:"
+ instance.getClass() + " " + declaringClass);
}
if (instance == null && com.getMethod() != null && !Modifier.isStatic(com.getMethod().getModifiers())) {
throw new TestNGException("An inner factory method MUST be static. But '" + com.getMethod().getName() + "' from '" + declaringClass.getName() + "' is not.");
}
if (com.getMethod() != null && !Modifier.isPublic(com.getMethod().getModifiers())) {
try {
com.getMethod().setAccessible(true);
} catch (SecurityException e) {
throw new TestNGException(e);
}
}
m_instance = instance;
m_xmlTest = xmlTest;
m_testContext = testContext;
NoOpTestClass tc = new NoOpTestClass();
tc.setTestClass(declaringClass);
m_testClass = tc;
}
private static void ppp(String s) {
System.out.println("[FactoryMethod] " + s);
}
public Object[] invoke() {
List