KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junit > tests > extensions > ExceptionTestCaseTest


1 package junit.tests.extensions;
2
3 import junit.framework.*;
4 import junit.extensions.*;
5
6 public class ExceptionTestCaseTest extends junit.framework.TestCase {
7
8     static public class ThrowExceptionTestCase extends ExceptionTestCase {
9         public ThrowExceptionTestCase(String JavaDoc name, Class JavaDoc exception) {
10             super(name, exception);
11         }
12         public void test() {
13             throw new IndexOutOfBoundsException JavaDoc();
14         }
15     }
16
17     static public class ThrowRuntimeExceptionTestCase extends ExceptionTestCase {
18         public ThrowRuntimeExceptionTestCase(String JavaDoc name, Class JavaDoc exception) {
19             super(name, exception);
20         }
21         public void test() {
22             throw new RuntimeException JavaDoc();
23         }
24     }
25
26     static public class ThrowNoExceptionTestCase extends ExceptionTestCase {
27         public ThrowNoExceptionTestCase(String JavaDoc name, Class JavaDoc exception) {
28             super(name, exception);
29         }
30         public void test() {
31         }
32     }
33
34     public void testExceptionSubclass() {
35         ExceptionTestCase test= new ThrowExceptionTestCase("test", IndexOutOfBoundsException JavaDoc.class);
36         TestResult result= test.run();
37         assertEquals(1, result.runCount());
38         assertTrue(result.wasSuccessful());
39     }
40     public void testExceptionTest() {
41         ExceptionTestCase test= new ThrowExceptionTestCase("test", IndexOutOfBoundsException JavaDoc.class);
42         TestResult result= test.run();
43         assertEquals(1, result.runCount());
44         assertTrue(result.wasSuccessful());
45     }
46     public void testFailure() {
47         ExceptionTestCase test= new ThrowRuntimeExceptionTestCase("test", IndexOutOfBoundsException JavaDoc.class);
48         TestResult result= test.run();
49         assertEquals(1, result.runCount());
50         assertEquals(1, result.errorCount());
51     }
52     public void testNoException() {
53         ExceptionTestCase test= new ThrowNoExceptionTestCase("test", Exception JavaDoc.class);
54         TestResult result= test.run();
55         assertEquals(1, result.runCount());
56         assertEquals(1, result.failureCount());
57     }
58     public void testWrongException() {
59         ExceptionTestCase test= new ThrowRuntimeExceptionTestCase("test", IndexOutOfBoundsException JavaDoc.class);
60         TestResult result= test.run();
61         assertEquals(1, result.runCount());
62         assertEquals(1, result.errorCount());
63     }
64 }
Popular Tags