SimpleElementReader implements ElementReader { public String getNodeValue(Element element) { Node child = element.getFirstChild(); if (child == null) { return ""; } String nodeValue = child.getNodeValue(); if (nodeValue != null) { return nodeValue.trim(); } else { return ""; } }  String getAttribute(Element element, String attribute); String getNodeValue(Element element);  }
@Test public void testGetNodeValue() { Element element = mock(Element.class); Node node = mock(Node.class); when(node.getNodeValue()).thenReturn(" B "); when(element.getFirstChild()).thenReturn(node); String result = reader.getNodeValue(element); assertEquals("B", result); }
@Test public void testNodeValueIsNull() { Element element = mock(Element.class); Node node = mock(Node.class); when(node.getNodeValue()).thenReturn(null); when(element.getFirstChild()).thenReturn(node); assertEquals("", reader.getNodeValue(element)); }