Author: julien(a)jboss.com
Date: 2007-10-11 09:38:02 -0400 (Thu, 11 Oct 2007)
New Revision: 8601
Added:
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/writer/
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/writer/PrintListener.java
Removed:
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/console/
Modified:
modules/test/trunk/unit/build.xml
modules/test/trunk/unit/src/main/org/jboss/test/unit/blah/BlahTestTwo.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/blah/BlahTests.java
modules/test/trunk/unit/src/main/org/jboss/unit/tooling/report/DelegatingReporter.java
Log:
change the package name of the PrintListener reporter and also make it configurable to use
any stream
Modified: modules/test/trunk/unit/build.xml
===================================================================
--- modules/test/trunk/unit/build.xml 2007-10-11 09:56:02 UTC (rev 8600)
+++ modules/test/trunk/unit/build.xml 2007-10-11 13:38:02 UTC (rev 8601)
@@ -186,9 +186,9 @@
<target name="test" depends="output">
<java classname="org.jboss.test.unit.AllTests"
fork="true">
-<!--
<jvmarg value="-Xdebug"/>
<jvmarg
value="-Xrunjdwp:transport=dt_socket,address=7878,server=y,suspend=y"/>
+<!--
-->
<classpath>
<path location="${build.lib}/jboss-unit-lib.jar"/>
Modified: modules/test/trunk/unit/src/main/org/jboss/test/unit/blah/BlahTestTwo.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/blah/BlahTestTwo.java 2007-10-11
09:56:02 UTC (rev 8600)
+++ modules/test/trunk/unit/src/main/org/jboss/test/unit/blah/BlahTestTwo.java 2007-10-11
13:38:02 UTC (rev 8601)
@@ -24,8 +24,8 @@
import java.io.InputStream;
-import org.jboss.unit.report.impl.console.PrintListener;
import org.jboss.unit.report.impl.junit.JUnitReporter;
+import org.jboss.unit.report.impl.writer.PrintListener;
import org.jboss.unit.runner.TestRunner;
import org.jboss.unit.runner.TestRunnerEventListener;
import org.jboss.unit.runner.model.ModelBuilder;
Modified: modules/test/trunk/unit/src/main/org/jboss/test/unit/blah/BlahTests.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/test/unit/blah/BlahTests.java 2007-10-11
09:56:02 UTC (rev 8600)
+++ modules/test/trunk/unit/src/main/org/jboss/test/unit/blah/BlahTests.java 2007-10-11
13:38:02 UTC (rev 8601)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.jboss.test.unit.blah;
-import org.jboss.unit.report.impl.console.PrintListener;
+import org.jboss.unit.report.impl.writer.PrintListener;
import org.jboss.unit.runner.TestRunner;
import org.jboss.unit.runner.model.ModelBuilder;
import org.jboss.unit.runner.model.TestSuiteDef;
Added:
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/writer/PrintListener.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/writer/PrintListener.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/writer/PrintListener.java 2007-10-11
13:38:02 UTC (rev 8601)
@@ -0,0 +1,142 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.unit.report.impl.writer;
+
+import org.jboss.unit.Failure;
+import org.jboss.unit.TestId;
+import org.jboss.unit.runner.TestResult;
+import org.jboss.unit.runner.TestRunnerEvent;
+import org.jboss.unit.runner.TestRunnerEventListener;
+import org.jboss.unit.runner.event.EndRunnerEvent;
+import org.jboss.unit.runner.event.EndTestEvent;
+import org.jboss.unit.runner.event.RunnerFailureEvent;
+import org.jboss.unit.runner.event.StartRunnerEvent;
+import org.jboss.unit.runner.event.StartTestEvent;
+import org.jboss.unit.runner.results.TestFailure;
+import org.jboss.unit.runner.results.TestSuccess;
+
+import java.io.PrintStream;
+import java.io.Writer;
+import java.io.PrintWriter;
+import java.io.OutputStream;
+
+/**
+ * A listener which output messages on a specified stream.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PrintListener implements TestRunnerEventListener
+{
+
+ /** . */
+ private final PrintWriter out;
+
+ /**
+ * Builds with the <code>System.out</code> print stream.
+ */
+ public PrintListener()
+ {
+ this(System.out);
+ }
+
+ /**
+ * Use a writer, if the writer is an instance of <code>PrintWriter</code>
then this object
+ * will be reused as is.
+ *
+ * @param writer the writer
+ */
+ public PrintListener(Writer writer) throws IllegalArgumentException
+ {
+ if (writer == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (writer instanceof PrintWriter)
+ {
+ this.out = (PrintWriter)writer;
+ }
+ else
+ {
+ this.out = new PrintWriter(writer, true);
+ }
+ }
+
+ /**
+ * Uses a provided output stream.
+ *
+ * @param stream the stream
+ */
+ public PrintListener(OutputStream stream) throws IllegalArgumentException
+ {
+ if (stream == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ this.out = new PrintWriter(stream, true);
+ }
+
+ public void onEvent(TestRunnerEvent event)
+ {
+ if (event instanceof StartRunnerEvent)
+ {
+ out.println("--- Start ---");
+ }
+ else if (event instanceof EndRunnerEvent)
+ {
+ out.println("--- End ---");
+ }
+ else if (event instanceof RunnerFailureEvent)
+ {
+ RunnerFailureEvent failureEvent = (RunnerFailureEvent)event;
+ Failure failure = failureEvent.getFailure();
+ out.println("Runner failure: " + failure.getType() + " " +
failure.getMessage());
+ failure.getCause().printStackTrace(out);
+ }
+ else if (event instanceof StartTestEvent)
+ {
+ StartTestEvent startTestEvent = (StartTestEvent)event;
+ out.println("Starting id=" + startTestEvent.getTestId() + "
name=" + startTestEvent.getTestInfo().getName() + " description=" +
startTestEvent.getTestInfo().getDescription());
+ }
+ else if (event instanceof EndTestEvent)
+ {
+ EndTestEvent endTestEvent = (EndTestEvent)event;
+ TestId testId = endTestEvent.getTestId();
+ TestResult testResult = endTestEvent.getTestResult();
+ if (testResult instanceof TestSuccess)
+ {
+ out.println("Test id=" + testId + " is successful (" +
testResult.getDurationMillis() + "ms)");
+ }
+ else if (testResult instanceof TestFailure)
+ {
+ TestFailure testFailure = (TestFailure)testResult;
+ Failure failure = testFailure.getFailure();
+ out.println("Test id=" + testId + " " + failure.getType()
+ " failed " + failure.getMessage() + " (" +
testResult.getDurationMillis() + "ms)");
+ if (failure.getCause() != null)
+ {
+ failure.getCause().printStackTrace(out);
+ }
+ }
+ }
+ }
+}
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/tooling/report/DelegatingReporter.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/tooling/report/DelegatingReporter.java 2007-10-11
09:56:02 UTC (rev 8600)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/tooling/report/DelegatingReporter.java 2007-10-11
13:38:02 UTC (rev 8601)
@@ -24,7 +24,7 @@
import org.jboss.unit.runner.TestRunnerEventListener;
import org.jboss.unit.runner.TestRunnerEvent;
-import org.jboss.unit.report.impl.console.PrintListener;
+import org.jboss.unit.report.impl.writer.PrintListener;
/**
* @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
com">Boleslaw Dawidowicz</a>