1 16 package scriptella.util; 17 18 import scriptella.AbstractTestCase; 19 20 import java.sql.SQLException ; 21 22 28 public class ExceptionUtilsTest extends AbstractTestCase { 29 public void testGetCause() { 30 SQLException e = new SQLException (); 31 SQLException e2 = new SQLException ("2"); 32 e.setNextException(e2); 33 assertTrue(e2==ExceptionUtils.getCause(e)); 34 assertNull(ExceptionUtils.getCause(new Throwable ())); 35 } 36 37 public void testThrowUnchecked() { 38 Error er = new Error (); 39 try { 40 ExceptionUtils.throwUnchecked(er); 41 fail("Error must be rethrown"); 42 } catch (Error e) { 43 assertTrue(er==e); 44 } 45 RuntimeException re = new RuntimeException (); 46 try { 47 ExceptionUtils.throwUnchecked(re); 48 fail("Runtime ex must be rethrown"); 49 } catch (RuntimeException e) { 50 assertTrue(re==e); 51 } 52 try { 53 ExceptionUtils.throwUnchecked(new Exception ()); 54 fail("Runtime ex must be thrown"); 55 } catch (IllegalStateException e) { 56 } 57 58 59 } 60 61 } 62 | Popular Tags |