1 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 ; 11 import java.io.PrintWriter ; 12 import java.io.StringWriter ; 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import junit.framework.AssertionFailedError; 18 import junit.framework.Test; 19 20 23 public class TCJUnitFormatter implements JUnitResultFormatter { 24 25 private final List currentExceptions; 26 private static class TestException { 27 private final Test theTest; 28 private final Throwable exception; 29 30 public TestException(Test theTest, Throwable exception) { 31 this.theTest = theTest; 32 this.exception = exception; 33 } 34 35 public String toString() { 36 StringWriter sw = new StringWriter (); 37 PrintWriter pw = new PrintWriter (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 (); 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 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 theStream) { 67 } 69 70 public void setSystemError(String arg0) { 71 } 73 74 public void setSystemOutput(String arg0) { 75 } 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 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 } 94 95 public void startTest(Test arg0) { 96 } 98 } 99 | Popular Tags |