Class DefaultNodeMatcher
- java.lang.Object
-
- org.xmlunit.diff.DefaultNodeMatcher
-
- All Implemented Interfaces:
NodeMatcher
public class DefaultNodeMatcher extends Object implements NodeMatcher
Default implemetation ofNodeMatcherthat matches control and tests nodes for comparison with the help ofDefaultNodeMatcher.NodeTypeMatcherandElementSelectors.There is an important difference between using
ElementSelectors.or(org.xmlunit.diff.ElementSelector...)to combine multipleElementSelectors and usingDefaultNodeMatcher's constructor with multipleElementSelectors:Consider
ElementSelectorse1ande2and two control and test nodes each. Assumee1would match the first control node to the second test node and vice versa if used alone, whilee2would match the nodes in order (the first control node to the first test and so on).ElementSelectors.or(org.xmlunit.diff.ElementSelector...)creates a combinedElementSelectorthat 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 runninge2alone.DefaultNodeMatcherwith twoElementSelectors will consult theElementSelectors separately and only invokee2if there are any nodes not matched bye1at all. In this case the result will be the same as runninge1alone.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDefaultNodeMatcher.DefaultNodeTypeMatcherDefaultNodeMatcher.NodeTypeMatcherthat marks pairs of nodes of the same node type as well as pairs of CDATA sections and text nodes as eligible.static interfaceDefaultNodeMatcher.NodeTypeMatcherDetermines whether two Nodes are eligible for comparison based on their node type.
-
Constructor Summary
Constructors Constructor Description DefaultNodeMatcher()Creates a matcher usingElementSelectors.DefaultandDefaultNodeMatcher.DefaultNodeTypeMatcher.DefaultNodeMatcher(DefaultNodeMatcher.NodeTypeMatcher ntm, ElementSelector... es)Creates a matcher using the givenElementSelectors andDefaultNodeMatcher.NodeTypeMatcher.DefaultNodeMatcher(ElementSelector... es)Creates a matcher using the givenElementSelectors andDefaultNodeMatcher.DefaultNodeTypeMatcher.
-
-
-
Constructor Detail
-
DefaultNodeMatcher
public DefaultNodeMatcher()
Creates a matcher usingElementSelectors.DefaultandDefaultNodeMatcher.DefaultNodeTypeMatcher.
-
DefaultNodeMatcher
public DefaultNodeMatcher(ElementSelector... es)
Creates a matcher using the givenElementSelectors andDefaultNodeMatcher.DefaultNodeTypeMatcher.- Parameters:
es- the ElementSelectors to use
-
DefaultNodeMatcher
public DefaultNodeMatcher(DefaultNodeMatcher.NodeTypeMatcher ntm, ElementSelector... es)
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 Detail
-
match
public Iterable<Map.Entry<Node,Node>> match(Iterable<Node> controlNodes, Iterable<Node> testNodes)
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
-
-