SimilarHtmlMatcher.java

1
package fr.sii.ogham.testing.assertion.hamcrest;
2
3
import java.util.function.Consumer;
4
5
import org.custommonkey.xmlunit.DetailedDiff;
6
import org.junit.ComparisonFailure;
7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9
import org.w3c.dom.Document;
10
11
import fr.sii.ogham.testing.assertion.OghamAssertions;
12
import fr.sii.ogham.testing.assertion.util.HtmlUtils;
13
14
/**
15
 * Check if the HTML is similar to the expected. The HTML strings are parsed
16
 * into {@link Document}s. Two documents are considered to be "similar" if they
17
 * contain the same elements and attributes regardless of order.
18
 * 
19
 * <p>
20
 * This matcher is a {@link ExpectedValueProvider} for knowing the original expected
21
 * value. Thanks to this information, {@link OghamAssertions} will generate a
22
 * {@link ComparisonFailure} with the expected string and actual string in order
23
 * to be able to visualize the differences on sources directly in the IDE.
24
 * 
25
 * <p>
26
 * See {@link HtmlUtils} for more information about "similar" HTML.
27
 * 
28
 * @author Aurélien Baudet
29
 *
30
 */
31
public class SimilarHtmlMatcher extends AbstractHtmlDiffMatcher {
32
	private static final Logger LOG = LoggerFactory.getLogger(SimilarHtmlMatcher.class);
33
34
	public SimilarHtmlMatcher(String expected) {
35
		this(expected, LOG::warn);
36
	}
37
38
	public SimilarHtmlMatcher(String expected, Consumer<String> printer) {
39
		super(expected, printer, "similar");
40
	}
41
42
	@Override
43
	protected boolean matches(DetailedDiff diff) {
44 4 1. matches : replaced boolean return with false for fr/sii/ogham/testing/assertion/hamcrest/SimilarHtmlMatcher::matches → NO_COVERAGE
2. matches : replaced boolean return with true for fr/sii/ogham/testing/assertion/hamcrest/SimilarHtmlMatcher::matches → NO_COVERAGE
3. matches : replaced boolean return with false for fr/sii/ogham/testing/assertion/hamcrest/SimilarHtmlMatcher::matches → KILLED
4. matches : replaced boolean return with true for fr/sii/ogham/testing/assertion/hamcrest/SimilarHtmlMatcher::matches → KILLED
		return diff.similar();
45
	}
46
47
	@Override
48
	public String toString() {
49 1 1. toString : replaced return value with "" for fr/sii/ogham/testing/assertion/hamcrest/SimilarHtmlMatcher::toString → NO_COVERAGE
		return "isSimilarHtml('"+expected+"')";
50
	}
51
}

Mutations

44

1.1
Location : matches
Killed by : none
replaced boolean return with false for fr/sii/ogham/testing/assertion/hamcrest/SimilarHtmlMatcher::matches → NO_COVERAGE

2.2
Location : matches
Killed by : oghamtesting.it.assertion.hamcrest.SimilarHtmlMatcherSpec
replaced boolean return with false for fr/sii/ogham/testing/assertion/hamcrest/SimilarHtmlMatcher::matches → KILLED

3.3
Location : matches
Killed by : oghamtesting.it.assertion.hamcrest.SimilarHtmlMatcherSpec
replaced boolean return with true for fr/sii/ogham/testing/assertion/hamcrest/SimilarHtmlMatcher::matches → KILLED

4.4
Location : matches
Killed by : none
replaced boolean return with true for fr/sii/ogham/testing/assertion/hamcrest/SimilarHtmlMatcher::matches → NO_COVERAGE

49

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

Active mutators

Tests examined


Report generated by PIT OGHAM