KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hanseltest > TestBug584900


1 package org.hanseltest;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5
6 import org.hansel.CoverageDecorator;
7
8 /**
9  * Test for Bug 584900. This Bug occured in a "try { } catch { } finally {}"
10  * situation and caused the finally loop never to be covered.
11  *
12  * @author Niklas Mehner
13  */

14 public class TestBug584900 extends TestCase {
15     
16     /**
17      * Creates a new Test.
18      * @param name Name of the test.
19      */

20     public TestBug584900(String JavaDoc name) {
21         super(name);
22     }
23
24     /**
25      * Static method to create the TestSuit.
26      * This wrapps the test in a CoverageDecorator.
27      * @return TestSuit for this class.
28      */

29     public static Test suite() {
30         return new CoverageDecorator(TestBug584900.class,
31                                      new Class JavaDoc[] {Example.class});
32     }
33
34     /**
35      * Covers the example class.
36      */

37     public void testClass() {
38         Example example = new Example();
39         assertEquals(2, example.testMethod("java.lang.String"));
40         assertEquals(3, example.testMethod("no.known.class"));
41     }
42
43     /** Example class to be covered. */
44     public static class Example {
45         /**
46          * Test method, that returns an int, depending on
47          * wether classname exists or not.
48          * @param classname Classname-
49          * @return 2, if classname exists, 3 otherwise.
50          */

51         public int testMethod(String JavaDoc classname) {
52             int i = 0;
53             try {
54                 Class.forName(classname);
55             } catch (ClassNotFoundException JavaDoc cnfe) {
56                 i += 1;
57             } finally {
58                 i += 2;
59             }
60
61             return i;
62         }
63         
64     }
65 }
66
Popular Tags