Browse Source

javadoc

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@473558 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 19 years ago
parent
commit
1f52126472
7 changed files with 151 additions and 4 deletions
  1. +32
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskMirror.java
  2. +7
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskMirrorImpl.java
  3. +62
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java
  4. +18
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
  5. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java
  6. +16
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/junit/SummaryJUnitResultFormatter.java
  7. +15
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java

+ 32
- 1
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskMirror.java View File

@@ -143,15 +143,46 @@ public interface JUnitTaskMirror {
*/ */
int getRetCode(); int getRetCode();


/**
* Handle output sent to System.err.
*
* @param output coming from System.err
*/
void handleErrorFlush(String output); void handleErrorFlush(String output);


/**
* Handle output sent to System.err.
*
* @param output output for System.err
*/
void handleErrorOutput(String output); void handleErrorOutput(String output);


/**
* Handle output sent to System.out.
*
* @param output output for System.out.
*/
void handleOutput(String output); void handleOutput(String output);


/**
* Handle an input request.
*
* @param buffer the buffer into which data is to be read.
* @param offset the offset into the buffer at which data is stored.
* @param length the amount of data to read.
*
* @return the number of bytes read.
*
* @exception IOException if the data cannot be read.
*/
int handleInput(byte[] buffer, int offset, int length) throws IOException; int handleInput(byte[] buffer, int offset, int length) throws IOException;


void handleFlush(String output);
/**
* Handle output sent to System.out.
*
* @param output output for System.out.
*/
void handleFlush(String output);


} }
} }

+ 7
- 0
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskMirrorImpl.java View File

@@ -35,10 +35,15 @@ public final class JUnitTaskMirrorImpl implements JUnitTaskMirror {


private final JUnitTask task; private final JUnitTask task;


/**
* Constructor.
* @param task the junittask that uses this mirror.
*/
public JUnitTaskMirrorImpl(JUnitTask task) { public JUnitTaskMirrorImpl(JUnitTask task) {
this.task = task; this.task = task;
} }


/** {@inheritDoc}. */
public void addVmExit(JUnitTest test, JUnitTaskMirror.JUnitResultFormatterMirror aFormatter, public void addVmExit(JUnitTest test, JUnitTaskMirror.JUnitResultFormatterMirror aFormatter,
OutputStream out, String message, String testCase) { OutputStream out, String message, String testCase) {
JUnitResultFormatter formatter = (JUnitResultFormatter) aFormatter; JUnitResultFormatter formatter = (JUnitResultFormatter) aFormatter;
@@ -53,6 +58,7 @@ public final class JUnitTaskMirrorImpl implements JUnitTaskMirror {
formatter.endTestSuite(test); formatter.endTestSuite(test);
} }


/** {@inheritDoc}. */
public JUnitTaskMirror.JUnitTestRunnerMirror newJUnitTestRunner(JUnitTest test, public JUnitTaskMirror.JUnitTestRunnerMirror newJUnitTestRunner(JUnitTest test,
boolean haltOnError, boolean filterTrace, boolean haltOnFailure, boolean haltOnError, boolean filterTrace, boolean haltOnFailure,
boolean showOutput, boolean logTestListenerEvents, AntClassLoader classLoader) { boolean showOutput, boolean logTestListenerEvents, AntClassLoader classLoader) {
@@ -60,6 +66,7 @@ public final class JUnitTaskMirrorImpl implements JUnitTaskMirror {
showOutput, logTestListenerEvents, classLoader); showOutput, logTestListenerEvents, classLoader);
} }


/** {@inheritDoc}. */
public JUnitTaskMirror.SummaryJUnitResultFormatterMirror newSummaryJUnitResultFormatter() { public JUnitTaskMirror.SummaryJUnitResultFormatterMirror newSummaryJUnitResultFormatter() {
return new SummaryJUnitResultFormatter(); return new SummaryJUnitResultFormatter();
} }


+ 62
- 0
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java View File

@@ -52,13 +52,25 @@ public class JUnitTest extends BaseTest implements Cloneable {
// Snapshot of the system properties // Snapshot of the system properties
private Properties props = null; private Properties props = null;


/** No arg constructor. */
public JUnitTest() { public JUnitTest() {
} }


/**
* Constructor with name.
* @param name the name of the test.
*/
public JUnitTest(String name) { public JUnitTest(String name) {
this.name = name; this.name = name;
} }


/**
* Constructor with options.
* @param name the name of the test.
* @param haltOnError if true halt the tests if there is an error.
* @param haltOnFailure if true halt the tests if there is a failure.
* @param filtertrace if true filter stack traces.
*/
public JUnitTest(String name, boolean haltOnError, boolean haltOnFailure, public JUnitTest(String name, boolean haltOnError, boolean haltOnFailure,
boolean filtertrace) { boolean filtertrace) {
this.name = name; this.name = name;
@@ -69,6 +81,7 @@ public class JUnitTest extends BaseTest implements Cloneable {


/** /**
* Set the name of the test class. * Set the name of the test class.
* @param value the name to use.
*/ */
public void setName(String value) { public void setName(String value) {
name = value; name = value;
@@ -76,6 +89,7 @@ public class JUnitTest extends BaseTest implements Cloneable {


/** /**
* Set the name of the output file. * Set the name of the output file.
* @param value the name of the output file to use.
*/ */
public void setOutfile(String value) { public void setOutfile(String value) {
outfile = value; outfile = value;
@@ -83,6 +97,7 @@ public class JUnitTest extends BaseTest implements Cloneable {


/** /**
* Get the name of the test class. * Get the name of the test class.
* @return the name of the test.
*/ */
public String getName() { public String getName() {
return name; return name;
@@ -97,36 +112,71 @@ public class JUnitTest extends BaseTest implements Cloneable {
return outfile; return outfile;
} }


/**
* Set the number of runs, failures and errors.
* @param runs the number of runs.
* @param failures the number of failures.
* @param errors the number of errors.
*/
public void setCounts(long runs, long failures, long errors) { public void setCounts(long runs, long failures, long errors) {
this.runs = runs; this.runs = runs;
this.failures = failures; this.failures = failures;
this.errors = errors; this.errors = errors;
} }


/**
* Set the runtime.
* @param runTime the time in milliseconds.
*/
public void setRunTime(long runTime) { public void setRunTime(long runTime) {
this.runTime = runTime; this.runTime = runTime;
} }


/**
* Get the number of runs.
* @return the number of runs.
*/
public long runCount() { public long runCount() {
return runs; return runs;
} }


/**
* Get the number of failures.
* @return the number of failures.
*/
public long failureCount() { public long failureCount() {
return failures; return failures;
} }


/**
* Get the number of errors.
* @return the number of errors.
*/
public long errorCount() { public long errorCount() {
return errors; return errors;
} }


/**
* Get the run time.
* @return the run time in milliseconds.
*/
public long getRunTime() { public long getRunTime() {
return runTime; return runTime;
} }


/**
* Get the properties used in the test.
* @return the properties.
*/
public Properties getProperties() { public Properties getProperties() {
return props; return props;
} }


/**
* Set the properties to be used in the test.
* @param p the properties.
* This is a copy of the projects ant properties.
*/
public void setProperties(Hashtable p) { public void setProperties(Hashtable p) {
props = new Properties(); props = new Properties();
for (Enumeration e = p.keys(); e.hasMoreElements();) { for (Enumeration e = p.keys(); e.hasMoreElements();) {
@@ -135,6 +185,13 @@ public class JUnitTest extends BaseTest implements Cloneable {
} }
} }


/**
* Check if this test should run based on the if and unless
* attributes.
* @param p the project to use to check if the if and unless
* properties exist in.
* @return true if this test or testsuite should be run.
*/
public boolean shouldRun(Project p) { public boolean shouldRun(Project p) {
if (ifProperty != null && p.getProperty(ifProperty) == null) { if (ifProperty != null && p.getProperty(ifProperty) == null) {
return false; return false;
@@ -146,6 +203,10 @@ public class JUnitTest extends BaseTest implements Cloneable {
return true; return true;
} }


/**
* Get the formatters set for this test.
* @return the formatters as an array.
*/
public FormatterElement[] getFormatters() { public FormatterElement[] getFormatters() {
FormatterElement[] fes = new FormatterElement[formatters.size()]; FormatterElement[] fes = new FormatterElement[formatters.size()];
formatters.copyInto(fes); formatters.copyInto(fes);
@@ -164,6 +225,7 @@ public class JUnitTest extends BaseTest implements Cloneable {


/** /**
* @since Ant 1.5 * @since Ant 1.5
* @return a clone of this test.
*/ */
public Object clone() { public Object clone() {
try { try {


+ 18
- 0
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java View File

@@ -549,6 +549,10 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
perm = permissions; perm = permissions;
} }


/**
* Handle a string destined for standard output.
* @param output the string to output
*/
public void handleOutput(String output) { public void handleOutput(String output) {
if (!logTestListenerEvents && output.startsWith(JUnitTask.TESTLISTENER_PREFIX)) { if (!logTestListenerEvents && output.startsWith(JUnitTask.TESTLISTENER_PREFIX)) {
// ignore // ignore
@@ -558,6 +562,12 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
} }


/** /**
* Handle input.
* @param buffer not used.
* @param offset not used.
* @param length not used.
* @return -1 always.
* @throws IOException never.
* @see org.apache.tools.ant.Task#handleInput(byte[], int, int) * @see org.apache.tools.ant.Task#handleInput(byte[], int, int)
* *
* @since Ant 1.6 * @since Ant 1.6
@@ -567,18 +577,21 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
return -1; return -1;
} }


/** {@inheritDoc}. */
public void handleErrorOutput(String output) { public void handleErrorOutput(String output) {
if (systemError != null) { if (systemError != null) {
systemError.print(output); systemError.print(output);
} }
} }


/** {@inheritDoc}. */
public void handleFlush(String output) { public void handleFlush(String output) {
if (systemOut != null) { if (systemOut != null) {
systemOut.print(output); systemOut.print(output);
} }
} }


/** {@inheritDoc}. */
public void handleErrorFlush(String output) { public void handleErrorFlush(String output) {
if (systemError != null) { if (systemError != null) {
systemError.print(output); systemError.print(output);
@@ -609,10 +622,12 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
} }
} }


/** {@inheritDoc}. */
public void addFormatter(JUnitResultFormatter f) { public void addFormatter(JUnitResultFormatter f) {
formatters.addElement(f); formatters.addElement(f);
} }


/** {@inheritDoc}. */
public void addFormatter(JUnitTaskMirror.JUnitResultFormatterMirror f) { public void addFormatter(JUnitTaskMirror.JUnitResultFormatterMirror f) {
formatters.addElement((JUnitResultFormatter) f); formatters.addElement((JUnitResultFormatter) f);
} }
@@ -643,6 +658,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
* System.out.</td><td>false</td></tr> * System.out.</td><td>false</td></tr>
* *
* </table> * </table>
* @param args the command line arguments.
* @throws IOException on error.
*/ */
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
boolean haltError = false; boolean haltError = false;
@@ -840,6 +857,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
/** /**
* Filters stack frames from internal JUnit and Ant classes * Filters stack frames from internal JUnit and Ant classes
* @param stack the stack trace to filter. * @param stack the stack trace to filter.
* @return the filtered stack.
*/ */
public static String filterStack(String stack) { public static String filterStack(String stack) {
if (!filtertrace) { if (!filtertrace) {


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java View File

@@ -176,7 +176,7 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter {
* Interface TestListener. * Interface TestListener.
* *
* <p>A Test is finished. * <p>A Test is finished.
* @param t the test.
* @param test the test.
*/ */
public void endTest(Test test) { public void endTest(Test test) {
if (Boolean.TRUE.equals(failed.get(test))) { if (Boolean.TRUE.equals(failed.get(test))) {


+ 16
- 2
src/main/org/apache/tools/ant/taskdefs/optional/junit/SummaryJUnitResultFormatter.java View File

@@ -31,8 +31,7 @@ import org.apache.tools.ant.BuildException;
*/ */


public class SummaryJUnitResultFormatter public class SummaryJUnitResultFormatter
implements JUnitResultFormatter
,JUnitTaskMirror.SummaryJUnitResultFormatterMirror {
implements JUnitResultFormatter, JUnitTaskMirror.SummaryJUnitResultFormatterMirror {


/** /**
* Formatter for timings. * Formatter for timings.
@@ -54,6 +53,7 @@ public class SummaryJUnitResultFormatter
} }
/** /**
* The testsuite started. * The testsuite started.
* @param suite the testsuite.
*/ */
public void startTestSuite(JUnitTest suite) { public void startTestSuite(JUnitTest suite) {
String newLine = System.getProperty("line.separator"); String newLine = System.getProperty("line.separator");
@@ -70,16 +70,20 @@ public class SummaryJUnitResultFormatter
} }
/** /**
* Empty * Empty
* @param t not used.
*/ */
public void startTest(Test t) { public void startTest(Test t) {
} }
/** /**
* Empty * Empty
* @param test not used.
*/ */
public void endTest(Test test) { public void endTest(Test test) {
} }
/** /**
* Empty * Empty
* @param test not used.
* @param t not used.
*/ */
public void addFailure(Test test, Throwable t) { public void addFailure(Test test, Throwable t) {
} }
@@ -87,24 +91,31 @@ public class SummaryJUnitResultFormatter
* Interface TestListener for JUnit &gt; 3.4. * Interface TestListener for JUnit &gt; 3.4.
* *
* <p>A Test failed. * <p>A Test failed.
* @param test not used.
* @param t not used.
*/ */
public void addFailure(Test test, AssertionFailedError t) { public void addFailure(Test test, AssertionFailedError t) {
addFailure(test, (Throwable) t); addFailure(test, (Throwable) t);
} }
/** /**
* Empty * Empty
* @param test not used.
* @param t not used.
*/ */
public void addError(Test test, Throwable t) { public void addError(Test test, Throwable t) {
} }


/** {@inheritDoc}. */
public void setOutput(OutputStream out) { public void setOutput(OutputStream out) {
this.out = out; this.out = out;
} }


/** {@inheritDoc}. */
public void setSystemOutput(String out) { public void setSystemOutput(String out) {
systemOutput = out; systemOutput = out;
} }


/** {@inheritDoc}. */
public void setSystemError(String err) { public void setSystemError(String err) {
systemError = err; systemError = err;
} }
@@ -112,6 +123,7 @@ public class SummaryJUnitResultFormatter
/** /**
* Should the output to System.out and System.err be written to * Should the output to System.out and System.err be written to
* the summary. * the summary.
* @param value if true write System.out and System.err to the summary.
*/ */
public void setWithOutAndErr(boolean value) { public void setWithOutAndErr(boolean value) {
withOutAndErr = value; withOutAndErr = value;
@@ -119,6 +131,8 @@ public class SummaryJUnitResultFormatter


/** /**
* The whole testsuite ended. * The whole testsuite ended.
* @param suite the testsuite.
* @throws BuildException if there is an error.
*/ */
public void endTestSuite(JUnitTest suite) throws BuildException { public void endTestSuite(JUnitTest suite) throws BuildException {
String newLine = System.getProperty("line.separator"); String newLine = System.getProperty("line.separator");


+ 15
- 0
src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java View File

@@ -86,23 +86,28 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
*/ */
private OutputStream out; private OutputStream out;


/** No arg constructor. */
public XMLJUnitResultFormatter() { public XMLJUnitResultFormatter() {
} }


/** {@inheritDoc}. */
public void setOutput(OutputStream out) { public void setOutput(OutputStream out) {
this.out = out; this.out = out;
} }


/** {@inheritDoc}. */
public void setSystemOutput(String out) { public void setSystemOutput(String out) {
formatOutput(SYSTEM_OUT, out); formatOutput(SYSTEM_OUT, out);
} }


/** {@inheritDoc}. */
public void setSystemError(String out) { public void setSystemError(String out) {
formatOutput(SYSTEM_ERR, out); formatOutput(SYSTEM_ERR, out);
} }


/** /**
* The whole testsuite started. * The whole testsuite started.
* @param suite the testsuite.
*/ */
public void startTestSuite(JUnitTest suite) { public void startTestSuite(JUnitTest suite) {
doc = getDocumentBuilder().newDocument(); doc = getDocumentBuilder().newDocument();
@@ -147,6 +152,8 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan


/** /**
* The whole testsuite ended. * The whole testsuite ended.
* @param suite the testsuite.
* @throws BuildException on error.
*/ */
public void endTestSuite(JUnitTest suite) throws BuildException { public void endTestSuite(JUnitTest suite) throws BuildException {
rootElement.setAttribute(ATTR_TESTS, "" + suite.runCount()); rootElement.setAttribute(ATTR_TESTS, "" + suite.runCount());
@@ -174,6 +181,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
* Interface TestListener. * Interface TestListener.
* *
* <p>A new Test is started. * <p>A new Test is started.
* @param t the test.
*/ */
public void startTest(Test t) { public void startTest(Test t) {
testStarts.put(t, new Long(System.currentTimeMillis())); testStarts.put(t, new Long(System.currentTimeMillis()));
@@ -183,6 +191,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
* Interface TestListener. * Interface TestListener.
* *
* <p>A Test is finished. * <p>A Test is finished.
* @param test the test.
*/ */
public void endTest(Test test) { public void endTest(Test test) {
// Fix for bug #5637 - if a junit.extensions.TestSetup is // Fix for bug #5637 - if a junit.extensions.TestSetup is
@@ -217,6 +226,8 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
* Interface TestListener for JUnit &lt;= 3.4. * Interface TestListener for JUnit &lt;= 3.4.
* *
* <p>A Test failed. * <p>A Test failed.
* @param test the test.
* @param t the exception.
*/ */
public void addFailure(Test test, Throwable t) { public void addFailure(Test test, Throwable t) {
formatError(FAILURE, test, t); formatError(FAILURE, test, t);
@@ -226,6 +237,8 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
* Interface TestListener for JUnit &gt; 3.4. * Interface TestListener for JUnit &gt; 3.4.
* *
* <p>A Test failed. * <p>A Test failed.
* @param test the test.
* @param t the assertion.
*/ */
public void addFailure(Test test, AssertionFailedError t) { public void addFailure(Test test, AssertionFailedError t) {
addFailure(test, (Throwable) t); addFailure(test, (Throwable) t);
@@ -235,6 +248,8 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
* Interface TestListener. * Interface TestListener.
* *
* <p>An error occurred while running the test. * <p>An error occurred while running the test.
* @param test the test.
* @param t the error.
*/ */
public void addError(Test test, Throwable t) { public void addError(Test test, Throwable t) {
formatError(ERROR, test, t); formatError(ERROR, test, t);


Loading…
Cancel
Save