IdenticalHtmlMatcher.java

1
package fr.sii.ogham.testing.assertion.hamcrest;
2
3
import java.util.function.Consumer;
4
5
import org.opentest4j.AssertionFailedError;
6
import org.slf4j.Logger;
7
import org.slf4j.LoggerFactory;
8
import org.w3c.dom.Document;
9
10
import fr.sii.ogham.testing.assertion.OghamAssertions;
11
import fr.sii.ogham.testing.assertion.util.HtmlUtils;
12
import org.xmlunit.diff.Diff;
13
14
/**
15
 * Check if the HTML is identical to the expected. The HTML strings are parsed
16
 * into {@link Document}s. Two documents are considered to be "identical" if
17
 * they contain the same elements and attributes in the same 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 AssertionFailedError} 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 "identical" HTML.
27
 * 
28
 * @author Aurélien Baudet
29
 *
30
 */
31
public class IdenticalHtmlMatcher extends AbstractHtmlDiffMatcher {
32
	private static final Logger LOG = LoggerFactory.getLogger(IdenticalHtmlMatcher.class);
33
	
34
	public IdenticalHtmlMatcher(String expected) {
35
		this(expected, LOG::warn);
36
	}
37
38
	public IdenticalHtmlMatcher(String expected, Consumer<String> printer) {
39
		super(expected, printer, "identical", true);
40
	}
41
42
	@Override
43
	protected boolean matches(Diff diff) {
44 2 1. matches : negated conditional → NO_COVERAGE
2. matches : replaced boolean return with true for fr/sii/ogham/testing/assertion/hamcrest/IdenticalHtmlMatcher::matches → NO_COVERAGE
		return !diff.hasDifferences();
45
	}
46
47
	@Override
48
	public String toString() {
49 1 1. toString : replaced return value with "" for fr/sii/ogham/testing/assertion/hamcrest/IdenticalHtmlMatcher::toString → NO_COVERAGE
		return "isIdenticalHtml('"+expected+"')";
50
	}
51
}

Mutations

44

1.1
Location : matches
Killed by :
negated conditional → NO_COVERAGE

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

49

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

Active mutators

Tests examined


Report generated by PIT 1.13.1