Skip to content

Commit

Permalink
Change return type for Comparison.Detail.getTarget().
Browse files Browse the repository at this point in the history
 From Object to org.w3c.dom.Node
  • Loading branch information
brabenetz committed Feb 28, 2015
1 parent eb8a6e4 commit 3f824ef
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
12 changes: 7 additions & 5 deletions xmlunit-core/src/main/java/org/xmlunit/diff/Comparison.java
Expand Up @@ -13,6 +13,8 @@
*/
package org.xmlunit.diff;

import org.w3c.dom.Node;

/**
* Details of a single comparison XMLUnit has performed.
*/
Expand All @@ -23,11 +25,11 @@ public class Comparison {
* Node) that took part in the comparison.
*/
public static class Detail {
private final Object target;
private final Node target;
private final String xpath;
private final Object value;

private Detail(Object n, String x, Object v) {
private Detail(Node n, String x, Object v) {
target = n;
xpath = x;
value = v;
Expand All @@ -36,7 +38,7 @@ private Detail(Object n, String x, Object v) {
/**
* The actual target.
*/
public Object getTarget() { return target; }
public Node getTarget() { return target; }
/**
* XPath leading to the target.
*/
Expand All @@ -50,9 +52,9 @@ private Detail(Object n, String x, Object v) {
private final Detail control, test;
private final ComparisonType type;

public Comparison(ComparisonType t, Object controlTarget,
public Comparison(ComparisonType t, Node controlTarget,
String controlXPath, Object controlValue,
Object testTarget, String testXPath, Object testValue) {
Node testTarget, String testXPath, Object testValue) {
type = t;
control = new Detail(controlTarget, controlXPath, controlValue);
test = new Detail(testTarget, testXPath, testValue);
Expand Down
Expand Up @@ -204,12 +204,10 @@ private void appendAttribute(StringBuilder sb, Attr aNode) {

@Override
public String getDetails(Comparison.Detail difference, ComparisonType type, boolean formatXml) {
if (difference.getTarget() instanceof Node) {
return getFullFormattedXml((Node) difference.getTarget(), type, formatXml);
} else if (difference.getTarget() == null) {
if (difference.getTarget() == null) {
return "<NULL>";
}
return difference.getTarget().toString();
return getFullFormattedXml(difference.getTarget(), type, formatXml);
}

private String getFullFormattedXml(final Node node, ComparisonType type, boolean formatXml) {
Expand Down
Expand Up @@ -359,7 +359,7 @@ public IgnoreAttributeDifferenceEvaluator(String attributeName) {

@Override
public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) {
final Node controlNode = (Node) comparison.getControlDetails().getTarget();
final Node controlNode = comparison.getControlDetails().getTarget();
if (controlNode instanceof Attr) {
Attr attr = (Attr) controlNode;
if (attr.getName().equals(attributeName)) {
Expand Down
Expand Up @@ -52,7 +52,6 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
import org.xmlunit.diff.DOMDifferenceEngine;
import org.xmlunit.diff.DefaultNodeMatcher;
import org.xmlunit.diff.DifferenceEvaluator;
import org.xmlunit.diff.DifferenceEvaluators;
import org.xmlunit.diff.ElementSelector;
import org.xmlunit.diff.ElementSelectors;
import org.xmlunit.diff.NodeMatcher;
Expand Down Expand Up @@ -280,13 +279,13 @@ public static Iterable<Difference> toDifference(Comparison comp) {
.valueOf(!ZERO
.equals(cd
.getValue())),
(Node) cd.getTarget(),
cd.getTarget(),
cd.getXPath()),
new NodeDetail(String
.valueOf(!ZERO
.equals(td
.getValue())),
(Node) td.getTarget(),
td.getTarget(),
td.getXPath())));
}
proto = CHILD_NODELIST_LENGTH;
Expand Down Expand Up @@ -316,7 +315,7 @@ public static NodeDetail toNodeDetail(Comparison.Detail detail) {
if (detail.getValue() instanceof Node) {
value = ((Node) detail.getValue()).getNodeName();
}
return new NodeDetail(value, (Node) detail.getTarget(),
return new NodeDetail(value, detail.getTarget(),
detail.getXPath());
}

Expand Down Expand Up @@ -393,9 +392,9 @@ private static boolean swallowComparison(Comparison comparison,
}

private static boolean isNonElementDocumentChild(Comparison.Detail detail) {
return detail != null && detail.getTarget() instanceof Node
return detail != null && detail.getTarget() != null
&& !(detail.getTarget() instanceof Element)
&& ((Node) detail.getTarget()).getParentNode() instanceof Document;
&& detail.getTarget().getParentNode() instanceof Document;
}

public static class ComparisonController2ComparisonController
Expand Down
Expand Up @@ -300,7 +300,7 @@ public IgnoreAttributeDifferenceEvaluator(String attributeName) {

@Override
public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) {
final Node controlNode = (Node) comparison.getControlDetails().getTarget();
final Node controlNode = comparison.getControlDetails().getTarget();
if (controlNode instanceof Attr) {
Attr attr = (Attr) controlNode;
if (attr.getName().equals(attributeName)) {
Expand Down

0 comments on commit 3f824ef

Please sign in to comment.