ThrowableMessageMatcher.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 message 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 ThrowableMessageMatcher<T extends Throwable> extends TypeSafeMatcher<T> {
15
	private final Matcher<? extends String> messageMatcher;
16
17
	public ThrowableMessageMatcher(Matcher<? extends String> messageMatcher) {
18
		super();
19
		this.messageMatcher = messageMatcher;
20
	}
21
22
	public void describeTo(Description description) {
23
		description.appendText("exception with message ");
24
		description.appendDescriptionOf(messageMatcher);
25
	}
26
27
	@Override
28
	protected boolean matchesSafely(T item) {
29 2 1. matchesSafely : replaced boolean return with false for fr/sii/ogham/testing/assertion/hamcrest/ThrowableMessageMatcher::matchesSafely → RUN_ERROR
2. matchesSafely : replaced boolean return with true for fr/sii/ogham/testing/assertion/hamcrest/ThrowableMessageMatcher::matchesSafely → RUN_ERROR
		return messageMatcher.matches(item.getMessage());
30
	}
31
32
	@Override
33
	protected void describeMismatchSafely(T item, Description description) {
34
		description.appendText("message ");
35 1 1. describeMismatchSafely : removed call to org/hamcrest/Matcher::describeMismatch → NO_COVERAGE
		messageMatcher.describeMismatch(item.getMessage(), description);
36
	}
37
	
38
	@Override
39
	public String toString() {
40 1 1. toString : replaced return value with "" for fr/sii/ogham/testing/assertion/hamcrest/ThrowableMessageMatcher::toString → NO_COVERAGE
		return "hasMessage('"+messageMatcher+"')";
41
	}
42
}

Mutations

29

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

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

35

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

40

1.1
Location : toString
Killed by :
replaced return value with "" for fr/sii/ogham/testing/assertion/hamcrest/ThrowableMessageMatcher::toString → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.13.1