| 1 | package fr.sii.ogham.testing.assertion.hamcrest; | |
| 2 | ||
| 3 | import static org.hamcrest.Matchers.instanceOf; | |
| 4 | import static org.hamcrest.Matchers.is; | |
| 5 | import static org.hamcrest.Matchers.notNullValue; | |
| 6 | ||
| 7 | import org.hamcrest.Matcher; | |
| 8 | ||
| 9 | public final class ExceptionMatchers { | |
| 10 | ||
| 11 | /** | |
| 12 | * Returns a matcher that verifies that any exception in the stack matches | |
| 13 | * the finder exists. | |
| 14 | * | |
| 15 | * @param expectedClass | |
| 16 | * to find the cause in exception stack | |
| 17 | * @param <T> | |
| 18 | * type of the outer exception | |
| 19 | * @return the matcher | |
| 20 | */ | |
| 21 | public static <T extends Throwable> Matcher<T> hasAnyCause(final Class<? extends Throwable> expectedClass) { | |
| 22 |
4
1. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → NO_COVERAGE 2. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → KILLED 3. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → KILLED 4. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → KILLED |
return hasAnyCause(instanceOf(expectedClass)); |
| 23 | } | |
| 24 | ||
| 25 | /** | |
| 26 | * Returns a matcher that verifies that any exception in the stack matches | |
| 27 | * the finder exists. | |
| 28 | * | |
| 29 | * @param finder | |
| 30 | * to find the cause in exception stack, the finder is also the matcher | |
| 31 | * @param <T> | |
| 32 | * type of the outer exception | |
| 33 | * @return the matcher | |
| 34 | */ | |
| 35 | public static <T extends Throwable> Matcher<T> hasAnyCause(final Matcher<? extends Throwable> finder) { | |
| 36 |
4
1. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → NO_COVERAGE 2. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → KILLED 3. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → KILLED 4. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → KILLED |
return new ThrowableAnyCauseMatcher<>(finder, notNullValue(Throwable.class)); |
| 37 | } | |
| 38 | ||
| 39 | /** | |
| 40 | * Returns a matcher that verifies that any exception in the stack matches | |
| 41 | * the finder and also checks that the supplied matcher evaluates to true. | |
| 42 | * | |
| 43 | * @param finder | |
| 44 | * to find the cause in exception stack | |
| 45 | * @param matcher | |
| 46 | * to apply to the cause of the outer exception | |
| 47 | * @param <T> | |
| 48 | * type of the outer exception | |
| 49 | * @return the matcher | |
| 50 | */ | |
| 51 | public static <T extends Throwable> Matcher<T> hasAnyCause(final Matcher<? extends Throwable> finder, final Matcher<? extends Throwable> matcher) { | |
| 52 |
3
1. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → NO_COVERAGE 2. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → KILLED 3. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → KILLED |
return new ThrowableAnyCauseMatcher<>(finder, matcher); |
| 53 | } | |
| 54 | ||
| 55 | /** | |
| 56 | * Returns a matcher that verifies that any exception in the stack matches | |
| 57 | * the expected class and also checks that the supplied matcher evaluates to | |
| 58 | * true. | |
| 59 | * | |
| 60 | * @param expectedClass | |
| 61 | * to find the cause in exception stack | |
| 62 | * @param matcher | |
| 63 | * to apply to the cause of the outer exception | |
| 64 | * @param <T> | |
| 65 | * type of the outer exception | |
| 66 | * @return the matcher | |
| 67 | */ | |
| 68 | public static <T extends Throwable> Matcher<T> hasAnyCause(final Class<? extends Throwable> expectedClass, final Matcher<? extends Throwable> matcher) { | |
| 69 |
8
1. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → NO_COVERAGE 2. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → TIMED_OUT 3. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → KILLED 4. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → KILLED 5. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → KILLED 6. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → KILLED 7. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → KILLED 8. hasAnyCause : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasAnyCause → KILLED |
return new ThrowableAnyCauseMatcher<>(instanceOf(expectedClass), matcher); |
| 70 | } | |
| 71 | ||
| 72 | /** | |
| 73 | * Returns a matcher that verifies that the exception has a message for | |
| 74 | * which the supplied matcher evaluates to true. | |
| 75 | * | |
| 76 | * @param matcher | |
| 77 | * to apply to the cause of the exception | |
| 78 | * @param <T> | |
| 79 | * type of the outer exception | |
| 80 | * @return the matcher | |
| 81 | */ | |
| 82 | public static <T extends Throwable> Matcher<T> hasMessage(final Matcher<? extends String> matcher) { | |
| 83 |
9
1. hasMessage : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasMessage → NO_COVERAGE 2. hasMessage : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasMessage → TIMED_OUT 3. hasMessage : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasMessage → KILLED 4. hasMessage : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasMessage → KILLED 5. hasMessage : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasMessage → KILLED 6. hasMessage : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasMessage → KILLED 7. hasMessage : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasMessage → KILLED 8. hasMessage : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasMessage → KILLED 9. hasMessage : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasMessage → KILLED |
return new ThrowableMessageMatcher<>(matcher); |
| 84 | } | |
| 85 | ||
| 86 | /** | |
| 87 | * shortcut to: | |
| 88 | * | |
| 89 | * <pre> | |
| 90 | * {@code | |
| 91 | * hasMessage(is("some message")) | |
| 92 | * } | |
| 93 | * </pre> | |
| 94 | * | |
| 95 | * @param expectedMessage | |
| 96 | * the expected message of the exception | |
| 97 | * @param <T> | |
| 98 | * type of the outer exception | |
| 99 | * @return the matcher | |
| 100 | */ | |
| 101 | public static <T extends Throwable> Matcher<T> hasMessage(String expectedMessage) { | |
| 102 |
5
1. hasMessage : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasMessage → NO_COVERAGE 2. hasMessage : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasMessage → KILLED 3. hasMessage : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasMessage → KILLED 4. hasMessage : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasMessage → KILLED 5. hasMessage : replaced return value with null for fr/sii/ogham/testing/assertion/hamcrest/ExceptionMatchers::hasMessage → KILLED |
return new ThrowableMessageMatcher<>(is(expectedMessage)); |
| 103 | } | |
| 104 | ||
| 105 | private ExceptionMatchers() { | |
| 106 | super(); | |
| 107 | } | |
| 108 | } | |
Mutations | ||
| 22 |
1.1 2.2 3.3 4.4 |
|
| 36 |
1.1 2.2 3.3 4.4 |
|
| 52 |
1.1 2.2 3.3 |
|
| 69 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 83 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 |
|
| 102 |
1.1 2.2 3.3 4.4 5.5 |