Class DefaultNodeMatcher
- All Implemented Interfaces:
NodeMatcher
NodeMatcher
that matches control
and tests nodes for comparison with the help of DefaultNodeMatcher.NodeTypeMatcher
and ElementSelector
s.
There is an important difference between using ElementSelectors.or(org.xmlunit.diff.ElementSelector...)
to combine multiple ElementSelector
s
and using DefaultNodeMatcher
's constructor with multiple
ElementSelector
s:
Consider ElementSelector
s e1
and e2
and
two control and test nodes each. Assume e1
would match the
first control node to the second test node and vice versa if used
alone, while e2
would match the nodes in order (the first
control node to the first test and so on).
ElementSelectors.or(org.xmlunit.diff.ElementSelector...)
creates a combined ElementSelector
that is willing to match the first control node to
both of the test nodes - and the same for the second control node.
Since nodes are compared in order when possible the result will be
the same as running e2
alone.
DefaultNodeMatcher
with two ElementSelector
s
will consult the ElementSelector
s separately and only
invoke e2
if there are any nodes not matched by e1
at all. In this case the result will be the same as running
e1
alone.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
DefaultNodeMatcher.NodeTypeMatcher
that marks pairs of nodes of the same node type as well as pairs of CDATA sections and text nodes as eligible.private static class
static interface
Determines whether two Nodes are eligible for comparison based on their node type. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final short
private final ElementSelector[]
private final DefaultNodeMatcher.NodeTypeMatcher
private static final short
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a matcher usingElementSelectors.Default
andDefaultNodeMatcher.DefaultNodeTypeMatcher
.Creates a matcher using the givenElementSelector
s andDefaultNodeMatcher.NodeTypeMatcher
.Creates a matcher using the givenElementSelector
s andDefaultNodeMatcher.DefaultNodeTypeMatcher
. -
Method Summary
Modifier and TypeMethodDescriptionprivate DefaultNodeMatcher.Match
findMatchingNode
(Node searchFor, List<Node> searchIn, int indexOfLastMatch, Set<Integer> availableIndexes, ElementSelector e) Matches control and test nodes against each other, returns the matching pairs.private boolean
nodesMatch
(Node n1, Node n2, ElementSelector elementSelector) private DefaultNodeMatcher.Match
searchIn
(Node searchFor, List<Node> searchIn, Set<Integer> availableIndexes, int fromInclusive, int toExclusive, ElementSelector e)
-
Field Details
-
TEXT
private static final short TEXT- See Also:
-
CDATA
private static final short CDATA- See Also:
-
elementSelectors
-
nodeTypeMatcher
-
-
Constructor Details
-
DefaultNodeMatcher
public DefaultNodeMatcher()Creates a matcher usingElementSelectors.Default
andDefaultNodeMatcher.DefaultNodeTypeMatcher
. -
DefaultNodeMatcher
Creates a matcher using the givenElementSelector
s andDefaultNodeMatcher.DefaultNodeTypeMatcher
. -
DefaultNodeMatcher
Creates a matcher using the givenElementSelector
s andDefaultNodeMatcher.NodeTypeMatcher
.The
ElementSelector
s are consulted in order so that the secondElementSelector
only gets to match the nodes that the first one couldn't match to any test nodes ate all and so on.
-
-
Method Details
-
match
Description copied from interface:NodeMatcher
Matches control and test nodes against each other, returns the matching pairs.Nodes passed in as attributes but not returned as member of any pair will cause
ComparisonType.CHILD_LOOKUP
differences}.- Specified by:
match
in interfaceNodeMatcher
-
findMatchingNode
private DefaultNodeMatcher.Match findMatchingNode(Node searchFor, List<Node> searchIn, int indexOfLastMatch, Set<Integer> availableIndexes, ElementSelector e) -
searchIn
private DefaultNodeMatcher.Match searchIn(Node searchFor, List<Node> searchIn, Set<Integer> availableIndexes, int fromInclusive, int toExclusive, ElementSelector e) -
nodesMatch
-