KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quilt > runner > Runner


1 /* Runner.java */
2
3 package org.quilt.runner;
4
5 import java.io.BufferedReader JavaDoc;
6 import java.io.PrintWriter JavaDoc;
7 import java.io.StringReader JavaDoc;
8 import java.io.StringWriter JavaDoc;
9
10 import junit.framework.*;
11 import org.apache.tools.ant.util.StringUtils;
12
13 import org.quilt.framework.QuiltTest;
14 import org.quilt.reports.Formatter;
15
16 /**
17  * Abstract class extended by Quilt test runners.
18  */

19 public abstract class Runner extends QuiltTest
20                                     implements RunnerConst, TestListener {
21
22     public abstract void run (); // constructor provides QuiltTest instance
23
public abstract int getRetCode();
24
25     // STATIC METHODS ///////////////////////////////////////////////
26
public static String JavaDoc getFilteredTrace(Throwable JavaDoc t, boolean filtertrace) {
27         String JavaDoc trace = StringUtils.getStackTrace(t);
28         return filterStack(trace, filtertrace);
29     }
30
31     /////////////////////////////////////////////////////////////////
32
// FOCUS -- LOOK AT THIS CAREFULLY
33
/////////////////////////////////////////////////////////////////
34

35     /**
36      * Filters stack traces from Ant, Quilt, and JUnit classes. These
37      * are usually meaningless to users, who wants to concentrate on
38      * their own code.
39      */

40     public static String JavaDoc filterStack(String JavaDoc stack, boolean filtertrace) {
41         if ( ! filtertrace ) {
42             return stack;
43         }
44         StringWriter JavaDoc sw = new StringWriter JavaDoc();
45         PrintWriter JavaDoc pw = new PrintWriter JavaDoc(sw);
46         StringReader JavaDoc sr = new StringReader JavaDoc(stack);
47         BufferedReader JavaDoc br = new BufferedReader JavaDoc(sr);
48
49         String JavaDoc line;
50         try {
51             while ((line = br.readLine()) != null) {
52                 if (!filterLine(line)) {
53                     pw.println(line);
54                 }
55             }
56         } catch (Exception JavaDoc IOException) {
57             return stack; // return the stack unfiltered
58
}
59         return sw.toString();
60     }
61
62     private static boolean filterLine(String JavaDoc line) {
63         for (int i = 0; i < DEFAULT_TRACE_FILTERS.length; i++) {
64             if (line.indexOf(DEFAULT_TRACE_FILTERS[i]) > 0) {
65                 return true;
66             }
67         }
68         return false;
69     }
70     // NON-STATIC METHODS ///////////////////////////////////////////
71
/** Add a result formatter. */
72     public abstract void addFormatter(Formatter f);
73     // TestListener INTERFACE ///////////////////////////////////////
74
/** A failure (or error) has occurred. */
75     public abstract void addFailure(Test test, Throwable JavaDoc t);
76     /** A failure (or error) has occurred. */
77     public abstract void addFailure(Test test, AssertionFailedError t);
78     /** An unexpected error has occurred. */
79     public abstract void addError(Test test, Throwable JavaDoc t);
80     /** Method called at start of individual test suite. */
81     public abstract void startTest(Test t);
82     /** Method called at end of individual test run. */
83     public abstract void endTest(Test test);
84     /** Process a block of output. */
85     public abstract void handleOutput(String JavaDoc line);
86     /** Process an error message */
87     public abstract void handleErrorOutput(String JavaDoc line);
88     /** Flush standard output. */
89     public abstract void handleFlush(String JavaDoc line);
90     /** Flush the error output stream. */
91     public abstract void handleErrorFlush(String JavaDoc line);
92 }
93
Popular Tags