1 | package fr.sii.ogham.testing.assertion.wiremock; | |
2 | ||
3 | import org.custommonkey.xmlunit.DetailedDiff; | |
4 | import org.w3c.dom.Document; | |
5 | ||
6 | import com.fasterxml.jackson.annotation.JsonProperty; | |
7 | import com.github.tomakehurst.wiremock.client.WireMock; | |
8 | import com.github.tomakehurst.wiremock.matching.MatchResult; | |
9 | import com.github.tomakehurst.wiremock.matching.StringValuePattern; | |
10 | ||
11 | import fr.sii.ogham.testing.assertion.util.HtmlUtils; | |
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 | * See {@link HtmlUtils} for more information about "similar" HTML. | |
20 | * | |
21 | * <p> | |
22 | * NOTE: {@link WireMock#equalToXml(String)} does an identical check. | |
23 | * | |
24 | * @author Aurélien Baudet | |
25 | * | |
26 | */ | |
27 | public class SimilarHtmlPattern extends StringValuePattern { | |
28 | /** | |
29 | * Initialized with the expected HTML | |
30 | * | |
31 | * @param expectedValue | |
32 | * the expected HTML | |
33 | */ | |
34 | public SimilarHtmlPattern(@JsonProperty("similarHtml") String expectedValue) { | |
35 | super(expectedValue); | |
36 | } | |
37 | ||
38 | @Override | |
39 | public MatchResult match(String value) { | |
40 | DetailedDiff diff = HtmlUtils.compare(expectedValue, value); | |
41 |
1
1. match : replaced return value with null for fr/sii/ogham/testing/assertion/wiremock/SimilarHtmlPattern::match → NO_COVERAGE |
return new MatchResult() { |
42 | ||
43 | @Override | |
44 | public boolean isExactMatch() { | |
45 |
2
1. isExactMatch : replaced boolean return with false for fr/sii/ogham/testing/assertion/wiremock/SimilarHtmlPattern$1::isExactMatch → NO_COVERAGE 2. isExactMatch : replaced boolean return with true for fr/sii/ogham/testing/assertion/wiremock/SimilarHtmlPattern$1::isExactMatch → NO_COVERAGE |
return diff.similar(); |
46 | } | |
47 | ||
48 | @Override | |
49 | public double getDistance() { | |
50 |
1
1. getDistance : replaced double return with 0.0d for fr/sii/ogham/testing/assertion/wiremock/SimilarHtmlPattern$1::getDistance → NO_COVERAGE |
return diff.getAllDifferences().size(); |
51 | } | |
52 | }; | |
53 | } | |
54 | } | |
Mutations | ||
41 |
1.1 |
|
45 |
1.1 2.2 |
|
50 |
1.1 |