@Test public void compareCharacterData() { DOMDifferenceEngine d = new DOMDifferenceEngine(); DiffExpecter ex = new DiffExpecter(ComparisonType.TEXT_VALUE, 9); d.addDifferenceListener(ex); d.setDifferenceEvaluator(new DifferenceEvaluator() { public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) { if (comparison.getType() == ComparisonType.NODE_TYPE) { if (outcome == ComparisonResult.EQUAL || ( comparison.getControlDetails() .getTarget() instanceof CharacterData && comparison.getTestDetails() .getTarget() instanceof CharacterData )) { return ComparisonResult.EQUAL; } } return outcome; } }); d.setComparisonController(ComparisonControllers.StopWhenDifferent); Comment fooComment = doc.createComment("foo"); Comment barComment = doc.createComment("bar"); Text fooText = doc.createTextNode("foo"); Text barText = doc.createTextNode("bar"); CDATASection fooCDATASection = doc.createCDATASection("foo"); CDATASection barCDATASection = doc.createCDATASection("bar"); assertEquals(wrap(ComparisonResult.EQUAL), d.compareNodes(fooComment, new XPathContext(), fooComment, new XPathContext())); assertEquals(wrapAndStop(ComparisonResult.DIFFERENT), d.compareNodes(fooComment, new XPathContext(), barComment, new XPathContext())); assertEquals(wrap(ComparisonResult.EQUAL), d.compareNodes(fooText, new XPathContext(), fooText, new XPathContext())); assertEquals(wrapAndStop(ComparisonResult.DIFFERENT), d.compareNodes(fooText, new XPathContext(), barText, new XPathContext())); assertEquals(wrap(ComparisonResult.EQUAL), d.compareNodes(fooCDATASection, new XPathContext(), fooCDATASection, new XPathContext())); assertEquals(wrapAndStop(ComparisonResult.DIFFERENT), d.compareNodes(fooCDATASection, new XPathContext(), barCDATASection, new XPathContext())); assertEquals(wrap(ComparisonResult.EQUAL), d.compareNodes(fooComment, new XPathContext(), fooText, new XPathContext())); assertEquals(wrapAndStop(ComparisonResult.DIFFERENT), d.compareNodes(fooComment, new XPathContext(), barText, new XPathContext())); assertEquals(wrap(ComparisonResult.EQUAL), d.compareNodes(fooComment, new XPathContext(), fooCDATASection, new XPathContext())); assertEquals(wrapAndStop(ComparisonResult.DIFFERENT), d.compareNodes(fooComment, new XPathContext(), barCDATASection, new XPathContext())); assertEquals(wrap(ComparisonResult.EQUAL), d.compareNodes(fooText, new XPathContext(), fooComment, new XPathContext())); assertEquals(wrapAndStop(ComparisonResult.DIFFERENT), d.compareNodes(fooText, new XPathContext(), barComment, new XPathContext())); assertEquals(wrap(ComparisonResult.EQUAL), d.compareNodes(fooText, new XPathContext(), fooCDATASection, new XPathContext())); assertEquals(wrapAndStop(ComparisonResult.DIFFERENT), d.compareNodes(fooText, new XPathContext(), barCDATASection, new XPathContext())); assertEquals(wrap(ComparisonResult.EQUAL), d.compareNodes(fooCDATASection, new XPathContext(), fooText, new XPathContext())); assertEquals(wrapAndStop(ComparisonResult.DIFFERENT), d.compareNodes(fooCDATASection, new XPathContext(), barText, new XPathContext())); assertEquals(wrap(ComparisonResult.EQUAL), d.compareNodes(fooCDATASection, new XPathContext(), fooComment, new XPathContext())); assertEquals(wrapAndStop(ComparisonResult.DIFFERENT), d.compareNodes(fooCDATASection, new XPathContext(), barComment, new XPathContext())); assertEquals(9, ex.invoked); }
private ComparisonState compareCharacterData(CharacterData control, XPathContext controlContext, CharacterData test, XPathContext testContext) { return compare(new Comparison(ComparisonType.TEXT_VALUE, control, getXPath(controlContext), control.getData(), getParentXPath(controlContext), test, getXPath(testContext), test.getData(), getParentXPath(testContext))); }
DOMDifferenceEngine extends AbstractDifferenceEngine { private ComparisonState compareCharacterData(CharacterData control, XPathContext controlContext, CharacterData test, XPathContext testContext) { return compare(new Comparison(ComparisonType.TEXT_VALUE, control, getXPath(controlContext), control.getData(), getParentXPath(controlContext), test, getXPath(testContext), test.getData(), getParentXPath(testContext))); } }
DOMDifferenceEngine extends AbstractDifferenceEngine { private ComparisonState compareCharacterData(CharacterData control, XPathContext controlContext, CharacterData test, XPathContext testContext) { return compare(new Comparison(ComparisonType.TEXT_VALUE, control, getXPath(controlContext), control.getData(), getParentXPath(controlContext), test, getXPath(testContext), test.getData(), getParentXPath(testContext))); } DOMDifferenceEngine();  DOMDifferenceEngine(final DocumentBuilderFactory f); }
DOMDifferenceEngine extends AbstractDifferenceEngine { private ComparisonState compareCharacterData(CharacterData control, XPathContext controlContext, CharacterData test, XPathContext testContext) { return compare(new Comparison(ComparisonType.TEXT_VALUE, control, getXPath(controlContext), control.getData(), getParentXPath(controlContext), test, getXPath(testContext), test.getData(), getParentXPath(testContext))); } DOMDifferenceEngine();  DOMDifferenceEngine(final DocumentBuilderFactory f); void setDocumentBuilderFactory(DocumentBuilderFactory f); @Override void compare(Source control, Source test); }
DOMDifferenceEngine extends AbstractDifferenceEngine { private ComparisonState compareCharacterData(CharacterData control, XPathContext controlContext, CharacterData test, XPathContext testContext) { return compare(new Comparison(ComparisonType.TEXT_VALUE, control, getXPath(controlContext), control.getData(), getParentXPath(controlContext), test, getXPath(testContext), test.getData(), getParentXPath(testContext))); } DOMDifferenceEngine();  DOMDifferenceEngine(final DocumentBuilderFactory f); void setDocumentBuilderFactory(DocumentBuilderFactory f); @Override void compare(Source control, Source test);  }