Example usage for junit.framework AssertionFailedError addSuppressed

List of usage examples for junit.framework AssertionFailedError addSuppressed

Introduction

In this page you can find the example usage for junit.framework AssertionFailedError addSuppressed.

Prototype

public final synchronized void addSuppressed(Throwable exception) 

Source Link

Document

Appends the specified exception to the exceptions that were suppressed in order to deliver this exception.

Usage

From source file:org.nuxeo.runtime.test.Failures.java

@Override
public String toString() {
    StringBuffer buffer = new StringBuffer();
    int i = 1;/*ww  w  . j  a v  a2s .  c o  m*/
    AssertionFailedError errors = new AssertionFailedError();
    for (Failure failure : failures) {
        buffer.append("* Failure " + i + ": ").append(failure.getTestHeader()).append("\n")
                .append(failure.getTrace()).append("\n");
        errors.addSuppressed(failure.getException());
        i++;
    }
    if (errors.getSuppressed().length > 0) {
        // Log because JUnit swallows some parts of the stack trace
        log.debug(errors.getMessage(), errors);
    }
    return buffer.toString();
}

From source file:org.nuxeo.runtime.test.Failures.java

/**
 * Call {@link org.junit.Assert#fail(String)} with a nice expanded string if there are failures. It also replaces
 * original failure messages with a custom one if originalMessage is not {@code null}.
 *
 * @param originalMessage Message to replace if found in a failure
 * @param customMessage Custom message to use as replacement for originalMessage
 *///from   w w  w  .  ja  v a 2s. com
public void fail(String originalMessage, String customMessage) {
    if (failures.isEmpty()) {
        Assert.fail(customMessage);
    }
    StringBuffer buffer = new StringBuffer();
    int i = 1;
    AssertionFailedError errors = new AssertionFailedError(customMessage);
    buffer.append(customMessage);
    for (Failure failure : failures) {
        buffer.append("\n* Failure " + i + ": ");
        String trace = failure.getTrace();
        if (originalMessage != null && originalMessage.equals(failure.getMessage())) {
            trace.replaceAll(originalMessage, customMessage);
        }
        buffer.append(failure.getTestHeader()).append("\n").append(trace);
        errors.addSuppressed(failure.getException());
        i++;
    }
    // Log because JUnit swallows some parts of the stack trace
    log.debug(errors.getMessage(), errors);
    Assert.fail(buffer.toString());
}