diff options
author | Pete Bentley <prb@google.com> | 2021-02-24 10:26:16 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-02-24 10:26:16 +0000 |
commit | 82af4b8b1d440f44b6ebac4db1fd61ae1d35a15e (patch) | |
tree | 1331fa1b743d5d0a341f82ff555ce4c602f40ab9 /src/main/java/org/junit/runners/model/MultipleFailureException.java | |
parent | d5e30375603aa83d21d16fbef079caab4d24e4c1 (diff) | |
parent | d8911c6e959a1bda9b2b77d9aa0d35eea7a401f9 (diff) | |
download | junit-82af4b8b1d440f44b6ebac4db1fd61ae1d35a15e.tar.gz |
Merge changes I8f5cd126,Ifdb59336,I6abae5ae,I5ec909df am: d135966357 am: d8911c6e95
Original change: https://android-review.googlesource.com/c/platform/external/junit/+/1601635
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: Ib00d0e3bda09315496b61b51b207bd8981c947e7
Diffstat (limited to 'src/main/java/org/junit/runners/model/MultipleFailureException.java')
-rw-r--r-- | src/main/java/org/junit/runners/model/MultipleFailureException.java | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/src/main/java/org/junit/runners/model/MultipleFailureException.java b/src/main/java/org/junit/runners/model/MultipleFailureException.java index 325c645..8e355a7 100644 --- a/src/main/java/org/junit/runners/model/MultipleFailureException.java +++ b/src/main/java/org/junit/runners/model/MultipleFailureException.java @@ -1,9 +1,13 @@ package org.junit.runners.model; +import java.io.PrintStream; +import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.junit.TestCouldNotBeSkippedException; +import org.junit.internal.AssumptionViolatedException; import org.junit.internal.Throwables; /** @@ -17,12 +21,22 @@ public class MultipleFailureException extends Exception { /* * We have to use the f prefix until the next major release to ensure * serialization compatibility. - * See https://github.com/junit-team/junit/issues/976 + * See https://github.com/junit-team/junit4/issues/976 */ private final List<Throwable> fErrors; public MultipleFailureException(List<Throwable> errors) { - this.fErrors = new ArrayList<Throwable>(errors); + if (errors.isEmpty()) { + throw new IllegalArgumentException( + "List of Throwables must not be empty"); + } + this.fErrors = new ArrayList<Throwable>(errors.size()); + for (Throwable error : errors) { + if (error instanceof AssumptionViolatedException) { + error = new TestCouldNotBeSkippedException((AssumptionViolatedException) error); + } + fErrors.add(error); + } } public List<Throwable> getFailures() { @@ -34,11 +48,32 @@ public class MultipleFailureException extends Exception { StringBuilder sb = new StringBuilder( String.format("There were %d errors:", fErrors.size())); for (Throwable e : fErrors) { - sb.append(String.format("\n %s(%s)", e.getClass().getName(), e.getMessage())); + sb.append(String.format("%n %s(%s)", e.getClass().getName(), e.getMessage())); } return sb.toString(); } + @Override + public void printStackTrace() { + for (Throwable e: fErrors) { + e.printStackTrace(); + } + } + + @Override + public void printStackTrace(PrintStream s) { + for (Throwable e: fErrors) { + e.printStackTrace(s); + } + } + + @Override + public void printStackTrace(PrintWriter s) { + for (Throwable e: fErrors) { + e.printStackTrace(s); + } + } + /** * Asserts that a list of throwables is empty. If it isn't empty, * will throw {@link MultipleFailureException} (if there are |