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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Marcus Better
  • Date: 2009-07-23 12:11:17 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090723121117-k1so370589zvpef2
* Changed section to "java".
* debian/rules: Make it work with debhelper 7.3.5. (Closes: #538016)
* Use qdox 1.9 and add a patch for the API changes. Thanks to Ludovic
  Claude.
* debian/control: Bump policy version to 3.8.2.
* debian/control: Build with default-jdk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.testng.internal;
 
2
 
 
3
import org.testng.ITestClass;
 
4
import org.testng.ITestContext;
 
5
import org.testng.ITestNGMethod;
 
6
import org.testng.ITestResult;
 
7
import org.testng.xml.XmlSuite;
 
8
 
 
9
import java.util.ArrayList;
 
10
import java.util.List;
 
11
import java.util.Map;
 
12
import java.util.concurrent.Callable;
 
13
 
 
14
public class TestMethodWithDataProviderMethodWorker implements Callable<List<ITestResult>> {
 
15
  
 
16
  private ITestNGMethod m_testMethod;
 
17
  private Object[] m_parameterValues;
 
18
  private Object[] m_instances;
 
19
  private XmlSuite m_xmlSuite;
 
20
  private Map<String, String> m_parameters;
 
21
  private ITestClass m_testClass;
 
22
  private ITestNGMethod[] m_beforeMethods;
 
23
  private ITestNGMethod[] m_afterMethods;
 
24
  private ConfigurationGroupMethods m_groupMethods;
 
25
  private Invoker m_invoker;
 
26
  private ExpectedExceptionsHolder m_expectedExceptionHolder;
 
27
  private ITestContext m_testContext;
 
28
  private int m_parameterIndex;
 
29
  private boolean m_skipFailedInvocationCounts;
 
30
  private int m_invocationCount;
 
31
  private ITestResultNotifier m_notifier;
 
32
 
 
33
  private List<ITestResult> m_testResults = new ArrayList<ITestResult>();
 
34
  private int m_failureCount;
 
35
 
 
36
  public TestMethodWithDataProviderMethodWorker(Invoker invoker, ITestNGMethod testMethod,
 
37
      int parameterIndex,
 
38
      Object[] parameterValues, Object[] instances, XmlSuite suite,
 
39
      Map<String, String> parameters, ITestClass testClass,
 
40
      ITestNGMethod[] beforeMethods, ITestNGMethod[] afterMethods,
 
41
      ConfigurationGroupMethods groupMethods, ExpectedExceptionsHolder expectedExceptionHolder,
 
42
      ITestContext testContext, boolean skipFailedInvocationCounts,
 
43
      int invocationCount, int failureCount, ITestResultNotifier notifier) {
 
44
    m_invoker = invoker;
 
45
    m_testMethod = testMethod;
 
46
    m_parameterIndex = parameterIndex;
 
47
    m_parameterValues = parameterValues;
 
48
    m_instances = instances;
 
49
    m_xmlSuite = suite;
 
50
    m_parameters = parameters;
 
51
    m_testClass = testClass;
 
52
    m_beforeMethods = beforeMethods;
 
53
    m_afterMethods = afterMethods;
 
54
    m_groupMethods = groupMethods;
 
55
    m_expectedExceptionHolder = expectedExceptionHolder;
 
56
    m_skipFailedInvocationCounts = skipFailedInvocationCounts;
 
57
    m_testContext = testContext;
 
58
    m_invocationCount = invocationCount;
 
59
    m_failureCount = failureCount;
 
60
    m_notifier = notifier;
 
61
  }
 
62
      
 
63
  public long getMaxTimeOut() {
 
64
    return 500;
 
65
  }
 
66
 
 
67
  public List<ITestResult> call() {
 
68
    List<ITestResult> tmpResults = new ArrayList<ITestResult>();
 
69
    long start = System.currentTimeMillis();
 
70
 
 
71
    try {
 
72
      tmpResults.addAll(m_invoker.invokeTestMethod(m_instances,
 
73
           m_testMethod,
 
74
           m_parameterValues,
 
75
           m_xmlSuite,
 
76
           m_parameters,
 
77
           m_testClass,
 
78
           m_beforeMethods,
 
79
           m_afterMethods,
 
80
           m_groupMethods));
 
81
    }
 
82
    finally {
 
83
      List<Object> failedInstances = new ArrayList<Object>();
 
84
 
 
85
      m_failureCount = m_invoker.handleInvocationResults(m_testMethod, tmpResults,
 
86
          failedInstances, m_failureCount, m_expectedExceptionHolder, true,
 
87
          false /* don't collect results */);
 
88
      if (failedInstances.isEmpty()) {
 
89
        m_testResults.addAll(tmpResults);
 
90
      } else {
 
91
        for (int i = 0; i < failedInstances.size(); i++) {
 
92
          List<ITestResult> retryResults = new ArrayList<ITestResult>();
 
93
 
 
94
          m_failureCount = 
 
95
             m_invoker.retryFailed(failedInstances.toArray(),
 
96
                 i, m_testMethod, m_xmlSuite, m_testClass, m_beforeMethods,
 
97
                 m_afterMethods, m_groupMethods, retryResults,
 
98
                 m_failureCount, m_expectedExceptionHolder,
 
99
                 m_testContext, m_parameters, m_parameterIndex);
 
100
          m_testResults.addAll(retryResults);
 
101
        }
 
102
      }
 
103
      
 
104
      //
 
105
      // If we have a failure, skip all the
 
106
      // other invocationCounts
 
107
      //
 
108
      
 
109
      // If not specified globally, use the attribute
 
110
      // on the annotation
 
111
      //
 
112
      if (! m_skipFailedInvocationCounts) {
 
113
        m_skipFailedInvocationCounts = m_testMethod.skipFailedInvocations();
 
114
      }
 
115
      if (m_failureCount > 0 && m_skipFailedInvocationCounts) {
 
116
        while (m_invocationCount-- > 0) {
 
117
          ITestResult r = 
 
118
            new TestResult(m_testMethod.getTestClass(),
 
119
              m_instances[0],
 
120
              m_testMethod,
 
121
              null,
 
122
              start,
 
123
              System.currentTimeMillis());
 
124
          r.setStatus(TestResult.SKIP);
 
125
          m_testResults.add(r);
 
126
          m_invoker.runTestListeners(r);
 
127
          m_notifier.addSkippedTest(m_testMethod, r);
 
128
        }
 
129
      }
 
130
    }
 
131
    m_parameterIndex++;
 
132
    
 
133
    return m_testResults;
 
134
  }
 
135
 
 
136
  public List<ITestResult> getTestResults() {
 
137
    return m_testResults;
 
138
  }
 
139
 
 
140
  public int getInvocationCount() {
 
141
    return m_invocationCount;
 
142
  }
 
143
 
 
144
  public int getFailureCount() {
 
145
    return m_failureCount;
 
146
  }
 
147
}