if ((null == thisInstance) && Modifier.isAbstract(cls.getModifiers())) {
Utils.log("", 5, "[WARN] Found an abstract class with no valid instance attached: " + cls);
continue;
}
IClass ic= findOrCreateIClass(m_testContext, cls, cim.getXmlClass(cls), thisInstance,
xmlTest, annotationFinder, objectFactory);
if(null != ic) {
Object[] theseInstances = ic.getInstances(false);
if (theseInstances.length == 0) {
theseInstances = ic.getInstances(true);
}
Object instance= theseInstances[0];
putIClass(cls, ic);
ConstructorOrMethod factoryMethod =
ClassHelper.findDeclaredFactoryMethod(cls, annotationFinder);
if (factoryMethod != null && factoryMethod.getEnabled()) {
FactoryMethod fm = new FactoryMethod( /* cls, */
factoryMethod,
instance,
xmlTest,
annotationFinder,
m_testContext);
ClassInfoMap moreClasses = new ClassInfoMap();
{
// ppp("INVOKING FACTORY " + fm + " " + this.hashCode());
Object[] instances= fm.invoke();
//
// If the factory returned IInstanceInfo, get the class from it,
// otherwise, just call getClass() on the returned instances
//
if (instances.length > 0) {
if (instances[0] != null) {
Class elementClass = instances[0].getClass();
if(IInstanceInfo.class.isAssignableFrom(elementClass)) {
for(Object o : instances) {
IInstanceInfo ii = (IInstanceInfo) o;
addInstance(ii.getInstanceClass(), ii.getInstance());
moreClasses.addClass(ii.getInstanceClass());
}
}
else {
for (int i = 0; i < instances.length; i++) {
Object o = instances[i];
if (o == null) {
throw new TestNGException("The factory " + fm + " returned a null instance" +
"at index " + i);
} else {
addInstance(o.getClass(), o);
if(!classExists(o.getClass())) {
moreClasses.addClass(o.getClass());
}
}
}
}
}
}
}
if(moreClasses.getSize() > 0) {
TestNGClassFinder finder=
new TestNGClassFinder(moreClasses,
m_instanceMap,
xmlTest,
configuration,
m_testContext);
IClass[] moreIClasses= finder.findTestClasses();
for(IClass ic2 : moreIClasses) {
putIClass(ic2.getRealClass(), ic2);
}
} // if moreClasses.size() > 0
}
} // null != ic
} // if not TestNG class
else {
Utils.log("TestNGClassFinder", 3, "SKIPPING CLASS " + cls + " no TestNG annotations found");
}
} // for
//
// Add all the instances we found to their respective IClasses
//
for(Class c : m_instanceMap.keySet()) {
List<Object> instances= m_instanceMap.get(c);
for(Object instance : instances) {
IClass ic= getIClass(c);
if(null != ic) {
ic.addInstance(instance);
}
}
}
}