1 | package org.junit.experimental.results; | |
2 | ||
3 | import org.hamcrest.BaseMatcher; | |
4 | import org.hamcrest.Description; | |
5 | import org.hamcrest.Matcher; | |
6 | import org.hamcrest.TypeSafeMatcher; | |
7 | ||
8 | /** | |
9 | * Matchers on a PrintableResult, to enable JUnit self-tests. | |
10 | * For example: | |
11 | * | |
12 | * <pre> | |
13 | * assertThat(testResult(HasExpectedException.class), isSuccessful()); | |
14 | * </pre> | |
15 | */ | |
16 | public class ResultMatchers { | |
17 | /** | |
18 | * Matches if the tests are all successful | |
19 | */ | |
20 | public static Matcher<PrintableResult> isSuccessful() { | |
21 |
1
1. isSuccessful : mutated return of Object value for org/junit/experimental/results/ResultMatchers::isSuccessful to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return failureCountIs(0); |
22 | } | |
23 | ||
24 | /** | |
25 | * Matches if there are {@code count} failures | |
26 | */ | |
27 | public static Matcher<PrintableResult> failureCountIs(final int count) { | |
28 |
1
1. failureCountIs : mutated return of Object value for org/junit/experimental/results/ResultMatchers::failureCountIs to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return new TypeSafeMatcher<PrintableResult>() { |
29 | public void describeTo(Description description) { | |
30 | description.appendText("has " + count + " failures"); | |
31 | } | |
32 | ||
33 | @Override | |
34 | public boolean matchesSafely(PrintableResult item) { | |
35 |
3
1. matchesSafely : negated conditional → NO_COVERAGE 2. matchesSafely : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE 3. matchesSafely : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return item.failureCount() == count; |
36 | } | |
37 | }; | |
38 | } | |
39 | ||
40 | /** | |
41 | * Matches if the result has exactly one failure, and it contains {@code string} | |
42 | */ | |
43 | public static Matcher<Object> hasSingleFailureContaining(final String string) { | |
44 |
1
1. hasSingleFailureContaining : mutated return of Object value for org/junit/experimental/results/ResultMatchers::hasSingleFailureContaining to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new BaseMatcher<Object>() { |
45 | public boolean matches(Object item) { | |
46 |
4
1. matches : negated conditional → NO_COVERAGE 2. matches : negated conditional → NO_COVERAGE 3. matches : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE 4. matches : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return item.toString().contains(string) && failureCountIs(1).matches(item); |
47 | } | |
48 | ||
49 | public void describeTo(Description description) { | |
50 | description.appendText("has single failure containing " + string); | |
51 | } | |
52 | }; | |
53 | } | |
54 | ||
55 | /** | |
56 | * Matches if the result has one or more failures, and at least one of them | |
57 | * contains {@code string} | |
58 | */ | |
59 | public static Matcher<PrintableResult> hasFailureContaining(final String string) { | |
60 |
1
1. hasFailureContaining : mutated return of Object value for org/junit/experimental/results/ResultMatchers::hasFailureContaining to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new BaseMatcher<PrintableResult>() { |
61 | public boolean matches(Object item) { | |
62 |
1
1. matches : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return item.toString().contains(string); |
63 | } | |
64 | ||
65 | public void describeTo(Description description) { | |
66 | description.appendText("has failure containing " + string); | |
67 | } | |
68 | }; | |
69 | } | |
70 | } | |
Mutations | ||
21 |
1.1 |
|
28 |
1.1 |
|
35 |
1.1 2.2 3.3 |
|
44 |
1.1 |
|
46 |
1.1 2.2 3.3 4.4 |
|
60 |
1.1 |
|
62 |
1.1 |