carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/TextListener.java
changeset 636 3ef299ba838f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/TextListener.java	Fri Dec 04 11:49:54 2009 -0600
@@ -0,0 +1,98 @@
+package org.junit.internal;
+
+import java.io.PrintStream;
+import java.text.NumberFormat;
+import java.util.List;
+
+import org.junit.runner.Description;
+import org.junit.runner.Result;
+import org.junit.runner.notification.Failure;
+import org.junit.runner.notification.RunListener;
+
+public class TextListener extends RunListener {
+
+	private final PrintStream fWriter;
+
+	public TextListener(JUnitSystem system) {
+		this(system.out());
+	}
+
+	public TextListener(PrintStream writer) {
+		this.fWriter= writer;
+	}
+
+	@Override
+	public void testRunFinished(Result result) {
+		printHeader(result.getRunTime());
+		printFailures(result);
+		printFooter(result);
+	}
+
+	@Override
+	public void testStarted(Description description) {
+		fWriter.append('.');
+	}
+
+	@Override
+	public void testFailure(Failure failure) {
+		fWriter.append('E');
+	}
+
+	@Override
+	public void testIgnored(Description description) {
+		fWriter.append('I');
+	}
+
+	/*
+	 * Internal methods
+	 */
+
+	private PrintStream getWriter() {
+		return fWriter;
+	}
+
+	protected void printHeader(long runTime) {
+		getWriter().println();
+		getWriter().println("Time: " + elapsedTimeAsString(runTime));
+	}
+
+	protected void printFailures(Result result) {
+		List<Failure> failures= result.getFailures();
+		if (failures.size() == 0)
+			return;
+		if (failures.size() == 1)
+			getWriter().println("There was " + failures.size() + " failure:");
+		else
+			getWriter().println("There were " + failures.size() + " failures:");
+		int i= 1;
+		for (Failure each : failures)
+			printFailure(each, "" + i++);
+	}
+
+	protected void printFailure(Failure each, String prefix) {
+		getWriter().println(prefix + ") " + each.getTestHeader());
+		getWriter().print(each.getTrace());
+	}
+
+	protected void printFooter(Result result) {
+		if (result.wasSuccessful()) {
+			getWriter().println();
+			getWriter().print("OK");
+			getWriter().println(" (" + result.getRunCount() + " test" + (result.getRunCount() == 1 ? "" : "s") + ")");
+
+		} else {
+			getWriter().println();
+			getWriter().println("FAILURES!!!");
+			getWriter().println("Tests run: " + result.getRunCount() + ",  Failures: " + result.getFailureCount());
+		}
+		getWriter().println();
+	}
+
+	/**
+	 * Returns the formatted string of the elapsed time. Duplicated from
+	 * BaseTestRunner. Fix it.
+	 */
+	protected String elapsedTimeAsString(long runTime) {
+		return NumberFormat.getInstance().format((double) runTime / 1000);
+	}
+}