Class DefaultNodeMatcher
- All Implemented Interfaces:
NodeMatcher
NodeMatcher that matches control
and tests nodes for comparison with the help of DefaultNodeMatcher.NodeTypeMatcher and ElementSelectors.
There is an important difference between using ElementSelectors.or(org.xmlunit.diff.ElementSelector...) to combine multiple ElementSelectors
and using DefaultNodeMatcher's constructor with multiple
ElementSelectors:
Consider ElementSelectors 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 ElementSelectors
will consult the ElementSelectors 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 classDefaultNodeMatcher.NodeTypeMatcherthat marks pairs of nodes of the same node type as well as pairs of CDATA sections and text nodes as eligible.static interfaceDetermines whether two Nodes are eligible for comparison based on their node type. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a matcher usingElementSelectors.DefaultandDefaultNodeMatcher.DefaultNodeTypeMatcher.Creates a matcher using the givenElementSelectors andDefaultNodeMatcher.NodeTypeMatcher.Creates a matcher using the givenElementSelectors andDefaultNodeMatcher.DefaultNodeTypeMatcher. -
Method Summary
-
Constructor Details
-
DefaultNodeMatcher
public DefaultNodeMatcher()Creates a matcher usingElementSelectors.DefaultandDefaultNodeMatcher.DefaultNodeTypeMatcher. -
DefaultNodeMatcher
Creates a matcher using the givenElementSelectors andDefaultNodeMatcher.DefaultNodeTypeMatcher.- Parameters:
es- the ElementSelectors to use
-
DefaultNodeMatcher
Creates a matcher using the givenElementSelectors andDefaultNodeMatcher.NodeTypeMatcher.The
ElementSelectors are consulted in order so that the secondElementSelectoronly gets to match the nodes that the first one couldn't match to any test nodes ate all and so on.- Parameters:
ntm- the NodeTypeMatcher to usees- the ElementSelectors to use
-
-
Method Details
-
match
Description copied from interface:NodeMatcherMatches 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_LOOKUPdifferences}.- Specified by:
matchin interfaceNodeMatcher- Parameters:
controlNodes- the control nodestestNodes- the test nodes- Returns:
- a Map.Entry containing the pair for each matched pair of nodes
-