• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

xmlunit / xmlunit / 3f7651ec-f6b5-44df-b60a-ba2dbc5d7339

21 Jun 2025 01:18PM CUT coverage: 91.769%. Remained the same
3f7651ec-f6b5-44df-b60a-ba2dbc5d7339

push

circleci

web-flow
Merge pull request #305 from xmlunit/extend-compat-test-range

add additional compatibility tests

4014 of 4722 branches covered (85.01%)

11774 of 12830 relevant lines covered (91.77%)

2.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

14.29
/xmlunit-legacy/src/main/java/org/custommonkey/xmlunit/ElementNameAndTextQualifier.java
1
/*
2
******************************************************************
3
Copyright (c) 2001,2015,2022 Jeff Martin, Tim Bacon
4
All rights reserved.
5

6
Redistribution and use in source and binary forms, with or without
7
modification, are permitted provided that the following conditions
8
are met:
9

10
        * Redistributions of source code must retain the above copyright
11
          notice, this list of conditions and the following disclaimer.
12
        * Redistributions in binary form must reproduce the above
13
          copyright notice, this list of conditions and the following
14
          disclaimer in the documentation and/or other materials provided
15
          with the distribution.
16
        * Neither the name of the XMLUnit nor the names
17
          of its contributors may be used to endorse or promote products
18
          derived from this software without specific prior written
19
          permission.
20

21
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
POSSIBILITY OF SUCH DAMAGE.
33

34
******************************************************************
35
*/
36

37
package org.custommonkey.xmlunit;
38

39
import org.xmlunit.diff.ElementSelectors;
40
import org.w3c.dom.Element;
41
import org.w3c.dom.Node;
42
import org.w3c.dom.NodeList;
43
import org.w3c.dom.Text;
44

45
/**
46
 * More complex interface implementation that tests two elements for tag name
47
 * and text content comparability.
48
 * @see DifferenceEngine#compareNodeList(java.util.List, java.util.List, int, DifferenceListener, ElementQualifier)
49
 * @see Diff#overrideElementQualifier(ElementQualifier)
50
 */
51
public class ElementNameAndTextQualifier extends ElementNameQualifier {
1✔
52
    /**
53
     * Determine whether two elements qualify for further Difference comparison.
54
     * @return true if the two elements qualify for further comparison based on
55
     * both the superclass qualification (namespace URI and non- namespaced tag
56
     * name), and the qualification of the text nodes contained within the
57
     * elements; false otherwise
58
     */
59
    @Override
60
    public boolean qualifyForComparison(Element control, Element test) {
61
        return ElementSelectors.byNameAndText.canBeCompared(control, test);
1✔
62
    }
63

64
    /**
65
     * Determine whether the text nodes contain similar values
66
     * @param control control text
67
     * @param test test text
68
     * @return true if text nodes are similar, false otherwise
69
     */
70
    protected boolean similar(Text control, Text test) {
71
        if (control == null) {
×
72
            return test == null;
×
73
        } else if (test == null) {
×
74
            return false;
×
75
        }
76
        return control.getNodeValue().equals(test.getNodeValue());
×
77
    }
78

79
    /**
80
     * Extract the normalized text from within an element
81
     * @param fromElement element to extract text from
82
     * @return extracted Text node (could be null)
83
     */
84
    protected Text extractText(Element fromElement) {
85
        fromElement.normalize();
×
86
        NodeList fromNodeList = fromElement.getChildNodes();
×
87
        Node currentNode;
88
        for (int i=0; i < fromNodeList.getLength(); ++i) {
×
89
            currentNode = fromNodeList.item(i);
×
90
            if (currentNode.getNodeType() == Node.TEXT_NODE) {
×
91
                return (Text) currentNode;
×
92
            }
93
        }
94
        return null;
×
95
    }
96

97
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc