### Question:
IdSplitIterator extends AbstractIterator<String> { public String getSubtreeId() { return subtreeId; } IdSplitIterator(String s); String getSubtreeId();  }### Answer:
@Test public void testEmptyString() throws Exception { IdSplitIterator iterator = new IdSplitIterator(""); assertFalse(iterator.hasNext()); try { iterator.next(); fail(); } catch (NoSuchElementException e) { } assertNull(iterator.getSubtreeId()); }
@Test public void testSimpleString() throws Exception { IdSplitIterator iterator = new IdSplitIterator("id"); assertTrue(iterator.hasNext()); assertEquals("id", iterator.next()); assertNull(iterator.getSubtreeId()); assertFalse(iterator.hasNext()); try { iterator.next(); fail(); } catch (NoSuchElementException e) { } assertNull(iterator.getSubtreeId()); }
@Test public void testTwoSegmentsString() throws Exception { IdSplitIterator iterator = new IdSplitIterator("form:table"); assertTrue(iterator.hasNext()); assertEquals("table", iterator.next()); assertEquals("form", iterator.getSubtreeId()); assertTrue(iterator.hasNext()); assertEquals("form", iterator.next()); assertNull(iterator.getSubtreeId()); assertFalse(iterator.hasNext()); }
@Test public void testThreeSegmentsString() throws Exception { IdSplitIterator iterator = new IdSplitIterator("form:table:cell"); assertTrue(iterator.hasNext()); assertEquals("cell", iterator.next()); assertEquals("form:table", iterator.getSubtreeId()); assertTrue(iterator.hasNext()); assertEquals("table", iterator.next()); assertEquals("form", iterator.getSubtreeId()); assertTrue(iterator.hasNext()); assertEquals("form", iterator.next()); assertNull(iterator.getSubtreeId()); assertFalse(iterator.hasNext()); }
@Test public void testBadStrings() throws Exception { IdSplitIterator iterator; iterator = new IdSplitIterator(":"); assertFalse(iterator.hasNext()); iterator = new IdSplitIterator("test:"); assertFalse(iterator.hasNext()); iterator = new IdSplitIterator(":test"); assertTrue(iterator.hasNext()); assertEquals("test", iterator.next()); assertEquals("", iterator.getSubtreeId()); assertFalse(iterator.hasNext()); iterator = new IdSplitIterator("::"); assertFalse(iterator.hasNext()); }