~ubuntu-branches/ubuntu/utopic/testng/utopic

« back to all changes in this revision

Viewing changes to src/main/org/testng/internal/RunInfo.java

  • Committer: Bazaar Package Importer
  • Author(s): Marcus Better
  • Date: 2009-05-04 10:47:43 UTC
  • Revision ID: james.westby@ubuntu.com-20090504104743-1gbwsis9q1fh3aaj
Tags: upstream-5.9+dfsg
ImportĀ upstreamĀ versionĀ 5.9+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.testng.internal;
 
2
 
 
3
import java.io.Serializable;
 
4
import java.util.ArrayList;
 
5
import java.util.Collections;
 
6
import java.util.List;
 
7
 
 
8
import org.testng.IMethodSelector;
 
9
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>
 
22
    m_methodSelectors = new ArrayList<MethodSelectorDescriptor>();
 
23
  
 
24
  public void addMethodSelector(IMethodSelector selector, int priority) {
 
25
    Utils.log("RunInfo", 3, "Adding method selector: " + selector + " priority: " + priority);
 
26
    MethodSelectorDescriptor md = new MethodSelectorDescriptor(selector, priority);
 
27
    m_methodSelectors.add(md);
 
28
  }
 
29
  
 
30
  /**
 
31
   * @return true as soon as we fond a Method Selector that returns
 
32
   * true for the method "tm".
 
33
   */
 
34
  public boolean includeMethod(ITestNGMethod tm, boolean isTestMethod) {
 
35
    Collections.sort(m_methodSelectors);
 
36
    boolean foundNegative = false;
 
37
    IMethodSelectorContext context = new DefaultMethodSelectorContext();
 
38
    
 
39
    boolean result = false;
 
40
    for (MethodSelectorDescriptor mds : m_methodSelectors) {
 
41
      // If we found any negative priority, we break as soon as we encounter
 
42
      // a selector with a positive priority
 
43
      if (! foundNegative) foundNegative = mds.getPriority() < 0;
 
44
      if (foundNegative && mds.getPriority() >= 0) break;
 
45
      
 
46
      // Proceeed normally
 
47
      IMethodSelector md = mds.getMethodSelector();
 
48
      result = md.includeMethod(context, tm, isTestMethod);
 
49
      if (context.isStopped()) {
 
50
        return result;
 
51
      }
 
52
      
 
53
      // This selector returned false, move on to the next
 
54
    }
 
55
    
 
56
    return result;
 
57
  }
 
58
  
 
59
  public static void ppp(String s) {
 
60
    System.out.println("[RunInfo] " + s);
 
61
  }
 
62
 
 
63
  public void setTestMethods(List<ITestNGMethod> testMethods) {
 
64
    for (MethodSelectorDescriptor mds : m_methodSelectors) {
 
65
      mds.setTestMethods(testMethods);
 
66
    }
 
67
  }
 
68
}