Description
Currently, in XFormBuilder there is a function setNodeValue(Element, String) that takes a node and a value. If a null node is passed in along a non-null value, calling getTextValue results in unexpected behavior. SetNodeValue should not only check if the String value is null, but also if the element passed in is null (in case a user calls a method later that requires a non-null node). I have written two tests, one that shows normal behavior, and one that throws an exception for a NullPointer:
@Test public void shouldSuccessfullyGetTextValueFromNonNullNode() throws Exception{ Element elm = new Element(); XformBuilder.setNodeValue(elm, "1"); String val = XformBuilder.getTextValue(elm); Assert.assertEquals("1", val); } @Test public void shouldThrowNullPointerExceptionIfGettingTextFromNullNode() throws Exception { boolean thrown = false; try { Element elm = null; XformBuilder.setNodeValue(elm, "1"); String val = XformBuilder.getTextValue(elm); } catch (NullPointerException e) { thrown = true; } Assert.assertTrue(thrown); }