NodeIterator { public String getText() throws ConstraintViolationException { if (next == null) { throw new ConstraintViolationException( "Expected text node, but found no further node"); } if (!(next instanceof Text)) { String msg = MessageFormat .format( "Expected text content, but found a node of type ''{0}'' by name ''{1}''", next.getClass().getName(), next.getLocalName()); throw new ConstraintViolationException(msg); } String ret = ((Text) next).getTextContent(); advance(); return ret; } NodeIterator(List<? extends Node> nodes, boolean ignoreWhitespaceText); boolean hasNext(); boolean nextIsText(); boolean nextIsElement(); boolean nextIsXliffElement(); boolean nextIsXliffElement(String localName); boolean nextIsNonXliffElement(); String getText(); Element getElement(); Element getXliffElement(); Element getNonXliffElement(); Element getXliffElement(String localName); void assertNoMoreNodes(); Element getXliffElement(String... localNames);  }
@Test public void testGetText() { ArrayList<Node> nodes = new ArrayList<Node>(); Document doc = Utils.createDocument(); nodes.add(doc.createTextNode("abc")); nodes.add(doc.createElementNS("ns", "abc")); NodeIterator ni = new NodeIterator(nodes, false); try { String text = ni.getText(); assertEquals("abc", text); } catch (ConstraintViolationException e) { fail("Did not expect ConstraintViolationException"); } try { ni.getText(); fail("Expected ConstraintViolationException"); } catch (ConstraintViolationException e) { } try { ni.getElement(); } catch (ConstraintViolationException e) { fail("Did not expect ConstraintViolationException"); } try { ni.getText(); fail("Expected ConstraintViolationException"); } catch (ConstraintViolationException e) { } }