### Question:
XmlHelper { public static String peekValue(final Document doc, final String xpathExpression) throws XPathExpressionException { final XPath xPath = XPF.newXPath(); final XPathExpression expression = xPath.compile(xpathExpression); final Node node = (Node) expression.evaluate(doc, XPathConstants.NODE); final String result = (node != null) ? node.getTextContent() : null; return result; }  static String peekValue(final Document doc, final String xpathExpression); static String peekValue(final File file, final String xpathExpression); static void pokeValue(final Document doc, final String xpathExpression, final String value); static void pokeValue(final File file, final String xpathExpression, final String value);  }### Answer:
@Test public void peekValue_Document() throws Exception { final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); final DocumentBuilder db = dbf.newDocumentBuilder(); final Document doc = db.newDocument(); final Element root = doc.createElement("build"); final Element queueIdNode = doc.createElement("queueId"); queueIdNode.appendChild(doc.createTextNode("76")); root.appendChild(queueIdNode); final Element timestampNode = doc.createElement("timestamp"); timestampNode.appendChild(doc.createTextNode("84")); root.appendChild(timestampNode); doc.appendChild(root); final String actualFound = XmlHelper.peekValue(doc, "/build/timestamp"); Assert.assertEquals("84", actualFound); final String actualNotFound = XmlHelper.peekValue(doc, "/build/startTime"); Assert.assertEquals(null, actualNotFound); }
@Test public void peekValue_File() throws Exception { final Class<? extends XmlHelperTest> clazz = this.getClass(); final String resourceBase = clazz.getSimpleName() + "/peekValue_File/"; final URL inputUrl = clazz.getResource(resourceBase + "input.xml"); File tmp = null; try { tmp = File.createTempFile("XmlHelperTest", "xml"); FileUtils.copyURLToFile(inputUrl, tmp); final String actual = XmlHelper.peekValue(tmp, "/build/timestamp"); Assert.assertEquals("1436542800239", actual); } finally { FileUtils.deleteQuietly(tmp); } }