### Question:
XmlHelper { protected void applyModifications(Element modificationsRoot, Element targetRoot) { for(Object object : modificationsRoot.elements()){ if(object instanceof Element){ Element modificationElement = (Element) object; String copy = modificationElement.attributeValue("sdk-copy"); if("true".equals(copy)){ addModification(targetRoot, modificationElement); } else { Element targetElement = targetRoot.element(modificationElement.getName()); if(targetElement == null) { targetElement = targetRoot.addElement(modificationElement.getName()); } applyModifications(modificationElement, targetElement); } } } }  void modifyXml(File targetfile, String modificationsPath);  }### Answer:
@Test public void testApplyChanges(){ Element modificationsRoot = new DefaultElement("project"); Element targetRoot = new DefaultElement("project"); Document target = DocumentFactory.getInstance().createDocument(targetRoot); Document modifications = DocumentFactory.getInstance().createDocument(modificationsRoot); Element targetDependencies = target.getRootElement().addElement("dependencies"); Element dependency = modifications.getRootElement() .addElement("dependencies") .addElement("dependency").addAttribute("sdk-copy", "true"); dependency.addElement("groupId").setText("org.openmrs.module"); dependency.addElement("artifactId").setText("metadtamapiing"); dependency.addElement("version").setText("2345"); assertThat(target.getRootElement().element("dependencies").element("dependency"), is(nullValue())); helper.applyModifications(modifications.getRootElement(), target.getRootElement()); assertThat(target.getRootElement().element("dependencies").element("dependency"), is(notNullValue())); assertThat(target.getRootElement().element("dependencies").element("dependency").element("groupId").getText(), is("org.openmrs.module")); }
@Test public void testApplyChanges2(){ Element modificationsRoot = new DefaultElement("project"); Element targetRoot = new DefaultElement("project"); Document target = DocumentFactory.getInstance().createDocument(targetRoot); Document modifications = DocumentFactory.getInstance().createDocument(modificationsRoot); Element dependency = modifications.getRootElement() .addElement("dependencies") .addElement("dependency").addAttribute("sdk-copy", "true"); dependency.addElement("groupId").setText("org.openmrs.module"); dependency.addElement("artifactId").setText("metadtamapiing"); dependency.addElement("version").setText("2345"); assertThat(target.getRootElement().element("dependencies"), is(nullValue())); helper.applyModifications(modifications.getRootElement(), target.getRootElement()); assertThat(target.getRootElement().element("dependencies").element("dependency"), is(notNullValue())); }