### Question:
XmlHelper { public static void pokeValue(final Document doc, final String xpathExpression, final String value) throws XPathExpressionException { final XPath xPath = XPF.newXPath(); final XPathExpression expression = xPath.compile(xpathExpression); final Node node = (Node) expression.evaluate(doc, XPathConstants.NODE); node.setTextContent(value); }  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 pokeValue_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); XmlHelper.pokeValue(doc, "/build/timestamp", "42"); final XPathFactory xpf = XPathFactory.newInstance(); final XPath xp = xpf.newXPath(); final XPathExpression expression = xp.compile("/build/timestamp"); final Node node = (Node) expression.evaluate(doc, XPathConstants.NODE); Assert.assertEquals("42", node.getTextContent()); }
@Test public void pokeValue_File() throws Exception { final Class<? extends XmlHelperTest> clazz = this.getClass(); final String resourceBase = clazz.getSimpleName() + "/pokeValue_File/"; final URL inputUrl = clazz.getResource(resourceBase + "input.xml"); File tmp = null; BufferedReader expectedReader = null, actualReader = null; try { tmp = File.createTempFile("XmlHelperTest", "xml"); FileUtils.copyURLToFile(inputUrl, tmp); XmlHelper.pokeValue(tmp, "/build/timestamp", "42"); final URL expectedUrl = clazz.getResource(resourceBase + "expected.xml"); expectedReader = new BufferedReader(new InputStreamReader(expectedUrl.openStream())); actualReader = new BufferedReader(new FileReader(tmp)); assertReaders(expectedReader, actualReader); } finally { FileUtils.deleteQuietly(tmp); IOUtils.closeQuietly(expectedReader); IOUtils.closeQuietly(actualReader); } }