private static AssertionError createLeakError(DataBuffer delegate) { String message = String.format("DataBuffer leak detected: {%s} has not been released.%n" + "Stack trace of buffer allocation statement follows:", delegate); AssertionError result = new AssertionError(message); // remove first four irrelevant stack trace elements StackTraceElement[] oldTrace = result.getStackTrace(); StackTraceElement[] newTrace = new StackTraceElement[oldTrace.length - 4]; System.arraycopy(oldTrace, 4, newTrace, 0, oldTrace.length - 4); result.setStackTrace(newTrace); return result; }
static void fail(@Nullable Object actualValue, Matcher<?> matcher) { Description description = new StringDescription() .appendText("\nExpected: ") .appendDescriptionOf(matcher) .appendText("\n but: "); matcher.describeMismatch(actualValue, description); AssertionError assertionError = new AssertionError(description.toString()); assertionError.setStackTrace(ObjectChecker.trimStackTrace(assertionError.getStackTrace())); throw assertionError; }
private void removeCustomAssertRelatedElementsFromStackTraceIfNeeded(AssertionError assertionError) { if (!Failures.instance().isRemoveAssertJRelatedElementsFromStackTrace()) return; if (isAssertjAssertClass()) return; StackTraceElement[] newStackTrace = Arrays.stream(assertionError.getStackTrace()) .filter(element -> !isElementOfCustomAssert(element)) .toArray(StackTraceElement[]::new); assertionError.setStackTrace(newStackTrace); }
@Override public void fail(AssertionError failure) { ThrowableAssumptionViolatedException assumptionViolated = new ThrowableAssumptionViolatedException(failure.getMessage(), failure.getCause()); assumptionViolated.setStackTrace(failure.getStackTrace()); throw assumptionViolated; } };
message, showStackTrace ? printSubsequentFailure(failures.get(0).getStackTrace(), failure) : failure.getMessage());
private void removeCustomAssertRelatedElementsFromStackTraceIfNeeded(AssertionError assertionError) { if (!Failures.instance().isRemoveAssertJRelatedElementsFromStackTrace()) return; if (isAssertjAssertClass()) return; StackTraceElement[] newStackTrace = Arrays.stream(assertionError.getStackTrace()) .filter(element -> !isElementOfCustomAssert(element)) .toArray(StackTraceElement[]::new); assertionError.setStackTrace(newStackTrace); }
@Override public T apply( GraphDatabaseService graphDb ) { try { return perform( graphDb ); } catch ( AssertionError e ) { AssertionError error = new AssertionError( message + ": " + e.getMessage() ); error.setStackTrace( e.getStackTrace() ); throw error; } }
StackTraceElement[] stackTrace = e.getStackTrace(); StackTraceElement[] newStackTrace = new StackTraceElement[stackTrace.length - framesToPop]; System.arraycopy(stackTrace, framesToPop, newStackTrace, 0, newStackTrace.length);
StackTraceElement[] stackTrace = e.getStackTrace(); StackTraceElement[] newStackTrace = new StackTraceElement[stackTrace.length - framesToPop]; System.arraycopy(stackTrace, framesToPop, newStackTrace, 0, newStackTrace.length);
originalFailure); e.setStackTrace(smallerFailure.getStackTrace()); return e;
/** * Assertion failure exception constructor * @param _evaluation evaluation * @param _cause Assertion error cause */ public AssertException(final String _evaluation,final AssertionError _cause) { super(SimpleFormat.format("evaluation {}, line {}: {}", _evaluation,_cause.getStackTrace()[0].getLineNumber(),_cause.getMessage()),_cause); this.evaluation=_evaluation; this.assertion=null; this.expected=null; this.actual=null; this.description=_cause.getMessage(); }
private AssertionError generateError(final List<AssertionError> assertionErrors) { AssertionError error = new AssertionError(joinMessages(assertionErrors)); List<StackTraceElement> allElements = Lists.newArrayList(); for (AssertionError assertionError : assertionErrors) { allElements.addAll(Arrays.asList(assertionError.getStackTrace())); } error.setStackTrace(allElements.toArray(new StackTraceElement[allElements.size()])); return error; }
originalFailure); e.setStackTrace(smallerFailure.getStackTrace()); return e;
@Override public final void setCustomErrorMessage(CharSequence customMessage) { Expectation expectation = getCurrentExpectation(); if (pendingError == null) { expectation.setCustomErrorMessage(customMessage); } else if (customMessage != null) { StackTraceElement[] previousStackTrace = pendingError.getStackTrace(); pendingError = new AssertionError(customMessage + "\n" + pendingError.getMessage()); pendingError.setStackTrace(previousStackTrace); } }
StackTraceElement[] stackTrace = e.getStackTrace(); StackTraceElement[] newStackTrace = new StackTraceElement[stackTrace.length - framesToPop]; System.arraycopy(stackTrace, framesToPop, newStackTrace, 0, newStackTrace.length);
StackTraceElement[] stackTrace = e.getStackTrace(); StackTraceElement[] newStackTrace = new StackTraceElement[stackTrace.length - framesToPop]; System.arraycopy(stackTrace, framesToPop, newStackTrace, 0, newStackTrace.length);