KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hanseltest > TestClassLiteral


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.Util;
8
9 /**
10  * Test class literals. This requires a seperate test, because javac generates
11  * a synthetic method to get the class reference.
12  * @author Niklas Mehner
13  */

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

22     public TestClassLiteral(String JavaDoc name) {
23         super(name);
24     }
25
26     /**
27      * Test full coverage.
28      */

29     public void testFullCoverage() {
30         CoverageDecorator cd =
31                  new CoverageDecorator(FullCoverage.class,
32                                        COVERED);
33
34         TestResult result = new TestResult();
35         cd.run(result);
36         
37         Util.dumpResult(result);
38         // No failures
39
assertEquals(0, result.failureCount());
40
41         // No errors
42
assertEquals(0, result.errorCount());
43     }
44
45     /** Fully cover the class. */
46     public static class FullCoverage extends TestCase {
47         /**
48          * Creates a new test.
49          * @param name Name of the test.
50          */

51         public FullCoverage(String JavaDoc name) {
52             super(name);
53         }
54         
55         /** Fully cover the class. */
56         public void testAll() {
57             CoverClassLiteral ccl = new CoverClassLiteral();
58             assertEquals("org.hanseltest.CoverClassLiteral",
59                          ccl.getClassName());
60         }
61     }
62
63 }
64
Popular Tags