01: package org.hanselexample;
02:
03: import junit.framework.Test;
04: import junit.framework.TestCase;
05:
06: import org.hansel.CoverageDecorator;
07:
08: /**
09: * Coverage Test for the Example class.
10: * This test covers all lines (including private/anonymous classes)
11: * of the Example class.
12: *
13: * @author Niklas Mehner
14: */
15: public class ExampleTest extends TestCase {
16:
17: /**
18: * Creates a new Test.
19: * @param name Name of the test.
20: */
21: public ExampleTest(String name) {
22: super (name);
23: }
24:
25: /**
26: * Static method to create the TestSuit.
27: * This wrapps the test in a CoverageDecorator.
28: * @return TestSuit for this class.
29: */
30: public static Test suite() {
31: CoverageDecorator cd = new CoverageDecorator(
32: ExampleJUnit4Test.class, new Class[] { Example.class });
33:
34: cd.setDisplayStatistics(true);
35: return cd;
36: }
37:
38: /**
39: * Test the Example.abs() method.
40: */
41: public void testAbs() {
42: Example example = new Example();
43:
44: assertEquals("abs(1) should be 1.", 1, example.abs(1));
45: assertEquals("abs(-1) should be 1.", 1, example.abs(-1));
46: assertEquals("abs(0) should be 0.", 0, example.abs(0));
47: }
48:
49: /**
50: * Test the Example.add() method. This also covers the code of the inner
51: * class.
52: */
53: public void testInnerClass() {
54: Example example = new Example();
55: assertEquals("add(2, 3) should be 5.", 5, example.add(2, 3));
56: }
57:
58: }
|