### Question:
XmlUtils { public static String nullSafeGetStringAttribute(Node node, String attributeName) { if (node != null) { Node namedItem = node.getAttributes().getNamedItem(attributeName); if (namedItem != null) { return namedItem.getNodeValue(); } } return null; } private  XmlUtils(); static String nullSafeGetStringAttribute(Node node, String attributeName);  }### Answer:
@Test public void nullSafeGetStringAttribute() throws XPathExpressionException { Node node = (Node) XPathFactory.newInstance().newXPath().evaluate("/test", doc, XPathConstants.NODE); assertEquals("stringValue", XmlUtils.nullSafeGetStringAttribute(node, "stringAttr")); assertNull(XmlUtils.nullSafeGetStringAttribute(node, "chuckNorris")); Node node2 = (Node) XPathFactory.newInstance().newXPath().evaluate("/chuckNorris", doc, XPathConstants.NODE); assertNull(node2); assertNull(XmlUtils.nullSafeGetStringAttribute(node2, "kick")); }