SimilarHtmlMatcher.java

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

Mutations

43

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

2.2
Location : matches
Killed by :
negated conditional → NO_COVERAGE

48

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

Active mutators

Tests examined


Report generated by PIT 1.13.1