i using xmlunit in junit compare results of tests. have problem wherein there element in xml gets current timestamp tests run , when compared expected output, results not match.
to overcome this, read using org.xmlunit.diff.nodefilters, not have examples on how implement this. code snippet have below,
final org.xmlunit.diff.diff documentdiff = diffbuilder .compare(sourcexp) .withtest(sourceactual) .ignorecomments() .ignorewhitespace() //.withnodefilter(node.element_node) .build(); return documentdiff.hasdifferences(); my problem is, how implement nodefilter? parameter should passed , should passed? there no samples on this. nodefilter method gets predicate in parameter. predicate mean?
predicate functional interface single test method - in case of nodefilter receives dom node argument , returns boolean. javadoc of predicate
an implementation of predicate<node> can used filter nodes difference engine , nodes predicate returns true compared. javadoc of setnodefilter, user-guide
assuming element containing timestamp called timestamp you'd use like
.withnodefilter(new predicate<node>() { @override public boolean test(node n) { return !(n instanceof element && "timestamp".equals(nodes.getqname(n).getlocalpart())); } }) or using lambdas
.withnodefilter(n -> !(n instanceof element && "timestamp".equals(nodes.getqname(n).getlocalpart()))) this uses xmlunit's org.xmlunit.util.nodes element name more easily.
Comments
Post a Comment