### Question:
XmlMerger implements DocumentProcessor { @Override public void process(Document fragment) { process(fragment.getDocumentElement(), document); } XmlMerger();  XmlMerger(Document source); @Override void process(Document fragment); @Override Document result();  }### Answer:
@Test public void addsMissingElement() { String root = aName(); merger = new XmlMerger(builder.element(root).build()); String name = aName(); merger.process(builder.element(name).build()); assertMerged(); }
@Test public void addsMissingElementAsDocumentElement() { merger = new XmlMerger(); String name = aName(); merger.process(builder.element(name).build()); assertMerged(); }
@Test public void skipsExistingElement() throws Exception { String name = aName(); builder.element(name); merger = new XmlMerger(builder.build()); merger.process(builder.build()); assertMerged(); }
@Test public void addsMissingAttribute() { String root = aName(); builder.element(root); merger = new XmlMerger(builder.build()); String name = aName(); String value = aName(); merger.process(builder.attribute(name, value).build()); assertMerged(); }
@Test public void skipsExistingAttribute() { String root = aName(); String name = aName(); String value = aName(); builder.element(root).attribute(name, value); merger = new XmlMerger(builder.build()); merger.process(builder.build()); assertMerged(); }
@Test public void addsSiblingElement() { String element = aName(); builder.element(element + 's'); merger = new XmlMerger(builder.build()); String attribute = aName(); String value1 = aName(); String value2 = aName(); builder.element(element) .attribute(attribute, value1) .end() .element(element) .attribute(attribute, value2); merger.process(builder.build()); assertMerged(); }