package org.testng.internal;
import org.testng.IMethodSelector;
import org.testng.IMethodSelectorContext;
import org.testng.ITestNGMethod;
import org.testng.collections.Lists;
import java.util.Collections;
import java.util.List;
public class RunInfo {
private final List<MethodSelectorDescriptor>
m_methodSelectors = Lists.newArrayList();
public void addMethodSelector(IMethodSelector selector, int priority) {
Utils.log("RunInfo", 3, "Adding method selector: " + selector + " priority: " + priority);
MethodSelectorDescriptor md = new MethodSelectorDescriptor(selector, priority);
m_methodSelectors.add(md);
}
public boolean includeMethod(ITestNGMethod tm, boolean isTestMethod) {
Collections.sort(m_methodSelectors);
boolean foundNegative = false;
IMethodSelectorContext context = new DefaultMethodSelectorContext();
boolean result = false;
for (MethodSelectorDescriptor mds : m_methodSelectors) {
if (! foundNegative) {
foundNegative = mds.getPriority() < 0;
}
if (foundNegative && mds.getPriority() >= 0) {
break;
}
IMethodSelector md = mds.getMethodSelector();
result = md.includeMethod(context, tm, isTestMethod);
if (context.isStopped()) {
return result;
}
}
return result;
}
public static void ppp(String s) {
System.out.println("[RunInfo] " + s);
}
public void setTestMethods(List<ITestNGMethod> testMethods) {
for (MethodSelectorDescriptor mds : m_methodSelectors) {
mds.setTestMethods(testMethods);
}
}
}