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