KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hanseltest > TestBug621269


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 621269. Some synthetic blocks have to
10  * be ignored
11  *
12  * @author Niklas Mehner
13  */

14 public class TestBug621269 extends TestCase {
15
16     /**
17      * Test for bug 621269.
18      * @return TestCase
19      */

20     public static Test suite() {
21         return new CoverageDecorator(TestBug621269.class,
22                                      new Class JavaDoc[] { CoverMe.class });
23     }
24
25     /** Test for bug ;) */
26     public void testBug() {
27         CoverMe cm = new CoverMe();
28
29         assertEquals(-1, cm.cover(0));
30         assertEquals(5, cm.cover(1));
31     }
32
33     /**
34      * CoverMe is a simple class that is to be covered
35      * by the Test.
36      */

37     public static class CoverMe {
38
39         /** Method to cover.
40          * @param i Parameter, use a value of 0, to cause an exception.
41          * @return 5/i or -1 if i==0
42          */

43         public int cover(int i) {
44             synchronized (this) {
45                 try {
46                     return 5 / i;
47                 } catch (ArithmeticException JavaDoc e) {
48                     return -1;
49                 }
50             }
51         }
52     }
53 }
54
Popular Tags