001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.debug.jdi.tests;
011:
012: import java.util.Enumeration;
013:
014: import junit.framework.AssertionFailedError;
015: import junit.framework.Test;
016: import junit.framework.TestFailure;
017: import junit.framework.TestResult;
018:
019: /**
020: * Tests a <code>TestResult</code>
021: */
022: class TextTestResult extends TestResult {
023:
024: /**
025: * @see junit.framework.TestResult#addError(junit.framework.Test, java.lang.Throwable)
026: */
027: public synchronized void addError(Test test, Throwable t) {
028: super .addError(test, t);
029: System.out.println("E");
030: }
031:
032: /**
033: * @see junit.framework.TestResult#addFailure(junit.framework.Test, junit.framework.AssertionFailedError)
034: */
035: public synchronized void addFailure(Test test,
036: AssertionFailedError t) {
037: super .addFailure(test, t);
038: System.out.print("F");
039: }
040:
041: /**
042: * Prints failures to the standard output
043: */
044: public synchronized void print() {
045: printHeader();
046: printErrors();
047: printFailures();
048: }
049:
050: /**
051: * Prints the errors to the standard output
052: */
053: public void printErrors() {
054: if (errorCount() != 0) {
055: if (errorCount() == 1)
056: System.out.println("There was " + errorCount()
057: + " error:");
058: else
059: System.out.println("There were " + errorCount()
060: + " errors:");
061:
062: int i = 1;
063: for (Enumeration e = errors(); e.hasMoreElements(); i++) {
064: TestFailure failure = (TestFailure) e.nextElement();
065: System.out.println(i + ") " + failure.failedTest());
066: failure.thrownException().printStackTrace();
067: System.out.println();
068: }
069: }
070: }
071:
072: /**
073: * Prints failures to the standard output
074: */
075: public void printFailures() {
076: if (failureCount() != 0) {
077: if (failureCount() == 1)
078: System.out.println("There was " + failureCount()
079: + " failure:");
080: else
081: System.out.println("There were " + failureCount()
082: + " failures:");
083:
084: int i = 1;
085: for (Enumeration e = failures(); e.hasMoreElements(); i++) {
086: TestFailure failure = (TestFailure) e.nextElement();
087: System.out.print(i + ") " + failure.failedTest());
088: Throwable t = failure.thrownException();
089: if (t.getMessage() != null)
090: System.out.println(" \"" + t.getMessage() + "\"");
091: else {
092: System.out.println();
093: failure.thrownException().printStackTrace();
094: }
095: }
096: }
097: }
098:
099: /**
100: * Prints the header of the report
101: */
102: public void printHeader() {
103: if (wasSuccessful()) {
104: System.out.println();
105: System.out.print("OK");
106: System.out.println(" (" + runCount() + " tests)");
107:
108: } else {
109: System.out.println();
110: System.out.println("!!!FAILURES!!!");
111: System.out.println("Test Results:");
112: System.out.println("Run: " + runCount() + " Failures: "
113: + failureCount() + " Errors: " + errorCount());
114: }
115: }
116:
117: /**
118: * @see junit.framework.TestResult#startTest(junit.framework.Test)
119: */
120: public synchronized void startTest(Test test) {
121: super .startTest(test);
122: System.out.print(".");
123: }
124: }
|