KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hanseltest > TestException


1 package org.hanseltest;
2
3 import junit.framework.TestCase;
4 import junit.framework.TestResult;
5
6 import org.hansel.CoverageDecorator;
7
8 /**
9  * Tests coverage of exception handlers.
10  * @author Niklas Mehner
11  */

12 public class TestException extends TestCase {
13     /** Class to be covered. */
14     private static final Class JavaDoc[] COVERED = {CoverException.class};
15
16     /**
17      * Creates a new test.
18      * @param name Name of the test.
19      */

20     public TestException(String JavaDoc name) {
21         super(name);
22     }
23
24     /**
25      * No code is covered.
26      */

27     public void testNoCoverage() {
28         CoverageDecorator cd = new CoverageDecorator(NoCoverage.class,
29                                                      COVERED);
30
31         TestResult result = new TestResult();
32        
33         cd.run(result);
34         //org.hansel.Util.dumpResult(result);
35
assertEquals(4, result.failureCount());
36         assertEquals(0, result.errorCount());
37     }
38
39     /** Tests only a part of the handlers. */
40     public void testPartCoverage1() {
41         CoverageDecorator cd = new CoverageDecorator(PartCoverage1.class,
42                                                      COVERED);
43
44         TestResult result = new TestResult();
45        
46         cd.run(result);
47    
48         //org.hansel.Util.dumpResult(result);
49
assertEquals(4, result.failureCount());
50         assertEquals(0, result.errorCount());
51     }
52
53     /** Tests only a part of the handlers. */
54     public void testPartCoverage2() {
55         CoverageDecorator cd = new CoverageDecorator(PartCoverage2.class,
56                                                      COVERED);
57
58         TestResult result = new TestResult();
59        
60         cd.run(result);
61     
62         //org.hansel.Util.dumpResult(result);
63
assertEquals(3, result.failureCount());
64         assertEquals(0, result.errorCount());
65     }
66
67     /** Does not cover any code. */
68     public static class NoCoverage extends TestCase {
69         /**
70          * Creates a new test.
71          * @param name Name of the test.
72          */

73         public NoCoverage(String JavaDoc name) {
74             super(name);
75         }
76         
77         /** Empty method. */
78         public void testNothing() {
79         }
80     }
81     
82     /** Only partly covers the code. */
83     public static class PartCoverage1 extends TestCase {
84         /**
85          * Creates a new test.
86          * @param name Name of the test.
87          */

88         public PartCoverage1(String JavaDoc name) {
89             super(name);
90         }
91         
92         /** Tests a part of the CoverException class. */
93         public void testPart() {
94             assertEquals(0, new CoverException().coverFinally(3, false));
95         }
96     }
97     
98     /** Only partly covers the code. */
99     public static class PartCoverage2 extends TestCase {
100         /**
101          * Creates a new test.
102          * @param name Name of the test.
103          */

104         public PartCoverage2(String JavaDoc name) {
105             super(name);
106         }
107         
108         /** Tests a part of the CoverException class. */
109         public void testPart() {
110             assertEquals(1, new CoverException().coverHandler(3));
111         }
112     }
113
114  
115 }
116
Popular Tags