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