java - What is the idiomatic way for printing all the differences in XMLUnit? -
i'm trying override default xmlunit behavior of reporting first difference found between 2 inputs (text) report includes differences found.
i've far accomplished this:
private static void reportxhtmldifferences(string expected, string actual) { diff ds = diffbuilder.compare(input.fromstring(expected)) .withtest(input.fromstring(actual)) .checkforsimilar() .normalizewhitespace() .ignorecomments() .withdocumentbuilderfactory(dbf).build(); defaultcomparisonformatter formatter = new defaultcomparisonformatter(); if (ds.hasdifferences()) { stringbuffer expectedbuffer = new stringbuffer(); stringbuffer actualbuffer = new stringbuffer(); (difference d: ds.getdifferences()) { expectedbuffer.append(formatter.getdetails(d.getcomparison().getcontroldetails(), null, true)); expectedbuffer.append("\n----------\n"); actualbuffer.append(formatter.getdetails(d.getcomparison().gettestdetails(), null, true)); actualbuffer.append("\n----------\n"); } throw new comparisonfailure("there html differences", expectedbuffer.tostring(), actualbuffer.tostring()); } }
but don't like:
- having iterate through
differences
in client code. - reaching internals of
defaultcomparisonformatter
, callinggetdetails
null
comparisontype. - concating differences line dashes.
maybe coming unjustified bad gut feeling, i'd know if has input on use case.
Comments
Post a Comment