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/experimental/results | |
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/experimental/results')
-rw-r--r-- | src/main/java/org/junit/experimental/results/PrintableResult.java | 9 | ||||
-rw-r--r-- | src/main/java/org/junit/experimental/results/ResultMatchers.java | 35 |
2 files changed, 41 insertions, 3 deletions
diff --git a/src/main/java/org/junit/experimental/results/PrintableResult.java b/src/main/java/org/junit/experimental/results/PrintableResult.java index ffe22f0..0f67766 100644 --- a/src/main/java/org/junit/experimental/results/PrintableResult.java +++ b/src/main/java/org/junit/experimental/results/PrintableResult.java @@ -54,6 +54,15 @@ public class PrintableResult { return result.getFailures().size(); } + /** + * Returns the failures in this result. + * + * @since 4.13 + */ + public List<Failure> failures() { + return result.getFailures(); + } + @Override public String toString() { ByteArrayOutputStream stream = new ByteArrayOutputStream(); diff --git a/src/main/java/org/junit/experimental/results/ResultMatchers.java b/src/main/java/org/junit/experimental/results/ResultMatchers.java index cf58f1b..92f2e6b 100644 --- a/src/main/java/org/junit/experimental/results/ResultMatchers.java +++ b/src/main/java/org/junit/experimental/results/ResultMatchers.java @@ -14,6 +14,15 @@ import org.hamcrest.TypeSafeMatcher; * </pre> */ public class ResultMatchers { + + /** + * Do not instantiate. + * @deprecated will be private soon. + */ + @Deprecated + public ResultMatchers() { + } + /** * Matches if the tests are all successful */ @@ -53,13 +62,33 @@ public class ResultMatchers { } /** + * Matches if the result has exactly one failure matching the given matcher. + * + * @since 4.13 + */ + public static Matcher<PrintableResult> hasSingleFailureMatching(final Matcher<Throwable> matcher) { + return new TypeSafeMatcher<PrintableResult>() { + @Override + public boolean matchesSafely(PrintableResult item) { + return item.failureCount() == 1 && matcher.matches(item.failures().get(0).getException()); + } + + public void describeTo(Description description) { + description.appendText("has failure with exception matching "); + matcher.describeTo(description); + } + }; + } + + /** * Matches if the result has one or more failures, and at least one of them * contains {@code string} */ public static Matcher<PrintableResult> hasFailureContaining(final String string) { - return new BaseMatcher<PrintableResult>() { - public boolean matches(Object item) { - return item.toString().contains(string); + return new TypeSafeMatcher<PrintableResult>() { + @Override + public boolean matchesSafely(PrintableResult item) { + return item.failureCount() > 0 && item.toString().contains(string); } public void describeTo(Description description) { |