public void testToSQLException() { Exception testSQLE = new SQLException("test"); assertSame(testSQLE, exceptions.toSQLException(testSQLE)); Exception checkedException = new Exception("test"); assertFalse(checkedException instanceof SQLException); Exception returned = exceptions.toSQLException(checkedException); assertTrue(returned instanceof SQLException); assertEquals(checkedException, returned.getCause()); }
public void testVoidBlock() { final Exception orig = new SQLException(); assertNull(orig.getMessage()); Exception caught = null; Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws Exception { throw orig; } }; try { block.exec(); } catch (WrappedException converted) { caught = converted; } assertNotNull(caught); assertEquals(orig, caught.getCause()); }
public void testReturnBlockThrows() { Exception expected = null; final Exception orig = new Exception("test"); Exceptions.StringBlock block = new Exceptions.StringBlock() { public String inner() throws Exception { throw orig; } }; try { block.exec(); } catch (Exception e) { expected = e; } assertNotNull(expected); assertEquals(orig, expected.getCause()); }
public void testRunSQLBlock() { ByteArrayOutputStream log = new ByteArrayOutputStream(); String msg = "search for me"; final Exception orig = new Exception(msg); SQLException caught = null; Exceptions.SQLBlock block = new Exceptions.SQLBlock( new PrintStream(log)) { public Object inner() throws Exception { throw orig; } }; try { block.exec(); } catch (SQLException e) { caught = e; } assertNotNull(caught); assertEquals(orig, caught.getCause()); assertTrue(log.toString().indexOf(msg) >= 0); }
public void testSwallowExceptionBlockExec() { ByteArrayOutputStream log = new ByteArrayOutputStream(); PrintStream fakeErr = new PrintStream(log); final Exception orig = new SQLException("foo"); Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws Exception { throw orig; } }; block.execNotThrowingExceptions(fakeErr); assertTrue(log.toString().indexOf("foo") >= 0); } }
public void testReturnBlock() { final String expected = "foo"; Exceptions.Block block = new Exceptions.Block() { public Object inner() throws Exception { return expected; } }; String actual = (String) block.exec(); assertEquals(expected, actual); }
public void testRunSQLBlock() { ByteArrayOutputStream log = new ByteArrayOutputStream(); String msg = "search for me"; final Exception orig = new Exception(msg); SQLException caught = null; Exceptions.SQLBlock block = new Exceptions.SQLBlock( new PrintStream(log)) { public Object inner() throws Exception { throw orig; } }; try { block.exec(); } catch (SQLException e) { caught = e; } assertNotNull(caught); assertEquals(orig, caught.getCause()); assertTrue(log.toString().indexOf(msg) >= 0); }
public void testReturnBlockThrows() { Exception expected = null; final Exception orig = new Exception("test"); Exceptions.StringBlock block = new Exceptions.StringBlock() { @Override public String inner() throws Exception { throw orig; } }; try { block.exec(); } catch (Exception e) { expected = e; } assertNotNull(expected); assertEquals(orig, expected.getCause()); }
public void testSwallowExceptionBlockExec() { ByteArrayOutputStream log = new ByteArrayOutputStream(); PrintStream fakeErr = new PrintStream(log); final Exception orig = new SQLException("foo"); Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws Exception { throw orig; } }; block.execSwallowingException(fakeErr); assertTrue(log.toString().indexOf("foo") >= 0); } }
public void testReturnBlock() { final String expected = "foo"; Exceptions.StringBlock block = new Exceptions.StringBlock() { public String inner() throws Exception { return expected; } }; assertEquals(expected, block.exec()); }
public void testToRuntime() { Exception runtime = new RuntimeException("test"); assertSame(runtime, exceptions.toRuntime(runtime)); Exception checkedException = new SQLException("test"); assertFalse(checkedException instanceof RuntimeException); Exception returned = exceptions.toRuntime(checkedException); assertTrue(returned instanceof RuntimeException); assertEquals(checkedException, returned.getCause()); }
public void testVoidBlock() { final Exception orig = new SQLException(); assertNull(orig.getMessage()); Exception caught = null; Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws Exception { throw orig; } }; try { block.exec(); } catch (WrappedException converted) { caught = converted; } assertNotNull(caught); assertEquals(orig, caught.getCause()); }
public void testRunSQLBlock() { ByteArrayOutputStream log = new ByteArrayOutputStream(); String msg = "search for me"; final Exception orig = new Exception(msg); SQLException caught = null; Exceptions.SQLBlock block = new Exceptions.SQLBlock( new PrintStream(log)) { @Override public Object inner() throws Exception { throw orig; } }; try { block.exec(); } catch (SQLException e) { caught = e; } assertNotNull(caught); assertEquals(orig, caught.getCause()); assertTrue(log.toString().indexOf(msg) >= 0); }
public void testReturnBlockThrows() { Exception expected = null; final Exception orig = new Exception("test"); Exceptions.Block block = new Exceptions.Block() { public Object inner() throws Exception { throw orig; } }; try { block.exec(); } catch (Exception e) { expected = e; } assertNotNull(expected); assertEquals(orig, expected.getCause()); }
public void testSwallowExceptionBlockExec() { ByteArrayOutputStream log = new ByteArrayOutputStream(); PrintStream fakeErr = new PrintStream(log); final Exception orig = new SQLException("foo"); Exceptions.VoidBlock block = new Exceptions.VoidBlock() { @Override public void inner() throws Exception { throw orig; } }; block.execNotThrowingExceptions(fakeErr); assertTrue(log.toString().indexOf("foo") >= 0); } }
public void testReturnBlock() { final String expected = "foo"; Exceptions.StringBlock block = new Exceptions.StringBlock() { @Override public String inner() throws Exception { return expected; } }; assertEquals(expected, block.exec()); }
public void testToSQLException() { Exception testSQLE = new SQLException("test"); assertSame(testSQLE, exceptions.toSQLException(testSQLE)); Exception checkedException = new Exception("test"); assertFalse(checkedException instanceof SQLException); Exception returned = exceptions.toSQLException(checkedException); assertTrue(returned instanceof SQLException); assertEquals(checkedException, returned.getCause()); }
public void testVoidBlock() { final Exception orig = new SQLException(); assertNull(orig.getMessage()); Exception caught = null; Exceptions.VoidBlock block = new Exceptions.VoidBlock() { @Override public void inner() throws Exception { throw orig; } }; try { block.exec(); } catch (WrappedException converted) { caught = converted; } assertNotNull(caught); assertEquals(orig, caught.getCause()); }
public void testToRuntime() { Exception runtime = new RuntimeException("test"); assertSame(runtime, exceptions.toRuntime(runtime)); Exception checkedException = new SQLException("test"); assertFalse(checkedException instanceof RuntimeException); Exception returned = exceptions.toRuntime(checkedException); assertTrue(returned instanceof RuntimeException); assertEquals(checkedException, returned.getCause()); }
public void testToSQLException() { Exception testSQLE = new SQLException("test"); assertSame(testSQLE, exceptions.toSQLException(testSQLE)); Exception checkedException = new Exception("test"); assertFalse(checkedException instanceof SQLException); Exception returned = exceptions.toSQLException(checkedException); assertTrue(returned instanceof SQLException); assertEquals(checkedException, returned.getCause()); }