KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > ejtools > management > test > Log4jFormatter


1 package net.sourceforge.ejtools.management.test;
2
3 import junit.framework.AssertionFailedError;
4 import junit.framework.Test;
5
6 import org.apache.log4j.Category;
7
8 /**
9  * @author laurent
10  *
11  * To change this generated comment edit the template variable "typecomment":
12  * Window>Preferences>Java>Templates.
13  * To enable and disable the creation of type comments go to
14  * Window>Preferences>Java>Code Generation.
15  */

16 public class Log4jFormatter implements Formatter
17 {
18     protected int[] counters = new int[4];
19    /** Description of the Field */
20    private static Category logger = Category.getInstance(Log4jFormatter.class);
21
22     /**
23      * Constructor for Log4jFormatter.
24      */

25     public Log4jFormatter()
26     {
27         super();
28     }
29
30     /**
31      * @see net.sourceforge.ejtools.management.test.Formatter#setName(String)
32      */

33     public void setName(String JavaDoc name)
34     {
35     }
36
37     /**
38      * @see net.sourceforge.ejtools.management.test.Formatter#addProperty(String, Object)
39      */

40     public void addProperty(String JavaDoc key, Object JavaDoc value)
41     {
42     }
43
44     /**
45      * @see net.sourceforge.ejtools.management.test.Formatter#addResult(String, int)
46      */

47     public void addResult(String JavaDoc message, int status)
48     {
49     }
50
51     /**
52      * @see net.sourceforge.ejtools.management.test.Formatter#getPercentage()
53      */

54     public long getPercentage()
55     {
56         return 0;
57     }
58
59     /**
60      * @see junit.extensions.jfunc.AssertListener#addAssert(Test, String, boolean)
61      */

62     public void addAssert(Test arg0, String JavaDoc arg1, boolean arg2)
63     {
64         logger.debug("[ ASSERT] (" + arg0 + ") " + arg1 + " = " + arg2);
65         if (arg2) {
66             counters[Formatter.PASSED]++;
67         }
68     }
69
70     /**
71      * @see junit.framework.TestListener#addError(Test, Throwable)
72      */

73     public void addError(Test arg0, Throwable JavaDoc arg1)
74     {
75         logger.debug("[ ERROR ] (" + arg0 + ") " + arg1.getMessage());
76             counters[Formatter.ERROR]++;
77     }
78
79     /**
80      * @see junit.framework.TestListener#addFailure(Test, AssertionFailedError)
81      */

82     public void addFailure(Test arg0, AssertionFailedError arg1)
83     {
84         logger.debug("[FAILURE] (" + arg0 + ") " + arg1.getMessage());
85             counters[Formatter.FAILED]++;
86     }
87
88     /**
89      * @see junit.framework.TestListener#endTest(Test)
90      */

91     public void endTest(Test arg0)
92     {
93         long total = counters[Formatter.ERROR] + counters[Formatter.FAILED] + counters[Formatter.PASSED];
94         logger.info("Total : " + total);
95         logger.info("Passed : " + counters[Formatter.PASSED] + "/" + total);
96         logger.info("Failed : " + counters[Formatter.FAILED] + "/" + total);
97         logger.info("Errors : " + counters[Formatter.ERROR] + "/" + total);
98         logger.debug("Test is ending " + arg0);
99     }
100
101     /**
102      * @see junit.framework.TestListener#startTest(Test)
103      */

104     public void startTest(Test arg0)
105     {
106         logger.debug("Test is starting " + arg0);
107     }
108 }
109
Popular Tags