Skip to content

Commit

Permalink
refactor: define failureCountIs in terms of failureCount
Browse files Browse the repository at this point in the history
  • Loading branch information
alb-i986 committed May 13, 2016
1 parent e5e47b3 commit 9b1bc4a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
13 changes: 3 additions & 10 deletions src/main/java/org/junit/experimental/results/ResultMatchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -34,16 +36,7 @@ public static Matcher<PrintableResult> isSuccessful() {
* Matches if there are {@code count} failures
*/
public static Matcher<PrintableResult> failureCountIs(final int count) {
return new TypeSafeMatcher<PrintableResult>() {
public void describeTo(Description description) {
description.appendText("has " + count + " failures");
}

@Override
public boolean matchesSafely(PrintableResult item) {
return item.failureCount() == count;
}
};
return failureCount(equalTo(count));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9b1bc4a

Please sign in to comment.