aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/junit/experimental/results
diff options
context:
space:
mode:
authorPete Bentley <prb@google.com>2021-03-03 15:09:19 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-03-03 15:09:19 +0000
commit4ea71685c0a1bda87567b2d1ef5ed651d9c2608b (patch)
tree10923530939981dd1dc5f44ceb6316fb9442428a /src/main/java/org/junit/experimental/results
parent5cb7d97d73027edb2274ac39e8a958bab5e2e7b3 (diff)
parenta9a7715d84046efd231e038b0dc2f551daf61701 (diff)
downloadjunit-4ea71685c0a1bda87567b2d1ef5ed651d9c2608b.tar.gz
Merge changes I578a2676,I4b37c2d0,Id1e2d638,I1ebe37da,I6135799c am: b6446bec0a am: fcd81b3e3f am: c7a6d4ec7d am: a9a7715d84
Original change: https://android-review.googlesource.com/c/platform/external/junit/+/1613132 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I56f45d05317bd1060b5838f1ada3a90bb2985d55
Diffstat (limited to 'src/main/java/org/junit/experimental/results')
-rw-r--r--src/main/java/org/junit/experimental/results/PrintableResult.java9
-rw-r--r--src/main/java/org/junit/experimental/results/ResultMatchers.java35
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) {