I have tried the below example and tried with different methods of DiffBuilder
and CompareMatcher
classes:
import org.junit.jupiter.api.Test;
import org.xmlunit.diff.DefaultNodeMatcher;
import org.xmlunit.diff.ElementSelectors;
import org.xmlunit.matchers.CompareMatcher;
import static org.hamcrest.MatcherAssert.assertThat;
public class XmlDemo4 {
@Test
public void demoMethod() {
String actual = "<struct><int>3</int><boolean>false</boolean></struct>";
String expected = "<struct><boolean>false</boolean><int>4</int></struct>";
assertThat(actual, CompareMatcher.isSimilarTo(expected)
.ignoreWhitespace().normalizeWhitespace().
withNodeMatcher(new
DefaultNodeMatcher(ElementSelectors.byName,ElementSelectors.Default)));
}
}
by running above code I am getting:
java.lang.AssertionError:
Expected: Expected text value '4' but was '3' - comparing <int ...>4</int> at
/struct[1]/int[1]/text()[1] to <int ...>3</int> at /struct[1]/int[1]/text()[1]:
<int>4</int>
but: result was:
<int>3</int>
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8)
at StringXml.XmlDemo4.demoMethod(XmlDemo4.java:29)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
Process finished with exit code -1
here it is comparing content text also, please suggest, is there any way to compare the content text with the data type and it should not compare with the exact content text