001: package org.testng;
002:
003: import java.util.ArrayList;
004: import java.util.Collections;
005: import java.util.List;
006:
007: import org.testng.internal.IResultListener;
008:
009: /**
010: * A simple ITestListener adapter that stores all the tests
011: * that were run. You can retrieve these results with the
012: * following methods:
013: * getPassedTests()
014: * getFailedTests()
015: * getSkippedTests()
016: *
017: * If you extend this class in order to override any of these
018: * methods, remember to call their super equivalent if you want
019: * this list of tests to be maintained.
020: *
021: * @author Cedric Beust, Aug 6, 2004
022: * @author <a href='mailto:the_mindstorm@evolva.ro'>Alexandru Popescu</a>
023: */
024: public class TestListenerAdapter implements IResultListener {
025: private List<ITestNGMethod> m_allTestMethods = Collections
026: .synchronizedList(new ArrayList<ITestNGMethod>());
027: private List<ITestResult> m_passedTests = Collections
028: .synchronizedList(new ArrayList<ITestResult>());
029: private List<ITestResult> m_failedTests = Collections
030: .synchronizedList(new ArrayList<ITestResult>());
031: private List<ITestResult> m_skippedTests = Collections
032: .synchronizedList(new ArrayList<ITestResult>());
033: private List<ITestResult> m_failedButWSPerTests = Collections
034: .synchronizedList(new ArrayList<ITestResult>());
035: private List<ITestContext> m_testContexts = Collections
036: .synchronizedList(new ArrayList<ITestContext>());
037: private List<ITestResult> m_failedConfs = Collections
038: .synchronizedList(new ArrayList<ITestResult>());
039: private List<ITestResult> m_skippedConfs = Collections
040: .synchronizedList(new ArrayList<ITestResult>());
041: private List<ITestResult> m_passedConfs = Collections
042: .synchronizedList(new ArrayList<ITestResult>());
043:
044: public void onTestSuccess(ITestResult tr) {
045: m_allTestMethods.add(tr.getMethod());
046: m_passedTests.add(tr);
047: }
048:
049: public void onTestFailure(ITestResult tr) {
050: m_allTestMethods.add(tr.getMethod());
051: m_failedTests.add(tr);
052: }
053:
054: public void onTestSkipped(ITestResult tr) {
055: m_allTestMethods.add(tr.getMethod());
056: m_skippedTests.add(tr);
057: }
058:
059: public void onTestFailedButWithinSuccessPercentage(ITestResult tr) {
060: m_allTestMethods.add(tr.getMethod());
061: m_failedButWSPerTests.add(tr);
062: }
063:
064: protected ITestNGMethod[] getAllTestMethods() {
065: return m_allTestMethods
066: .toArray(new ITestNGMethod[m_allTestMethods.size()]);
067: }
068:
069: public void onStart(ITestContext testContext) {
070: m_testContexts.add(testContext);
071: }
072:
073: public void onFinish(ITestContext testContext) {
074: }
075:
076: /**
077: * @return Returns the failedButWithinSuccessPercentageTests.
078: */
079: public List<ITestResult> getFailedButWithinSuccessPercentageTests() {
080: return m_failedButWSPerTests;
081: }
082:
083: /**
084: * @return Returns the failedTests.
085: */
086: public List<ITestResult> getFailedTests() {
087: return m_failedTests;
088: }
089:
090: /**
091: * @return Returns the passedTests.
092: */
093: public List<ITestResult> getPassedTests() {
094: return m_passedTests;
095: }
096:
097: /**
098: * @return Returns the skippedTests.
099: */
100: public List<ITestResult> getSkippedTests() {
101: return m_skippedTests;
102: }
103:
104: private static void ppp(String s) {
105: System.out.println("[TestListenerAdapter] " + s);
106: }
107:
108: /**
109: * @param allTestMethods The allTestMethods to set.
110: */
111: public void setAllTestMethods(List<ITestNGMethod> allTestMethods) {
112: m_allTestMethods = allTestMethods;
113: }
114:
115: /**
116: * @param failedButWithinSuccessPercentageTests The failedButWithinSuccessPercentageTests to set.
117: */
118: public void setFailedButWithinSuccessPercentageTests(
119: List<ITestResult> failedButWithinSuccessPercentageTests) {
120: m_failedButWSPerTests = failedButWithinSuccessPercentageTests;
121: }
122:
123: /**
124: * @param failedTests The failedTests to set.
125: */
126: public void setFailedTests(List<ITestResult> failedTests) {
127: m_failedTests = failedTests;
128: }
129:
130: /**
131: * @param passedTests The passedTests to set.
132: */
133: public void setPassedTests(List<ITestResult> passedTests) {
134: m_passedTests = passedTests;
135: }
136:
137: /**
138: * @param skippedTests The skippedTests to set.
139: */
140: public void setSkippedTests(List<ITestResult> skippedTests) {
141: m_skippedTests = skippedTests;
142: }
143:
144: public void onTestStart(ITestResult result) {
145: }
146:
147: /**
148: * @return
149: */
150: public List<ITestContext> getTestContexts() {
151: return m_testContexts;
152: }
153:
154: public List<ITestResult> getConfigurationFailures() {
155: return m_failedConfs;
156: }
157:
158: /**
159: * @see org.testng.internal.IConfigurationListener#onConfigurationFailure(org.testng.ITestResult)
160: */
161: public void onConfigurationFailure(ITestResult itr) {
162: m_failedConfs.add(itr);
163: }
164:
165: public List<ITestResult> getConfigurationSkips() {
166: return m_skippedConfs;
167: }
168:
169: /**
170: * @see org.testng.internal.IConfigurationListener#onConfigurationSkip(org.testng.ITestResult)
171: */
172: public void onConfigurationSkip(ITestResult itr) {
173: m_skippedConfs.add(itr);
174: }
175:
176: /**
177: * @see org.testng.internal.IConfigurationListener#onConfigurationSuccess(org.testng.ITestResult)
178: */
179: public void onConfigurationSuccess(ITestResult itr) {
180: m_passedConfs.add(itr);
181: }
182: }
|