Source of ExceptionTestCaseTest.java


  1: package junit.tests.extensions;

  3: import junit.framework.*;
  4: import junit.extensions.*;

  6: public class ExceptionTestCaseTest extends junit.framework.TestCase {

  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:         }

 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:         }

 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:         }

 34:         public void testExceptionSubclass() {
 35:                 ExceptionTestCase test= new ThrowExceptionTestCase("test", IndexOutOfBoundsException.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.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.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.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.class);
 60:                 TestResult result= test.run();
 61:                 assertEquals(1, result.runCount());
 62:                 assertEquals(1, result.errorCount());
 63:         }
 64: }