0

I have an issue in the following code.

String xml1="<Akash><status>COMPLETE</status>"
                    +"<startedTime>23</startedTime></Akash>"; 
String xml2="<Akash><status>COMPLETE</status><startedTime></startedTime></Akash>";

Diff diff = new Diff(xml1,xml2);
diff.overrideElementQualifier(new ElementNameAndTextQualifier()); 
assertTrue("XML similar " + diff.toString(), diff.similar());

When I dont' write this following line in my above java code.

 XMLUnit.setIgnoreWhitespace(true) 

Assert gives an exception near "started time" that value of this node is not there, which is what I wanted, because value 23 is not present. But when I add this line (setIgnoreWhitespace) to the code before instantiating Diff class, Despite having same xml, this code passes the assert test.

I am really not getting what the **** is happening here. Please help me.

Note: I need XMLUnit.setIgnoreWhitespace(true) for equating two xmls which have space in between some of their nodes, otherwise code gives some other error.

Geek_Akash
  • 189
  • 1
  • 11

1 Answers1

1
public static void main(String[] args) throws Exception {
    String xml1="<Akash><status>COMPLETE</status>"
        +"<startedTime>23</startedTime></Akash>"; 
    String xml2="<Akash><status>COMPLETE</status><startedTime></startedTime></Akash>";

    XMLUnit.setIgnoreWhitespace(true);
    Diff diff = new Diff(xml1,xml2);
    diff.overrideElementQualifier(new ElementNameAndTextQualifier()); 
    assertTrue("XML similar " + diff.toString(), diff.similar());
}

throws an exception for me (XMLUnit 1.6).

Exception in thread "main" java.lang.AssertionError: XML similar org.custommonkey.xmlunit.Diff
[different] Expected presence of child nodes to be 'true' but was 'false' - comparing <startedTime...> at /Akash[1]/startedTime[1] to <startedTime...> at /Akash[1]/startedTime[1]
Stefan Bodewig
  • 3,260
  • 15
  • 22