XPathHandler { public String run(String xpath, Object document) { try { final Document doc = transformToDocument(document); return XPathFactory.newInstance().newXPath().evaluate(xpath, doc); } catch (Exception e) { throw new RuntimeException(e); } }  String run(String xpath, Object document); String extractXml(String xpath, Object document);  }
@Test public void testRun_1() throws Exception { XPathHandler xPathHandler = new XPathHandler(); String document = "<package>\n" + " <class name=\"Director\">\n" + " <field name=\"test1\"/>\n" + " </class>\n" + "</package>\n"; String result = xPathHandler.run(" assertEquals("Director", result); }
@Test public void testRun_2() throws Exception { XPathHandler xPathHandler = new XPathHandler(); String document = "<package>\n" + " <class name=\"Director\">\n" + " <field name=\"test1\">Headquaters</field>\n" + " </class>\n" + "</package>"; String result = xPathHandler.run(" assertEquals("Headquaters", result); }
@Test public void testRun_3() throws Exception { XPathHandler xPathHandler = new XPathHandler(); String document = "<package>\n" + " <class name=\"Director\">\n" + " <field name=\"test1\">Headquaters</field>\n" + " </class>\n" + "</package>"; String result = xPathHandler.run(" assertEquals("test1", result); }