### Question:
XMLUtil extends AbstractCaller { @Description("Returns a object by xpath.<br>" + "<b>content</b> - xml document<br>" + "<b>xpath</b> - path to object<br>" + "Example:<br/>" + "#{getObjectByXPath(content, xpath)}") @UtilityMethod public Map<String, ?> getObjectByXPath(String content, String xpath) { NodeList nodes = getNodesByXPath(content, xpath); if (nodes.getLength() == 0) { return Collections.emptyMap(); } if (nodes.getLength() != 1) { throw new EPSCommonException("There are several nodes for this xpath \"" + xpath + "\"."); } if (hasOnlyTextNode(nodes.item(0))) { throw new EPSCommonException("Node isn't object."); } return nodeToMap(nodes.item(0)); }  @Description("Returns a xml document with new value of selected node.<br>" + "<b>content</b> - xml document<br>" + "<b>xpath</b> - path to node<br>" + "<b>value</b> - new value of node<br>" + "Example:<br/>" + "#{setValueByXPath(content, xpath, value)}") @UtilityMethod String setValueByXPath(String content, String xpath, String value); @Description("Returns a value of node by xpath.<br>" + "<b>content</b> - xml document<br>" + "<b>xpath</b> - path to node<br>" + "Example:<br/>" + "#{getObjectByXPath(content, xpath)}") @UtilityMethod String getValueByXPath(String content, String xpath); @Description("Returns a object by xpath.<br>" + "<b>content</b> - xml document<br>" + "<b>xpath</b> - path to object<br>" + "Example:<br/>" + "#{getObjectByXPath(content, xpath)}") @UtilityMethod Map<String, ?> getObjectByXPath(String content, String xpath); @Description("Returns a list values by xpath.<br>" + "<b>content</b> - xml document<br>" + "<b>xpath</b> - path to list<br>" + "Example:<br/>" + "#{getListByXPath(content, xpath)}") @UtilityMethod List<String> getListByXPath(String content, String xpath);  }### Answer:
@Test public void testGetObjectByXPath() { Map<String, ?> object = xmlUtil.getObjectByXPath(XML_EXAMPLE, "A"); Map<String, Object> aObject = new HashMap<>(); aObject.put("B", Arrays.asList("value1", "value2")); Map<String, Object> cObject = new HashMap<>(); cObject.put("D", "Test!"); aObject.put("C", cObject); Assert.assertEquals(aObject, object); }
@Test(expected = EPSCommonException.class) public void testGetObjectByXPathException() { Map<String, ?> object = xmlUtil.getObjectByXPath(XML_EXAMPLE, "A/C/D"); }