since otherwise it conflitcts somewhat with the testXXX methods in a testcase. It leads to terrible code in testcase since we cannot then say that the testcase is a testrunlistener (or a formatter) because of the method naming guidelines. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270540 13f79535-47bb-0310-9956-ffa450edef68master
@@ -80,14 +80,14 @@ public interface TestRunListener { | |||||
* @param a testname made of the testname and testcase classname. | * @param a testname made of the testname and testcase classname. | ||||
* in the following format: <tt><testname>(<testcase>)</tt> | * in the following format: <tt><testname>(<testcase>)</tt> | ||||
*/ | */ | ||||
public void testStarted(String testname); | |||||
public void onTestStarted(String testname); | |||||
/** | /** | ||||
* A test ended. | * A test ended. | ||||
* @param a testname made of the testname and testcase classname. | * @param a testname made of the testname and testcase classname. | ||||
* in the following format: <tt><testname>(<testcase>)</tt> | * in the following format: <tt><testname>(<testcase>)</tt> | ||||
*/ | */ | ||||
public void testEnded(String testname); | |||||
public void onTestEnded(String testname); | |||||
/** | /** | ||||
* A test has failed. | * A test has failed. | ||||
@@ -97,24 +97,24 @@ public interface TestRunListener { | |||||
* @param trace the error/failure stacktrace. | * @param trace the error/failure stacktrace. | ||||
* @todo change this to a testFailure / testError ? | * @todo change this to a testFailure / testError ? | ||||
*/ | */ | ||||
public void testFailed(int status, String testname, String trace); | |||||
public void onTestFailed(int status, String testname, String trace); | |||||
/** test logged this line on stdout */ | /** test logged this line on stdout */ | ||||
public void testStdOutLine(String testname, String line); | |||||
public void onTestStdOutLine(String testname, String line); | |||||
/** test logged this line on sterr */ | /** test logged this line on sterr */ | ||||
public void testStdErrLine(String testname, String line); | |||||
public void onTestStdErrLine(String testname, String line); | |||||
/** these system properties are used on the remote client */ | /** these system properties are used on the remote client */ | ||||
public void testRunSystemProperties(Properties props); | |||||
public void onTestRunSystemProperties(Properties props); | |||||
/** starting a sequence of <tt>testcount</tt> tests. */ | /** starting a sequence of <tt>testcount</tt> tests. */ | ||||
public void testRunStarted(int testcount); | |||||
public void onTestRunStarted(int testcount); | |||||
/** ending gracefully the sequence after <tt>elapsedtime</tt> ms. */ | /** ending gracefully the sequence after <tt>elapsedtime</tt> ms. */ | ||||
public void testRunEnded(long elapsedtime); | |||||
public void onTestRunEnded(long elapsedtime); | |||||
/** stopping the sequence after <tt>elapsedtime</tt> ms. */ | /** stopping the sequence after <tt>elapsedtime</tt> ms. */ | ||||
public void testRunStopped(long elapsedtime); | |||||
public void onTestRunStopped(long elapsedtime); | |||||
} | } |
@@ -100,22 +100,22 @@ public abstract class BaseFormatter implements Formatter { | |||||
public void setSystemError(String err) { | public void setSystemError(String err) { | ||||
} | } | ||||
public void testStdOutLine(String testname, String line) { | |||||
public void onTestStdOutLine(String testname, String line) { | |||||
} | } | ||||
public void testStdErrLine(String testname, String line) { | |||||
public void onTestStdErrLine(String testname, String line) { | |||||
} | } | ||||
public void testRunSystemProperties(Properties props) { | |||||
public void onTestRunSystemProperties(Properties props) { | |||||
} | } | ||||
public void testStarted(String testname) { | |||||
public void onTestStarted(String testname) { | |||||
} | } | ||||
public void testEnded(String testname) { | |||||
public void onTestEnded(String testname) { | |||||
} | } | ||||
public void testFailed(int status, String testname, String trace) { | |||||
public void onTestFailed(int status, String testname, String trace) { | |||||
if (status == STATUS_ERROR) { | if (status == STATUS_ERROR) { | ||||
errorCount++; | errorCount++; | ||||
} else if (status == STATUS_FAILURE) { | } else if (status == STATUS_FAILURE) { | ||||
@@ -123,15 +123,15 @@ public abstract class BaseFormatter implements Formatter { | |||||
} | } | ||||
} | } | ||||
public void testRunStarted(int testcount) { | |||||
public void onTestRunStarted(int testcount) { | |||||
runCount = testcount; | runCount = testcount; | ||||
} | } | ||||
public void testRunEnded(long elapsedtime) { | |||||
public void onTestRunEnded(long elapsedtime) { | |||||
finished(elapsedtime); | finished(elapsedtime); | ||||
} | } | ||||
public void testRunStopped(long elapsedtime) { | |||||
public void onTestRunStopped(long elapsedtime) { | |||||
finished(elapsedtime); | finished(elapsedtime); | ||||
} | } | ||||
@@ -62,7 +62,7 @@ package org.apache.tools.ant.taskdefs.optional.junit.formatter; | |||||
*/ | */ | ||||
public class BriefFormatter extends SummaryFormatter { | public class BriefFormatter extends SummaryFormatter { | ||||
public void testFailed(int status, String testname, String trace) { | |||||
public void onTestFailed(int status, String testname, String trace) { | |||||
writer.print("TestCase: "); | writer.print("TestCase: "); | ||||
writer.print(testname); | writer.print(testname); | ||||
if (status == STATUS_ERROR) { | if (status == STATUS_ERROR) { | ||||
@@ -74,7 +74,7 @@ public class BriefFormatter extends SummaryFormatter { | |||||
writer.print(trace); | writer.print(trace); | ||||
writer.println(); | writer.println(); | ||||
writer.println(); | writer.println(); | ||||
super.testFailed(status, testname, trace); | |||||
super.onTestFailed(status, testname, trace); | |||||
} | } | ||||
} | } |
@@ -63,32 +63,38 @@ import org.apache.tools.ant.taskdefs.optional.junit.TestRunListener; | |||||
*/ | */ | ||||
public class DefaultTestRunListener implements TestRunListener { | public class DefaultTestRunListener implements TestRunListener { | ||||
public void testStarted(String testname) { | |||||
public void onTestStarted(String testname) { | |||||
System.out.println("Started " + testname); | System.out.println("Started " + testname); | ||||
} | } | ||||
public void testEnded(String testname) { | |||||
public void onTestEnded(String testname) { | |||||
System.out.println("Ended " + testname); | System.out.println("Ended " + testname); | ||||
} | } | ||||
public void testFailed(int status, String testname, String trace) { | |||||
public void onTestFailed(int status, String testname, String trace) { | |||||
System.out.println(testname + " failed with status " + status); | System.out.println(testname + " failed with status " + status); | ||||
System.out.println(trace); | System.out.println(trace); | ||||
} | } | ||||
public void testRunSystemProperties(Properties props) { | |||||
public void onTestRunSystemProperties(Properties props) { | |||||
System.out.println("properties: " + props); | System.out.println("properties: " + props); | ||||
} | } | ||||
public void testRunStarted(int testcount) { | |||||
public void onTestRunStarted(int testcount) { | |||||
System.out.println("testsuite: " + testcount); | System.out.println("testsuite: " + testcount); | ||||
} | } | ||||
public void testRunEnded(long elapsedtime) { | |||||
public void onTestStdOutLine(String testname, String line) { | |||||
} | |||||
public void onTestStdErrLine(String testname, String line) { | |||||
} | |||||
public void onTestRunEnded(long elapsedtime) { | |||||
System.out.println("testsuite ended after: " + elapsedtime); | System.out.println("testsuite ended after: " + elapsedtime); | ||||
} | } | ||||
public void testRunStopped(long elapsedtime) { | |||||
public void onTestRunStopped(long elapsedtime) { | |||||
System.out.println("testsuite stopped after: " + elapsedtime); | System.out.println("testsuite stopped after: " + elapsedtime); | ||||
} | } | ||||
} | } |
@@ -73,39 +73,47 @@ public abstract class FilterFormatter implements Formatter { | |||||
formatter.setOutput(out); | formatter.setOutput(out); | ||||
} | } | ||||
public void testStarted(String testname) { | |||||
formatter.testStarted(testname); | |||||
public void onTestStdOutLine(String testname, String line) { | |||||
formatter.onTestStdOutLine(testname, line); | |||||
} | |||||
public void onTestStdErrLine(String testname, String line) { | |||||
formatter.onTestStdErrLine(testname, line); | |||||
} | |||||
public void onTestStarted(String testname) { | |||||
formatter.onTestStarted(testname); | |||||
} | } | ||||
public void setSystemOutput(String out) { | public void setSystemOutput(String out) { | ||||
formatter.setSystemOutput(out); | formatter.setSystemOutput(out); | ||||
} | } | ||||
public void testEnded(String testname) { | |||||
formatter.testEnded(testname); | |||||
public void onTestEnded(String testname) { | |||||
formatter.onTestEnded(testname); | |||||
} | } | ||||
public void setSystemError(String err) { | public void setSystemError(String err) { | ||||
formatter.setSystemError(err); | formatter.setSystemError(err); | ||||
} | } | ||||
public void testFailed(int status, String testname, String trace) { | |||||
formatter.testFailed(status, testname, trace); | |||||
public void onTestFailed(int status, String testname, String trace) { | |||||
formatter.onTestFailed(status, testname, trace); | |||||
} | } | ||||
public void testRunSystemProperties(Properties props) { | |||||
formatter.testRunSystemProperties(props); | |||||
public void onTestRunSystemProperties(Properties props) { | |||||
formatter.onTestRunSystemProperties(props); | |||||
} | } | ||||
public void testRunStarted(int testcount) { | |||||
formatter.testRunStarted(testcount); | |||||
public void onTestRunStarted(int testcount) { | |||||
formatter.onTestRunStarted(testcount); | |||||
} | } | ||||
public void testRunEnded(long elapsedtime) { | |||||
formatter.testRunEnded(elapsedtime); | |||||
public void onTestRunEnded(long elapsedtime) { | |||||
formatter.onTestRunEnded(elapsedtime); | |||||
} | } | ||||
public void testRunStopped(long elapsedtime) { | |||||
formatter.testRunEnded(elapsedtime); | |||||
public void onTestRunStopped(long elapsedtime) { | |||||
formatter.onTestRunEnded(elapsedtime); | |||||
} | } | ||||
} | } |
@@ -103,7 +103,7 @@ public class FilterStackFormatter extends FilterFormatter { | |||||
super(formatter); | super(formatter); | ||||
} | } | ||||
public void testFailed(int status, String testname, String trace) { | |||||
public void onTestFailed(int status, String testname, String trace) { | |||||
StringTokenizer st = new StringTokenizer(trace,"\r\n"); | StringTokenizer st = new StringTokenizer(trace,"\r\n"); | ||||
StringBuffer buf = new StringBuffer(trace.length()); | StringBuffer buf = new StringBuffer(trace.length()); | ||||
while ( st.hasMoreTokens() ){ | while ( st.hasMoreTokens() ){ | ||||
@@ -112,7 +112,7 @@ public class FilterStackFormatter extends FilterFormatter { | |||||
buf.append(line).append(StringUtils.LINE_SEP); | buf.append(line).append(StringUtils.LINE_SEP); | ||||
} | } | ||||
} | } | ||||
super.testFailed(status, testname, buf.toString()); | |||||
super.onTestFailed(status, testname, buf.toString()); | |||||
} | } | ||||
/** | /** | ||||
@@ -54,6 +54,7 @@ | |||||
package org.apache.tools.ant.taskdefs.optional.junit.formatter; | package org.apache.tools.ant.taskdefs.optional.junit.formatter; | ||||
import java.text.MessageFormat; | import java.text.MessageFormat; | ||||
import java.util.ResourceBundle; | |||||
/** | /** | ||||
* Display a summary message at the end of a testsuite stating | * Display a summary message at the end of a testsuite stating | ||||
@@ -135,35 +135,35 @@ public class XMLFormatter extends BaseFormatter { | |||||
/** Timing helper. */ | /** Timing helper. */ | ||||
private Hashtable testStarts = new Hashtable(); | private Hashtable testStarts = new Hashtable(); | ||||
public void testStarted(String testname) { | |||||
public void onTestStarted(String testname) { | |||||
//@fixme, eh, a testname only can obviouslly be a duplicate... | //@fixme, eh, a testname only can obviouslly be a duplicate... | ||||
testStarts.put(testname, new Long(System.currentTimeMillis())); | testStarts.put(testname, new Long(System.currentTimeMillis())); | ||||
Element currentTest = doc.createElement(TESTCASE); | Element currentTest = doc.createElement(TESTCASE); | ||||
currentTest.setAttribute(ATTR_NAME, testname); | currentTest.setAttribute(ATTR_NAME, testname); | ||||
rootElement.appendChild(currentTest); | rootElement.appendChild(currentTest); | ||||
testElements.put(testname, currentTest); | testElements.put(testname, currentTest); | ||||
super.testStarted(testname); | |||||
super.onTestStarted(testname); | |||||
} | } | ||||
public void testEnded(String testname) { | |||||
public void onTestEnded(String testname) { | |||||
Element currentTest = (Element) testElements.get(testname); | Element currentTest = (Element) testElements.get(testname); | ||||
// with a TestSetup, startTest and endTest are not called. | // with a TestSetup, startTest and endTest are not called. | ||||
if (currentTest == null){ | if (currentTest == null){ | ||||
testStarted(testname); | |||||
onTestStarted(testname); | |||||
currentTest = (Element) testElements.get(testname); | currentTest = (Element) testElements.get(testname); | ||||
} | } | ||||
Long l = (Long) testStarts.get(testname); | Long l = (Long) testStarts.get(testname); | ||||
float time = ((System.currentTimeMillis()-l.longValue()) / 1000.0f); | float time = ((System.currentTimeMillis()-l.longValue()) / 1000.0f); | ||||
currentTest.setAttribute(ATTR_TIME, Float.toString(time)); | currentTest.setAttribute(ATTR_TIME, Float.toString(time)); | ||||
super.testEnded(testname); | |||||
super.onTestEnded(testname); | |||||
// remove the test objects | // remove the test objects | ||||
testStarts.remove(testname); | testStarts.remove(testname); | ||||
testElements.remove(testname); | testElements.remove(testname); | ||||
} | } | ||||
public void testFailed(int status, String testname, String trace) { | |||||
public void onTestFailed(int status, String testname, String trace) { | |||||
if (testname != null) { | if (testname != null) { | ||||
testEnded(testname); | |||||
onTestEnded(testname); | |||||
} | } | ||||
String type = status == STATUS_FAILURE ? FAILURE : ERROR; | String type = status == STATUS_FAILURE ? FAILURE : ERROR; | ||||
Element nested = doc.createElement(type); | Element nested = doc.createElement(type); | ||||
@@ -183,19 +183,19 @@ public class XMLFormatter extends BaseFormatter { | |||||
nested.setAttribute(ATTR_TYPE, args[0]); | nested.setAttribute(ATTR_TYPE, args[0]); | ||||
Text text = doc.createTextNode(trace); | Text text = doc.createTextNode(trace); | ||||
nested.appendChild(text); | nested.appendChild(text); | ||||
super.testFailed(status, testname, trace); | |||||
super.onTestFailed(status, testname, trace); | |||||
} | } | ||||
public void testRunStarted(int testcount) { | |||||
super.testRunStarted(testcount); | |||||
public void onTestRunStarted(int testcount) { | |||||
super.onTestRunStarted(testcount); | |||||
} | } | ||||
public void testRunEnded(long elapsedtime) { | |||||
super.testRunEnded(elapsedtime); | |||||
public void onTestRunEnded(long elapsedtime) { | |||||
super.onTestRunEnded(elapsedtime); | |||||
} | } | ||||
public void testRunStopped(long elapsedtime) { | |||||
super.testRunStopped(elapsedtime); | |||||
public void onTestRunStopped(long elapsedtime) { | |||||
super.onTestRunStopped(elapsedtime); | |||||
} | } | ||||
private static DocumentBuilder getDocumentBuilder() { | private static DocumentBuilder getDocumentBuilder() { | ||||
@@ -190,7 +190,7 @@ public class MessageReader { | |||||
protected void notifyTestStarted(String testname) { | protected void notifyTestStarted(String testname) { | ||||
synchronized (listeners) { | synchronized (listeners) { | ||||
for (int i = 0; i < listeners.size(); i++) { | for (int i = 0; i < listeners.size(); i++) { | ||||
((TestRunListener) listeners.elementAt(i)).testStarted(testname); | |||||
((TestRunListener) listeners.elementAt(i)).onTestStarted(testname); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -198,7 +198,7 @@ public class MessageReader { | |||||
protected void notifyTestEnded(String testname) { | protected void notifyTestEnded(String testname) { | ||||
synchronized (listeners) { | synchronized (listeners) { | ||||
for (int i = 0; i < listeners.size(); i++) { | for (int i = 0; i < listeners.size(); i++) { | ||||
((TestRunListener) listeners.elementAt(i)).testEnded(testname); | |||||
((TestRunListener) listeners.elementAt(i)).onTestEnded(testname); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -206,7 +206,7 @@ public class MessageReader { | |||||
protected void notifyTestFailed(int kind, String testname, String trace) { | protected void notifyTestFailed(int kind, String testname, String trace) { | ||||
synchronized (listeners) { | synchronized (listeners) { | ||||
for (int i = 0; i < listeners.size(); i++) { | for (int i = 0; i < listeners.size(); i++) { | ||||
((TestRunListener) listeners.elementAt(i)).testFailed(kind, testname, trace); | |||||
((TestRunListener) listeners.elementAt(i)).onTestFailed(kind, testname, trace); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -214,7 +214,7 @@ public class MessageReader { | |||||
protected void notifyTestSuiteStarted(int count) { | protected void notifyTestSuiteStarted(int count) { | ||||
synchronized (listeners) { | synchronized (listeners) { | ||||
for (int i = 0; i < listeners.size(); i++) { | for (int i = 0; i < listeners.size(); i++) { | ||||
((TestRunListener) listeners.elementAt(i)).testRunStarted(count); | |||||
((TestRunListener) listeners.elementAt(i)).onTestRunStarted(count); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -222,7 +222,7 @@ public class MessageReader { | |||||
protected void notifyTestSuiteEnded(long elapsedtime) { | protected void notifyTestSuiteEnded(long elapsedtime) { | ||||
synchronized (listeners) { | synchronized (listeners) { | ||||
for (int i = 0; i < listeners.size(); i++) { | for (int i = 0; i < listeners.size(); i++) { | ||||
((TestRunListener) listeners.elementAt(i)).testRunEnded(elapsedtime); | |||||
((TestRunListener) listeners.elementAt(i)).onTestRunEnded(elapsedtime); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -230,7 +230,7 @@ public class MessageReader { | |||||
protected void notifyTestSuiteStopped(long elapsedtime) { | protected void notifyTestSuiteStopped(long elapsedtime) { | ||||
synchronized (listeners) { | synchronized (listeners) { | ||||
for (int i = 0; i < listeners.size(); i++) { | for (int i = 0; i < listeners.size(); i++) { | ||||
((TestRunListener) listeners.elementAt(i)).testRunStopped(elapsedtime); | |||||
((TestRunListener) listeners.elementAt(i)).onTestRunStopped(elapsedtime); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -238,7 +238,7 @@ public class MessageReader { | |||||
protected void notifyTestSystemProperties(Properties props) { | protected void notifyTestSystemProperties(Properties props) { | ||||
synchronized (listeners) { | synchronized (listeners) { | ||||
for (int i = 0; i < listeners.size(); i++) { | for (int i = 0; i < listeners.size(); i++) { | ||||
((TestRunListener) listeners.elementAt(i)).testRunSystemProperties(props); | |||||
((TestRunListener) listeners.elementAt(i)).onTestRunSystemProperties(props); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -111,7 +111,7 @@ public class FilterStackFormatterTest extends TestCase { | |||||
public void testFiltering() { | public void testFiltering() { | ||||
FilterStackFormatter wrapper = new FilterStackFormatter(wrapped); | FilterStackFormatter wrapper = new FilterStackFormatter(wrapped); | ||||
wrapper.testFailed(0, "", trace); | |||||
wrapper.onTestFailed(0, "", trace); | |||||
assertEquals(expected, wrapped.trace); | assertEquals(expected, wrapped.trace); | ||||
} | } | ||||
@@ -121,38 +121,38 @@ public class FilterStackFormatterTest extends TestCase { | |||||
public void setOutput(OutputStream out) { | public void setOutput(OutputStream out) { | ||||
} | } | ||||
public void testStarted(String testname) { | |||||
public void onTestStarted(String testname) { | |||||
} | } | ||||
public void setSystemOutput(String out) { | public void setSystemOutput(String out) { | ||||
} | } | ||||
public void testEnded(String testname) { | |||||
public void onTestEnded(String testname) { | |||||
} | } | ||||
public void setSystemError(String err) { | public void setSystemError(String err) { | ||||
} | } | ||||
public void testFailed(int status, String testname, String trace) { | |||||
public void onTestFailed(int status, String testname, String trace) { | |||||
this.trace = trace; | this.trace = trace; | ||||
} | } | ||||
public void testStdOutLine(String testname, String line) { | |||||
public void onTestStdOutLine(String testname, String line) { | |||||
} | } | ||||
public void testStdErrLine(String testname, String line) { | |||||
public void onTestStdErrLine(String testname, String line) { | |||||
} | } | ||||
public void testRunSystemProperties(Properties props) { | |||||
public void onTestRunSystemProperties(Properties props) { | |||||
} | } | ||||
public void testRunStarted(int testcount) { | |||||
public void onTestRunStarted(int testcount) { | |||||
} | } | ||||
public void testRunEnded(long elapsedtime) { | |||||
public void onTestRunEnded(long elapsedtime) { | |||||
} | } | ||||
public void testRunStopped(long elapsedtime) { | |||||
public void onTestRunStopped(long elapsedtime) { | |||||
} | } | ||||
} | } | ||||
} | } |