01: package org.testng.internal;
02:
03: import java.io.Serializable;
04: import java.util.ArrayList;
05: import java.util.Collections;
06: import java.util.List;
07:
08: import org.testng.IMethodSelector;
09: import org.testng.IMethodSelectorContext;
10: import org.testng.ITestNGMethod;
11:
12: /**
13: * This class contains all the information needed to determine
14: * what methods should be run. It gets invoked by the TestRunner
15: * and then goes through its list of method selectors to decide what methods
16: * need to be run.
17: *
18: * @author <a href="mailto:cedric@beust.com">Cedric Beust</a>
19: */
20: public class RunInfo implements Serializable {
21: transient private List<MethodSelectorDescriptor> m_methodSelectors = new ArrayList<MethodSelectorDescriptor>();
22:
23: public void addMethodSelector(IMethodSelector selector, int priority) {
24: Utils.log("RunInfo", 3, "Adding method selector: " + selector
25: + " priority: " + priority);
26: MethodSelectorDescriptor md = new MethodSelectorDescriptor(
27: selector, priority);
28: m_methodSelectors.add(md);
29: }
30:
31: /**
32: * @return true as soon as we fond a Method Selector that returns
33: * true for the method "tm".
34: */
35: public boolean includeMethod(ITestNGMethod tm, boolean isTestMethod) {
36: Collections.sort(m_methodSelectors);
37: boolean foundNegative = false;
38: IMethodSelectorContext context = new DefaultMethodSelectorContext();
39:
40: boolean result = false;
41: for (MethodSelectorDescriptor mds : m_methodSelectors) {
42: // If we found any negative priority, we break as soon as we encounter
43: // a selector with a positive priority
44: if (!foundNegative)
45: foundNegative = mds.getPriority() < 0;
46: if (foundNegative && mds.getPriority() >= 0)
47: break;
48:
49: // Proceeed normally
50: IMethodSelector md = mds.getMethodSelector();
51: result = md.includeMethod(context, tm, isTestMethod);
52: if (context.isStopped()) {
53: return result;
54: }
55:
56: // This selector returned false, move on to the next
57: }
58:
59: return result;
60: }
61:
62: public static void ppp(String s) {
63: System.out.println("[RunInfo] " + s);
64: }
65:
66: public void setTestMethods(List<ITestNGMethod> testMethods) {
67: for (MethodSelectorDescriptor mds : m_methodSelectors) {
68: mds.setTestMethods(testMethods);
69: }
70: }
71: }
|