/** * Creates a <code>{@link AssertionError}</code> using the given {@code String} as message. * <p> * It filters the AssertionError stack trace be default, to have full stack trace use * {@link #setRemoveAssertJRelatedElementsFromStackTrace(boolean)}. * * @param message the message of the {@code AssertionError} to create. * @return the created <code>{@link AssertionError}</code>. */ public AssertionError failure(String message) { AssertionError assertionError = new AssertionError(message); removeAssertJRelatedElementsFromStackTraceIfNeeded(assertionError); printThreadDumpIfNeeded(); return assertionError; }
/** * Creates a <code>{@link AssertionError}</code> using the given {@code String} as message. * <p> * It filters the AssertionError stack trace be default, to have full stack trace use * {@link #setRemoveAssertJRelatedElementsFromStackTrace(boolean)}. * * @param message the message of the {@code AssertionError} to create. * @return the created <code>{@link AssertionError}</code>. */ public AssertionError failure(String message) { AssertionError assertionError = new AssertionError(message); removeAssertJRelatedElementsFromStackTraceIfNeeded(assertionError); printThreadDumpIfNeeded(); return assertionError; }
private AssertionError comparisonFailure(Description description) { try { AssertionError comparisonFailure = newComparisonFailure(descriptionFormatter.format(description).trim()); Failures.instance().removeAssertJRelatedElementsFromStackTraceIfNeeded(comparisonFailure); return comparisonFailure; } catch (Throwable e) { return null; } }
private AssertionError assertionFailedError(String message) { try { Object o = constructorInvoker.newInstance("org.opentest4j.AssertionFailedError", MSG_ARG_TYPES_FOR_ASSERTION_FAILED_ERROR, message, expected, actual); if (o instanceof AssertionError) { AssertionError assertionError = (AssertionError) o; Failures.instance().removeAssertJRelatedElementsFromStackTraceIfNeeded(assertionError); return assertionError; } return null; } catch (Throwable e) { return null; } }
private AssertionError comparisonFailure(Description description) { try { AssertionError comparisonFailure = newComparisonFailure(descriptionFormatter.format(description).trim()); Failures.instance().removeAssertJRelatedElementsFromStackTraceIfNeeded(comparisonFailure); return comparisonFailure; } catch (Throwable e) { return null; } }
protected static void tryThrowingMultipleFailuresError(List<Throwable> errorsCollected) { if (errorsCollected.isEmpty()) return; // no errors, nothing to throw try { Object[] constructorArguments = array(null, errorsCollected); Object multipleFailuresError = CONSTRUCTOR_INVOKER.newInstance("org.opentest4j.MultipleFailuresError", MULTIPLE_FAILURES_ERROR_ARGUMENT_TYPES, constructorArguments); if (multipleFailuresError instanceof AssertionError) { AssertionError assertionError = (AssertionError) multipleFailuresError; Failures.instance().removeAssertJRelatedElementsFromStackTraceIfNeeded(assertionError); throw assertionError; } } catch (Exception e) { // do nothing, MultipleFailuresError was not in the classpath } } }
private Optional<AssertionError> tryBuildingMultipleFailuresError(String heading, List<? extends Throwable> errorsCollected) { if (errorsCollected.isEmpty()) return Optional.empty(); try { Object[] constructorArguments = array(heading, errorsCollected); Object multipleFailuresError = constructorInvoker.newInstance("org.opentest4j.MultipleFailuresError", MULTIPLE_FAILURES_ERROR_ARGUMENT_TYPES, constructorArguments); if (multipleFailuresError instanceof AssertionError) { AssertionError assertionError = (AssertionError) multipleFailuresError; Failures.instance().removeAssertJRelatedElementsFromStackTraceIfNeeded(assertionError); return Optional.of(assertionError); } } catch (Exception e) { // do nothing, MultipleFailuresError was not in the classpath } return Optional.empty(); }
public AssertionError failure(AssertionInfo info, ErrorMessageFactory messageFactory, Object actual, Object expected) { String assertionErrorMessage = assertionErrorMessage(info, messageFactory); AssertionError assertionError = assertionError(assertionErrorMessage, actual, expected); removeAssertJRelatedElementsFromStackTraceIfNeeded(assertionError); printThreadDumpIfNeeded(); return assertionError; }
private AssertionError assertionFailedError(String message) { try { Object o = constructorInvoker.newInstance("org.opentest4j.AssertionFailedError", MSG_ARG_TYPES_FOR_ASSERTION_FAILED_ERROR, message, expected, actual); if (o instanceof AssertionError) { AssertionError assertionError = (AssertionError) o; Failures.instance().removeAssertJRelatedElementsFromStackTraceIfNeeded(assertionError); return assertionError; } return null; } catch (Throwable e) { return null; } }
public AssertionError failure(AssertionInfo info, ErrorMessageFactory messageFactory, Object actual, Object expected) { String assertionErrorMessage = assertionErrorMessage(info, messageFactory); AssertionError assertionError = assertionErrorCreator.assertionError(assertionErrorMessage, actual, expected); removeAssertJRelatedElementsFromStackTraceIfNeeded(assertionError); printThreadDumpIfNeeded(); return assertionError; }
/** * Creates a <code>{@link AssertionError}</code> following this pattern: * <ol> * <li>creates a <code>{@link AssertionError}</code> using <code>{@link AssertionInfo#overridingErrorMessage()}</code> * as the error message if such value is not {@code null}, or</li> * <li>uses the given <code>{@link ErrorMessageFactory}</code> to create the detail message of the * <code>{@link AssertionError}</code>, prepending the value of <code>{@link AssertionInfo#description()}</code> to * the error message</li> * </ol> * * @param info contains information about the failed assertion. * @param messageFactory knows how to create detail messages for {@code AssertionError}s. * @return the created <code>{@link AssertionError}</code>. */ public AssertionError failure(AssertionInfo info, ErrorMessageFactory messageFactory) { AssertionError error = failureIfErrorMessageIsOverridden(info); if (error != null) return error; AssertionError assertionError = new AssertionError(messageFactory.create(info.description(), info.representation())); removeAssertJRelatedElementsFromStackTraceIfNeeded(assertionError); printThreadDumpIfNeeded(); return assertionError; }
/** * Creates a <code>{@link AssertionError}</code> following this pattern: * <ol> * <li>creates a <code>{@link AssertionError}</code> using <code>{@link AssertionInfo#overridingErrorMessage()}</code> * as the error message if such value is not {@code null}, or</li> * <li>uses the given <code>{@link ErrorMessageFactory}</code> to create the detail message of the * <code>{@link AssertionError}</code>, prepending the value of <code>{@link AssertionInfo#description()}</code> to * the error message</li> * </ol> * * @param info contains information about the failed assertion. * @param messageFactory knows how to create detail messages for {@code AssertionError}s. * @return the created <code>{@link AssertionError}</code>. */ public AssertionError failure(AssertionInfo info, ErrorMessageFactory messageFactory) { AssertionError error = failureIfErrorMessageIsOverridden(info); if (error != null) return error; AssertionError assertionError = new AssertionError(messageFactory.create(info.description(), info.representation())); removeAssertJRelatedElementsFromStackTraceIfNeeded(assertionError); printThreadDumpIfNeeded(); return assertionError; }
assertionError = new AssertionError(description + String.format(errorMessage, arguments)); Failures.instance().removeAssertJRelatedElementsFromStackTraceIfNeeded(assertionError); removeCustomAssertRelatedElementsFromStackTraceIfNeeded(assertionError); throw assertionError;
assertionError = new AssertionError(description + String.format(errorMessage, arguments)); Failures.instance().removeAssertJRelatedElementsFromStackTraceIfNeeded(assertionError); removeCustomAssertRelatedElementsFromStackTraceIfNeeded(assertionError); throw assertionError;
/** * Creates a <code>{@link AssertionError}</code> using the given {@code String} as message. * <p> * It filters the AssertionError stack trace be default, to have full stack trace use * {@link #setRemoveAssertJRelatedElementsFromStackTrace(boolean)}. * @param message the message of the {@code AssertionError} to create. * @return the created <code>{@link AssertionError}</code>. */ public AssertionError failure(String message) { AssertionError assertionError = new AssertionError(message); removeAssertJRelatedElementsFromStackTraceIfNeeded(assertionError); return assertionError; }
private AssertionError comparisonFailure(Description description) { try { AssertionError comparisonFailure = newComparisonFailure(descriptionFormatter.format(description).trim()); Failures.instance().removeAssertJRelatedElementsFromStackTraceIfNeeded(comparisonFailure); return comparisonFailure; } catch (Throwable e) { return null; } }
/** * Creates a <code>{@link AssertionError}</code> following this pattern: * <ol> * <li>creates a <code>{@link AssertionError}</code> using <code>{@link AssertionInfo#overridingErrorMessage()}</code> as the * error message if such value is not {@code null}, or</li> * <li>uses the given <code>{@link ErrorMessageFactory}</code> to create the detail message of the * <code>{@link AssertionError}</code>, prepending the value of <code>{@link AssertionInfo#description()}</code> to the error * message</li> * </ol> * @param info contains information about the failed assertion. * @param message knows how to create detail messages for {@code AssertionError}s. * @return the created <code>{@link AssertionError}</code>. */ public AssertionError failure(AssertionInfo info, ErrorMessageFactory message) { AssertionError error = failureIfErrorMessageIsOverriden(info); if (error != null) return error; AssertionError assertionError = new AssertionError(message.create(info.description(), info.representation())); removeAssertJRelatedElementsFromStackTraceIfNeeded(assertionError); return assertionError; }
/** * Copy from AssertJ to prevent errors with percents in error message */ private void failWithMessage(String errorMessage) { AssertionError assertionError = Failures.instance().failureIfErrorMessageIsOverridden(info); if (assertionError == null) { // error message was not overridden, build it. String description = MessageFormatter.instance().format(info.description(), info.representation(), ""); assertionError = new AssertionError(description + errorMessage); } Failures.instance().removeAssertJRelatedElementsFromStackTraceIfNeeded(assertionError); throw assertionError; }