From 9b1bc4acb73042ded8a3a553631aa4f936a6918a Mon Sep 17 00:00:00 2001 From: Alberto Scotto Date: Fri, 13 May 2016 01:49:18 +0100 Subject: [PATCH] refactor: define failureCountIs in terms of failureCount --- .../junit/experimental/results/ResultMatchers.java | 13 +++---------- .../experimental/results/ResultMatchersTest.java | 3 ++- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/junit/experimental/results/ResultMatchers.java b/src/main/java/org/junit/experimental/results/ResultMatchers.java index f7a9946b8073..6c1590dad4e2 100644 --- a/src/main/java/org/junit/experimental/results/ResultMatchers.java +++ b/src/main/java/org/junit/experimental/results/ResultMatchers.java @@ -5,6 +5,8 @@ import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; +import static org.hamcrest.Matchers.equalTo; + /** * Matchers on a PrintableResult, to enable JUnit self-tests. * For example: @@ -34,16 +36,7 @@ public static Matcher isSuccessful() { * Matches if there are {@code count} failures */ public static Matcher failureCountIs(final int count) { - return new TypeSafeMatcher() { - public void describeTo(Description description) { - description.appendText("has " + count + " failures"); - } - - @Override - public boolean matchesSafely(PrintableResult item) { - return item.failureCount() == count; - } - }; + return failureCount(equalTo(count)); } /** diff --git a/src/test/java/org/junit/tests/experimental/results/ResultMatchersTest.java b/src/test/java/org/junit/tests/experimental/results/ResultMatchersTest.java index 57155c797439..6885cd10c308 100644 --- a/src/test/java/org/junit/tests/experimental/results/ResultMatchersTest.java +++ b/src/test/java/org/junit/tests/experimental/results/ResultMatchersTest.java @@ -12,10 +12,11 @@ import static org.junit.Assert.assertThat; public class ResultMatchersTest { + @Test public void hasFailuresHasGoodDescription() { assertThat(ResultMatchers.failureCountIs(3).toString(), - is("has 3 failures")); + is("has a number of failures matching <3>")); } @Theory