XMLUtils { public static boolean nullSafeGetBooleanAttribute(Node node, String attributeName) { return nullSafeGetBooleanAttribute(node, attributeName, false); } private  XMLUtils(); static String nullSafeGetStringAttribute(Node node, String attributeName); static boolean nullSafeGetBooleanAttribute(Node node, String attributeName); static boolean nullSafeGetBooleanAttribute(Node node, String attributeName, boolean defaultValue);  }
@Test public void nullSafeGetBooleanAttribute() throws XPathExpressionException { Node node = (Node) XPathFactory.newInstance().newXPath().evaluate("/test", doc, XPathConstants.NODE); assertTrue(XMLUtils.nullSafeGetBooleanAttribute(node, "boolVal")); assertFalse(XMLUtils.nullSafeGetBooleanAttribute(node, "chuckNorris")); }
@Test public void nullSafeGetBooleanAttributeWithDefault() throws XPathExpressionException { Node node = (Node) XPathFactory.newInstance().newXPath().evaluate("/test", doc, XPathConstants.NODE); assertTrue(XMLUtils.nullSafeGetBooleanAttribute(node, "chuckNorris", true)); }