KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > test > TCJUnitFormatter


1 /**
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.test;
5
6 import org.apache.tools.ant.BuildException;
7 import org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter;
8 import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest;
9
10 import java.io.OutputStream JavaDoc;
11 import java.io.PrintWriter JavaDoc;
12 import java.io.StringWriter JavaDoc;
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import junit.framework.AssertionFailedError;
18 import junit.framework.Test;
19
20 /**
21  * @author andrew A
22  */

23 public class TCJUnitFormatter implements JUnitResultFormatter {
24
25   private final List JavaDoc currentExceptions;
26   private static class TestException {
27     private final Test theTest;
28     private final Throwable JavaDoc exception;
29
30     public TestException(Test theTest, Throwable JavaDoc exception) {
31       this.theTest = theTest;
32       this.exception = exception;
33     }
34
35     public String JavaDoc toString() {
36       StringWriter JavaDoc sw = new StringWriter JavaDoc();
37       PrintWriter JavaDoc pw = new PrintWriter JavaDoc(sw);
38
39       pw.println(this.theTest + " FAILED:");
40       this.exception.printStackTrace(pw);
41
42       pw.flush();
43       return sw.toString();
44     }
45   }
46
47   public TCJUnitFormatter() {
48     this.currentExceptions = new ArrayList JavaDoc();
49   }
50
51   public void endTestSuite(JUnitTest theTest) throws BuildException {
52     boolean passed = (theTest.errorCount() == 0 && theTest.failureCount() == 0);
53
54     if (!passed) {
55       System.err.println("*** " + theTest.getName() + " FAILED: " + this.currentExceptions.size() + " exceptions:");
56       Iterator JavaDoc iter = this.currentExceptions.iterator();
57       while (iter.hasNext()) {
58         System.err.println(iter.next().toString());
59         System.err.println("");
60       }
61     }
62
63     this.currentExceptions.clear();
64   }
65
66   public void setOutput(OutputStream JavaDoc theStream) {
67     //
68
}
69
70   public void setSystemError(String JavaDoc arg0) {
71     //
72
}
73
74   public void setSystemOutput(String JavaDoc arg0) {
75     //
76
}
77
78   public void startTestSuite(JUnitTest theTest) throws BuildException {
79     System.err.println(theTest.getName() + "...");
80     System.err.flush();
81   }
82
83   public void addError(Test arg0, Throwable JavaDoc arg1) {
84     this.currentExceptions.add(new TestException(arg0, arg1));
85   }
86
87   public void addFailure(Test arg0, AssertionFailedError arg1) {
88     this.currentExceptions.add(new TestException(arg0, arg1));
89   }
90
91   public void endTest(Test arg0) {
92     //
93
}
94
95   public void startTest(Test arg0) {
96     //
97
}
98 }
99
Popular Tags