List of usage examples for java.lang AssertionError initCause
public synchronized Throwable initCause(Throwable cause)
From source file:eu.stratosphere.core.testing.GenericTestPlan.java
private void validateResults() { for (final GenericDataSinkBase<T> sinkOperator : this.getDataSinks()) { final Records expectedValues = this.expectedOutputs.get(sinkOperator); // need a format which is deserializable without configuration if (sinkOperator.getFormatWrapper().getUserCodeClass() == (Class<?>) SequentialOutputFormat.class && expectedValues != null && expectedValues.isInitialized()) { final Records actualValues = this.getActualOutput(sinkOperator); try { actualValues.assertEquals(expectedValues); } catch (final AssertionError e) { final AssertionError assertionError = new AssertionError( sinkOperator.getName() + ": " + e.getMessage()); assertionError.initCause(e.getCause()); throw assertionError; } finally { actualValues.close();/*from ww w.j a v a 2 s . c o m*/ } } } }
From source file:ponzu.impl.test.Verify.java
public static void fail(String message, Throwable cause) { AssertionError failedException = new AssertionError(message); failedException.initCause(cause); throwMangledException(failedException); }
From source file:com.openddal.test.BaseTestCase.java
/** * Verify the next method call on the object will throw an exception. * * @param <T> the class of the object * @param expectedErrorCode the expected error code * @param obj the object to wrap/*from w ww . j av a 2 s. co m*/ * @return a proxy for the object */ protected <T> T assertThrows(final int expectedErrorCode, final T obj) { return assertThrows(new ResultVerifier() { @Override public boolean verify(Object returnValue, Throwable t, Method m, Object... args) { int errorCode; if (t instanceof DbException) { errorCode = ((DbException) t).getErrorCode(); } else if (t instanceof SQLException) { errorCode = ((SQLException) t).getErrorCode(); } else { errorCode = 0; } if (errorCode != expectedErrorCode) { AssertionError ae = new AssertionError( "Expected an SQLException or DbException with error code " + expectedErrorCode); ae.initCause(t); throw ae; } return false; } }, obj); }
From source file:com.openddal.test.BaseTestCase.java
/** * Verify the next method call on the object will throw an exception. * * @param <T> the class of the object * @param expectedExceptionClass the expected exception class to be thrown * @param obj the object to wrap//from w w w. j a v a 2s . c o m * @return a proxy for the object */ protected <T> T assertThrows(final Class<?> expectedExceptionClass, final T obj) { return assertThrows(new ResultVerifier() { @Override public boolean verify(Object returnValue, Throwable t, Method m, Object... args) { if (t == null) { throw new AssertionError("Expected an exception of type " + expectedExceptionClass.getSimpleName() + " to be thrown, but the method returned " + returnValue + " for " + ProxyCodeGenerator.formatMethodCall(m, args)); } if (!expectedExceptionClass.isAssignableFrom(t.getClass())) { AssertionError ae = new AssertionError( "Expected an exception of type\n" + expectedExceptionClass.getSimpleName() + " to be thrown, but the method under test " + "threw an exception of type\n" + t.getClass().getSimpleName() + " (see in the 'Caused by' for the exception " + "that was thrown) " + " for " + ProxyCodeGenerator.formatMethodCall(m, args)); ae.initCause(t); throw ae; } return false; } }, obj); }
From source file:com.gs.collections.impl.test.Verify.java
public static void fail(String message, Throwable cause) { AssertionError failedException = new AssertionError(message); failedException.initCause(cause); Verify.throwMangledException(failedException); }