KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hanseltest > TestProbeFilter


1 package org.hanseltest;
2
3 import junit.framework.TestCase;
4 import junit.framework.TestResult;
5
6 import org.hansel.CoverageDecorator;
7 import org.hansel.probes.StringProbeFilter;
8
9 /**
10  * Test the probe filter interface..
11  *
12  * @author Niklas Mehner
13  */

14 public class TestProbeFilter extends TestCase {
15     /** Class that should be covered by the tests. */
16     private static final Class JavaDoc[] COVERED = {CoverProbeFilter.class};
17
18     /**
19      * No code is covered.
20      */

21     public void testNoFilter() {
22         CoverageDecorator cd = new CoverageDecorator(Coverage.class,
23                                                      COVERED);
24
25         TestResult result = new TestResult();
26
27         cd.run(result);
28
29         // 1 Failure
30
assertEquals(1, result.failureCount());
31
32         // No errors
33
assertEquals(0, result.errorCount());
34     }
35
36     /**
37      * Validate that a test covering all of the code, does not cause
38      * any coverage failures or errors.
39      */

40     public void testFilter() {
41         CoverageDecorator cd = new CoverageDecorator(Coverage.class,
42                                                      COVERED,
43                                                      new StringProbeFilter("filterThis()"));
44
45         TestResult result = new TestResult();
46
47         cd.run(result);
48
49         assertEquals(0, result.failureCount());
50
51         // No errors
52
assertEquals(0, result.errorCount());
53     }
54
55
56     /** Does not cover any code. */
57     public static class Coverage extends TestCase {
58         /**
59          * Tests nothing.
60          */

61         public void testClass() {
62             new CoverProbeFilter();
63         }
64     }
65
66 }
67
Popular Tags