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

xmlunit / xmlunit / cd160610-9b67-4752-a2c4-e3a0d82d991e

21 Apr 2025 11:55AM UTC coverage: 91.756% (-0.02%) from 91.78%
cd160610-9b67-4752-a2c4-e3a0d82d991e

push

circleci

web-flow
Merge pull request #289 from xmlunit/circleci-project-setup

CircleCI project setup

3996 of 4698 branches covered (85.06%)

11754 of 12810 relevant lines covered (91.76%)

2.35 hits per line

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

95.83
/xmlunit-core/src/main/java/org/xmlunit/diff/Comparison.java
1
/*
2
  This file is licensed to You under the Apache License, Version 2.0
3
  (the "License"); you may not use this file except in compliance with
4
  the License.  You may obtain a copy of the License at
5

6
  http://www.apache.org/licenses/LICENSE-2.0
7

8
  Unless required by applicable law or agreed to in writing, software
9
  distributed under the License is distributed on an "AS IS" BASIS,
10
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
  See the License for the specific language governing permissions and
12
  limitations under the License.
13
*/
14
package org.xmlunit.diff;
15

16
import org.w3c.dom.Node;
17

18
import static org.xmlunit.diff.AbstractDifferenceEngine.getParentXPath;
19
import static org.xmlunit.diff.AbstractDifferenceEngine.getXPath;
20

21
/**
22
 * Details of a single comparison XMLUnit has performed.
23
 */
24
public class Comparison {
25

26
    /**
27
     * The details of a target (usually some representation of an XML
28
     * Node) that took part in the comparison.
29
     */
30
    public static class Detail {
31
        private final Node target;
32
        private final String xpath;
33
        private final Object value;
34
        private final String parentXPath;
35

36
        private Detail(Node n, String x, Object v, String parentX) {
1✔
37
            target = n;
1✔
38
            xpath = x;
1✔
39
            value = v;
1✔
40
            parentXPath = parentX;
1✔
41
        }
1✔
42

43
        /**
44
         * The actual target.
45
         * @return the actual target
46
         */
47
        public Node getTarget() { return target; }
1✔
48
        /**
49
         * XPath leading to the target.
50
         * @return XPath leading to the target
51
         */
52
        public String getXPath() { return xpath; }
1✔
53
        /**
54
         * The value for comparison found at the current target.
55
         * @return the value for comparison found at the current target
56
         */
57
        public Object getValue() { return value; }
1✔
58

59
        /**
60
         * XPath leading to the target's parent.
61
         * @return XPath leading to the target's parent
62
         */
63
        public String getParentXPath() {
64
            return parentXPath;
1✔
65
        }
66
    }
67

68
    private final Detail control, test;
69
    private final ComparisonType type;
70

71
    /**
72
     * Creates a new comparison.
73
     *
74
     * @param t the type of comparison
75
     * @param controlTarget the control node the comparison applies to
76
     * @param controlXPath xpath of the control node the comparison applies to
77
     * @param controlValue value from the control node used during comparison
78
     * @param controlParentXPath xpath of the control node' parent
79
     * @param testTarget the test node the comparison applies to
80
     * @param testXPath xpath of the test node the comparison applies to
81
     * @param testValue value from the test node used during comparison
82
     * @param testParentXPath xpath of the test node' parent
83
     */
84
    public Comparison(ComparisonType t,
85
                      Node controlTarget, String controlXPath, Object controlValue, String controlParentXPath,
86
                      Node testTarget, String testXPath, Object testValue, String testParentXPath) {
1✔
87
        type = t;
1✔
88
        control = new Detail(controlTarget, controlXPath, controlValue, controlParentXPath);
1✔
89
        test = new Detail(testTarget, testXPath, testValue, testParentXPath);
1✔
90
    }
1✔
91

92
    /**
93
     * Creates a new comparison.
94
     *
95
     * @param t the type of comparison
96
     * @param controlContext xpathContext object contains the current and parent XPath
97
     * @param controlTarget the control node the comparison applies to
98
     * @param controlValue value from the control node used during comparison
99
     * @param testContext xpathContext object contains the current and parent XPath
100
     * @param testTarget the test node the comparison applies to
101
     * @param testValue value from the test node used during comparison
102
     * @since XMLUnit 2.10.1
103
     */
104
    public Comparison(ComparisonType t,
105
                      XPathContext controlContext, Node controlTarget, Object controlValue,
106
                      XPathContext testContext, Node testTarget,Object testValue) {
107
        this (t,
1✔
108
              controlTarget, getXPath(controlContext), controlValue, getParentXPath(controlContext),
1✔
109
              testTarget, getXPath(testContext), testValue, getParentXPath(testContext));
1✔
110
    }
1✔
111

112
    /**
113
     * The kind of comparison performed.
114
     * @return the type of comparison
115
     */
116
    public ComparisonType getType() {
117
        return type;
1✔
118
    }
119

120
    /**
121
     * Details of the control target.
122
     * @return details of the control target
123
     */
124
    public Detail getControlDetails() {
125
        return control;
1✔
126
    }
127

128
    /**
129
     * Details of the test target.
130
     * @return details of the test target
131
     */
132
    public Detail getTestDetails() {
133
        return test;
1✔
134
    }
135

136
    /**
137
     * Returns a string representation of this comparison using the
138
     * given {@link ComparisonFormatter}
139
     * @param formatter the ComparisonFormatter to use
140
     * @return a string representation of this comparison
141
     */
142
    public String toString(ComparisonFormatter formatter) {
143
        return formatter.getDescription(this);
1✔
144
    }
145

146
    /**
147
     * Returns a string representation of this comparison using {@link DefaultComparisonFormatter}
148
     * @return a string representation of this comparison
149
     */
150
    @Override
151
    public String toString(){
152
        return toString(new DefaultComparisonFormatter());
×
153
    }
154
}
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