View Javadoc

1   package junitour;
2   
3   import junit.textui.ResultPrinter;
4   import junit.framework.TestResult;
5   import junit.framework.Test;
6   import java.io.PrintStream;
7   
8   /**
9    * extension to ResultPrinter, just to
10   *
11   * <br/>created: by hostlows, at 08.10.2003/ 18:46:11
12   * <pre>
13   * $Log$
14   * Revision 1.7  2005/08/21 21:26:55  hostlows
15   * added Java5 Annotations, more java-doc
16   *
17   * Revision 1.6  2005/07/31 03:01:13  hostlows
18   * just small typos an introducing a local variable
19   *
20   * Revision 1.5  2004/12/04 21:59:17  hostlows
21   * removed unused imports
22   *
23   * Revision 1.4  2004/07/08 01:47:50  hostlows
24   * cleanup, new build, license changed to mozilla license...
25   *
26   * Revision 1.3  2003/11/25 00:23:09  hostlows
27   * small javadoc fix
28   *
29   * Revision 1.2  2003/11/13 02:44:50  hostlows
30   * overloaded addFailure to check, if it is an Incomplete TestCase
31   *
32   * Revision 1.1.1.1  2003/11/12 23:32:13  hostlows
33   * Initial import.
34   *
35   * Revision 1.1  2003/10/30 07:13:54  hostlows
36   * First release, which can run as a TextUI-Testrunner and
37   * produces an enhanced output: additionally prints the count of
38   * incomplete Tests! It handles examination of incomplete Testcase over
39   * different classloaders now!
40   *
41   * </pre>
42   * @author $Author: hostlows $, created by  <a href="mailto:hostlows@users.sf.net">Robert Hostlowsky</a>
43   * @version $Revision: 62 $
44   */
45  public class MyResultPrinter extends ResultPrinter {
46  
47  	public MyResultPrinter(PrintStream writer) {
48  		super(writer);
49  	}
50  
51  	protected void printFooter(TourTestResult result) {
52  
53  		//Hack: added this call before normal printFooter method
54  		printIncompletes(result);
55  
56          final PrintStream writer = getWriter();
57          if (result.allCompletlyImplemented()) {
58  			//green or red, old fashioned way: no incomplete tests
59  			super.printFooter(result);
60  		}
61  		else if (result.wasSuccessful()) {
62  			//yellow: no errors/failures, but incomplete tests
63  			writer.println();
64  			writer.println("OK, But incomplete test cases!!!");
65  			writer.println("Tests run: " + result.runCount() +
66                            ",  Incomplete test cases: " + result.notImplementedCount());
67  			writer.println();
68  		}
69  		else {
70  			//red: errors/failures, incomplete tests
71  			writer.println();
72  			writer.println("FAILURES!!!");
73  			writer.println("Tests run: " + result.runCount() +
74  			                    ",  Failures: " + result.failureCount() +
75  			                    ",  Errors: " + result.errorCount() +
76  			                    ",  Incomplete Tests: " + result.notImplementedCount());
77  			writer.println();
78  		}
79  	}
80  
81  	private void printIncompletes(TourTestResult result) {
82  		printDefects(result.incompletesEnum(), result.notImplementedCount(), "incomplete testcases");
83  	}
84  
85      @Override
86  	protected void printFooter(TestResult result) {
87  		if( result instanceof TourTestResult )
88  			printFooter((TourTestResult) result);
89  		else
90  			super.printFooter(result);
91  	}
92  
93  	/** added switch: checks type of given throwable: if it's an IncompleteError then
94  	 * adds test to the notimplemented tests, else calls super-method for normal handling.
95  	 * @see junit.framework.TestListener#addError(junit.framework.Test, Throwable)
96       * @see junit.textui.ResultPrinter#addError(junit.framework.Test, java.lang.Throwable)
97       */
98      @Override
99  	public void addError(Test test, Throwable t) {
100 		if (UnitTestIncompleteError.isTestIncompleteError(t))
101 			addNotImplemented(test, t);
102 		else
103 			super.addError(test, t);
104     }
105 
106 	/** added switch: checks type of given throwable: if it's an IncompleteError then
107 	 * adds test to the notimplemented tests, else calls super-method for normal handling.
108 	 * @see junit.framework.TestListener#addFailure(junit.framework.Test, junit.framework.AssertionFailedError)
109      */
110     @Override
111 	public void addFailure(Test test, junit.framework.AssertionFailedError t) {
112 		if (UnitTestIncompleteError.isTestIncompleteError(t))
113 			addNotImplemented(test, t);
114 		else
115 			super.addFailure(test, t);
116 	}
117 
118     /**
119 	 * logs an incomplete test by printing 'I'.
120 	 * @param test unused
121 	 * @param t unused
122 	 */
123 	public void addNotImplemented(Test test, Throwable t) {
124 		getWriter().print("I");
125 	}
126 
127 }