ThrowableAnyCauseMatcher.java

1
package fr.sii.ogham.testing.assertion.hamcrest;
2
3
import org.hamcrest.Description;
4
import org.hamcrest.Matcher;
5
import org.hamcrest.TypeSafeMatcher;
6
7
/**
8
 * A matcher that applies a delegate matcher to the cause of the current
9
 * Throwable, returning the result of that match.
10
 *
11
 * @param <T>
12
 *            the type of the throwable being matched
13
 */
14
public class ThrowableAnyCauseMatcher<T extends Throwable> extends TypeSafeMatcher<T> {
15
	private final Matcher<? extends Throwable> causeFinder;
16
	private final Matcher<? extends Throwable> causeMatcher;
17
18
	public ThrowableAnyCauseMatcher(Matcher<? extends Throwable> causeFinder, Matcher<? extends Throwable> causeMatcher) {
19
		this.causeFinder = causeFinder;
20
		this.causeMatcher = causeMatcher;
21
	}
22
23
	public void describeTo(Description description) {
24
		description.appendText("exception with cause matching ");
25
		description.appendDescriptionOf(causeFinder);
26
		description.appendText(" and matched cause ");
27
		description.appendDescriptionOf(causeMatcher);
28
	}
29
30
	@Override
31
	protected boolean matchesSafely(T item) {
32
		Throwable cause = item;
33 1 1. matchesSafely : negated conditional → RUN_ERROR
		while (cause != null) {
34 1 1. matchesSafely : negated conditional → RUN_ERROR
			if (causeFinder.matches(cause)) {
35 2 1. matchesSafely : replaced boolean return with true for fr/sii/ogham/testing/assertion/hamcrest/ThrowableAnyCauseMatcher::matchesSafely → RUN_ERROR
2. matchesSafely : replaced boolean return with false for fr/sii/ogham/testing/assertion/hamcrest/ThrowableAnyCauseMatcher::matchesSafely → RUN_ERROR
				return causeMatcher.matches(cause);
36
			}
37
			cause = cause.getCause();
38
		}
39 1 1. matchesSafely : replaced boolean return with true for fr/sii/ogham/testing/assertion/hamcrest/ThrowableAnyCauseMatcher::matchesSafely → NO_COVERAGE
		return false;
40
	}
41
42
	@Override
43
	protected void describeMismatchSafely(T item, Description description) {
44
		Throwable cause = item;
45 1 1. describeMismatchSafely : negated conditional → NO_COVERAGE
		while (cause != null) {
46 1 1. describeMismatchSafely : negated conditional → NO_COVERAGE
			if (causeFinder.matches(cause)) {
47
				break;
48
			}
49
			cause = cause.getCause();
50
		}
51 1 1. describeMismatchSafely : negated conditional → NO_COVERAGE
		if (cause == null) {
52
			description.appendText("was not found in exception stack");
53
		} else {
54 1 1. describeMismatchSafely : removed call to org/hamcrest/Matcher::describeMismatch → NO_COVERAGE
			causeMatcher.describeMismatch(cause, description);
55
		}
56
	}
57
58
}

Mutations

33

1.1
Location : matchesSafely
Killed by :
negated conditional → RUN_ERROR

34

1.1
Location : matchesSafely
Killed by :
negated conditional → RUN_ERROR

35

1.1
Location : matchesSafely
Killed by :
replaced boolean return with true for fr/sii/ogham/testing/assertion/hamcrest/ThrowableAnyCauseMatcher::matchesSafely → RUN_ERROR

2.2
Location : matchesSafely
Killed by :
replaced boolean return with false for fr/sii/ogham/testing/assertion/hamcrest/ThrowableAnyCauseMatcher::matchesSafely → RUN_ERROR

39

1.1
Location : matchesSafely
Killed by :
replaced boolean return with true for fr/sii/ogham/testing/assertion/hamcrest/ThrowableAnyCauseMatcher::matchesSafely → NO_COVERAGE

45

1.1
Location : describeMismatchSafely
Killed by :
negated conditional → NO_COVERAGE

46

1.1
Location : describeMismatchSafely
Killed by :
negated conditional → NO_COVERAGE

51

1.1
Location : describeMismatchSafely
Killed by :
negated conditional → NO_COVERAGE

54

1.1
Location : describeMismatchSafely
Killed by :
removed call to org/hamcrest/Matcher::describeMismatch → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.13.1