You are using ElementSelectors.byNameAndText which means: when looking at lists of elements, compare those which each other that have the same element name and the same nested text. This works fine for elements like <String>S013J6S7STH</String>.
In your second example you want to influence which Map elements XMLUnit compares with each other. The Map elements have no nested text at all, so they all have the same nested text and you compare them in-order. I'm not really sure what identifies the Map elements for you - this is something only you will know, XMLUnit cannot guess that either. As a human I can guess that you consider two Map-elements to be "the same" if they share the same value in their nested entry element that has key attribute with the value display. In that case a byXPath element selector probably is a good choice.
As you need different element selectors for different elements you probably want a conditional builder.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've used below
DiffBuilder
using XMLUnit-2diff = DiffBuilder.compare(control).withTest(test).checkForSimilar() .normalizeWhitespace().ignoreComments() .ignoreWhitespace().ignoreElementContentWhitespace() .withNodeFilter(node -> (filter(node, attrsToIgnore))) .withAttributeFilter(fields -> (filterFields(fields, fieldsToIgnore))) .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)).build();
It works well for shuffling the
List<>
values or random value inList<>
as shown belowBut, When I've
List < Map {} >
it fails.. what can be done to handle both random order ofList<String>
values as well asList < Map {} >
value orders.In above example you can notice I've
List < Map {} >
and my above implementation working well for simpleList<>
but not forList < Map {} >
I want to ignore the order of both, someone please let me know how this can be achieved?
Thanks,
Swapnil.
Last edit: Swapnil Kotwal 2021-02-18
You are using
ElementSelectors.byNameAndText
which means: when looking at lists of elements, compare those which each other that have the same element name and the same nested text. This works fine for elements like<String>S013J6S7STH</String>
.In your second example you want to influence which
Map
elements XMLUnit compares with each other. TheMap
elements have no nested text at all, so they all have the same nested text and you compare them in-order. I'm not really sure what identifies theMap
elements for you - this is something only you will know, XMLUnit cannot guess that either. As a human I can guess that you consider twoMap
-elements to be "the same" if they share the same value in their nestedentry
element that haskey
attribute with the valuedisplay
. In that case abyXPath
element selector probably is a good choice.As you need different element selectors for different elements you probably want a conditional builder.
I'm talking about
Map { }
insideLast edit: Swapnil Kotwal 2021-02-22
so am I