1   /* SummaryFormatter.java */
2   
3   // //////////////////////////////////////////////////////////////////
4   // MODIFY TO EXTEND BaseFormatter ? /////////////////////////////////
5   // //////////////////////////////////////////////////////////////////
6   
7   package org.quilt.reports;
8   
9   import java.text.NumberFormat;
10  import java.io.IOException;
11  import java.io.OutputStream;
12  
13  import junit.framework.AssertionFailedError;
14  import junit.framework.Test;
15  
16  import org.apache.tools.ant.BuildException;
17  
18  import org.quilt.framework.*;
19  import org.quilt.runner.Runner;
20  
21  public class SummaryFormatter implements Formatter {
22  
23      private boolean filtertrace = false;
24      private Runner runner = null;
25  
26      private NumberFormat nf = NumberFormat.getInstance();
27      private OutputStream out;
28  
29      private boolean withOutAndErr = false;
30      private String systemOutput = null;
31      private String systemError = null;
32  
33      public SummaryFormatter() {}
34  
35      // FORMATTER INTERFACE //////////////////////////////////////////
36  
37      /*** Called at the end of the Ant/Quilt test run. */
38      public void endTestSuite(QuiltTest qt) throws BuildException {
39          StringBuffer sb = new StringBuffer("Tests run: " + qt.runCount()
40              + ", Failures: "    + qt.failureCount()
41              + ", Errors: "      + qt.errorCount()
42              + ", Time elapsed: "+ nf.format(qt.getRunTime() / 1000.0)
43              + " sec\n" );
44  
45          if (withOutAndErr) {
46              if (systemOutput != null && systemOutput.length() > 0) {
47                  sb.append("Output:\n" + systemOutput + "\n");
48              }
49              if (systemError != null && systemError.length() > 0) {
50                  sb.append("Error:\n " + systemError + "\n");
51              }
52          }
53  
54          try {
55              out.write(sb.toString().getBytes());
56              out.flush();
57          } catch (IOException e) {
58              throw new BuildException("Unable to write summary output", e);
59          } finally {
60              if (out != System.out && out != System.err) {
61                  try {
62                      out.close();
63                  } catch (IOException e) {}
64              }
65          } 
66      } 
67      /*** Enable filtering of Ant/Quilt/JUnit lines from stack traces. */
68      public void setFiltertrace(boolean b) {
69          filtertrace = b;            // NEVER USED 
70      }
71      /*** Where to direct output. */
72      public void setOutput(OutputStream out) {
73          this.out = out;
74      }
75      /*** Select the runner to be used. */
76      public void setRunner(Runner testrunner) {
77          runner = testrunner;
78      }
79      /*** Where to send system error output. */
80      public void setSystemError(String err) {
81          systemError = err;
82      }
83      /*** Where to send standard output. */
84      public void setSystemOutput(String out) {
85          systemOutput = out;
86      }
87      /*** Called at start of Ant/Quilt test run. */
88      public void startTestSuite(QuiltTest suite) {}
89  
90      // INTERFACE TESTLISTENER ///////////////////////////////////////
91      /*** An unexpected error occurred. */
92      public void addError(Test test, Throwable t) {}
93      /*** A failure occurred. */
94      public void addFailure(Test test, Throwable t) {}
95      /*** A failure occurred. */
96      public void addFailure(Test test, AssertionFailedError t) {
97          addFailure(test, (Throwable) t);
98      }
99      /*** Called at end of JUnit test. */
100     public void endTest(Test test) {}
101     /*** Called at beginning of JUnit test. */
102     public void startTest(Test t) {}
103    
104     // OTHER METHODS ////////////////////////////////////////////////
105     /***
106      * Ant-compatible method determining whether System.out and 
107      * System.err should be echoed to the summary report. 
108      */
109     public void setWithOutAndErr(boolean value) {
110         withOutAndErr = value;
111     }
112 }
This page was automatically generated by Maven