HtmlUtils.java

1
package fr.sii.ogham.testing.assertion.util;
2
3
import java.io.IOException;
4
5
import javax.xml.parsers.ParserConfigurationException;
6
7
import org.custommonkey.xmlunit.DetailedDiff;
8
import org.custommonkey.xmlunit.HTMLDocumentBuilder;
9
import org.custommonkey.xmlunit.TolerantSaxDocumentBuilder;
10
import org.custommonkey.xmlunit.XMLUnit;
11
import org.custommonkey.xmlunit.exceptions.ConfigurationException;
12
import org.w3c.dom.Document;
13
import org.xml.sax.SAXException;
14
15
import fr.sii.ogham.testing.assertion.exception.ComparisonException;
16
17
public final class HtmlUtils {
18
	/**
19
	 * Compare two HTML documents. The HTML strings are parsed into
20
	 * {@link Document}s. The HTML are compared by elements and attributes, not
21
	 * using directly using string.
22
	 * 
23
	 * <p>
24
	 * A {@link DetailedDiff} is provided to know if the documents are
25
	 * "identical" or "similar":
26
	 * <ul>
27
	 * <li>Two documents are considered to be "identical" if they contain the
28
	 * same elements and attributes in the same order.</li>
29
	 * <li>Two documents are considered to be "similar" if they contain the same
30
	 * elements and attributes regardless of order.</li>
31
	 * </ul>
32
	 * 
33
	 * 
34
	 * @param expected
35
	 *            the expected HTML
36
	 * @param actual
37
	 *            the HTML content to check
38
	 * @return a report that let you know differences between the two HTML
39
	 *         strings
40
	 */
41
	public static DetailedDiff compare(String expected, String actual) {
42 5 1. compare : negated conditional → NO_COVERAGE
2. compare : negated conditional → TIMED_OUT
3. compare : negated conditional → KILLED
4. compare : negated conditional → KILLED
5. compare : negated conditional → KILLED
		if (expected == null) {
43
			throw new IllegalArgumentException("expected html can't be null");
44
		}
45
		try {
46
			HTMLDocumentBuilder builder = new HTMLDocumentBuilder(new TolerantSaxDocumentBuilder(XMLUnit.newTestParser()));
47
			Document expectedDoc = builder.parse(expected);
48 5 1. compare : negated conditional → NO_COVERAGE
2. compare : negated conditional → TIMED_OUT
3. compare : negated conditional → KILLED
4. compare : negated conditional → KILLED
5. compare : negated conditional → KILLED
			Document actualDoc = builder.parse(actual==null ? "" : actual);
49 5 1. compare : replaced return value with null for fr/sii/ogham/testing/assertion/util/HtmlUtils::compare → NO_COVERAGE
2. compare : replaced return value with null for fr/sii/ogham/testing/assertion/util/HtmlUtils::compare → TIMED_OUT
3. compare : replaced return value with null for fr/sii/ogham/testing/assertion/util/HtmlUtils::compare → KILLED
4. compare : replaced return value with null for fr/sii/ogham/testing/assertion/util/HtmlUtils::compare → KILLED
5. compare : replaced return value with null for fr/sii/ogham/testing/assertion/util/HtmlUtils::compare → KILLED
			return new DetailedDiff(XMLUnit.compareXML(expectedDoc, actualDoc));
50
		} catch (SAXException | IOException | ConfigurationException | ParserConfigurationException e) {
51
			throw new ComparisonException("Failed to compare HTML", e);
52
		}
53
	}
54
	
55
	private HtmlUtils() {
56
		super();
57
	}
58
}

Mutations

42

1.1
Location : compare
Killed by : oghamall.it.html.translator.JsoupInlineCssTranslatorTest.externalStyles(oghamall.it.html.translator.JsoupInlineCssTranslatorTest)
negated conditional → KILLED

2.2
Location : compare
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : compare
Killed by : oghamcore.ut.html.inliner.impl.JsoupCssInlinerTest.noStyles(oghamcore.ut.html.inliner.impl.JsoupCssInlinerTest)
negated conditional → KILLED

4.4
Location : compare
Killed by : none
negated conditional → TIMED_OUT

5.5
Location : compare
Killed by : oghamtesting.ut.assertion.html.AssertIdenticalSpec
negated conditional → KILLED

48

1.1
Location : compare
Killed by : oghamcore.ut.html.inliner.impl.JsoupCssInlinerTest.noStyles(oghamcore.ut.html.inliner.impl.JsoupCssInlinerTest)
negated conditional → KILLED

2.2
Location : compare
Killed by : none
negated conditional → TIMED_OUT

3.3
Location : compare
Killed by : none
negated conditional → NO_COVERAGE

4.4
Location : compare
Killed by : oghamall.it.html.translator.JsoupInlineCssTranslatorTest.externalStyles(oghamall.it.html.translator.JsoupInlineCssTranslatorTest)
negated conditional → KILLED

5.5
Location : compare
Killed by : oghamtesting.ut.assertion.html.AssertIdenticalSpec
negated conditional → KILLED

49

1.1
Location : compare
Killed by : oghamtesting.ut.assertion.html.AssertIdenticalSpec
replaced return value with null for fr/sii/ogham/testing/assertion/util/HtmlUtils::compare → KILLED

2.2
Location : compare
Killed by : oghamcore.ut.html.inliner.impl.JsoupCssInlinerTest.noStyles(oghamcore.ut.html.inliner.impl.JsoupCssInlinerTest)
replaced return value with null for fr/sii/ogham/testing/assertion/util/HtmlUtils::compare → KILLED

3.3
Location : compare
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/util/HtmlUtils::compare → TIMED_OUT

4.4
Location : compare
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/util/HtmlUtils::compare → NO_COVERAGE

5.5
Location : compare
Killed by : oghamall.it.html.translator.JsoupInlineCssTranslatorTest.externalStyles(oghamall.it.html.translator.JsoupInlineCssTranslatorTest)
replaced return value with null for fr/sii/ogham/testing/assertion/util/HtmlUtils::compare → KILLED

Active mutators

Tests examined


Report generated by PIT OGHAM