SqlScript implements Iterable<String> { @Override public Iterator<String> iterator() { return new SqlScriptIterator(script); } SqlScript(final String script); @Override Iterator<String> iterator(); @Override Spliterator<String> spliterator();  }
@SuppressWarnings("unchecked") @Test public void testRemovalOfCommentsProperSplittingOfStatementsAndTrimmingOfEachOfIt() { final SqlScript script = new SqlScript(TEST_SCRIPT); final List<String> list = IteratorUtils.toList(script.iterator()); assertThat(list.size(), equalTo(12)); assertThat(list, everyItem(not(containsString("comment")))); assertThat(list, everyItem(not(startsWith(" ")))); assertThat(list, everyItem(not(startsWith("\t")))); assertThat(list, everyItem(not(endsWith(" ")))); assertThat(list, everyItem(not(endsWith("\t")))); }
@Test public void testIterator() { final String token = "code"; final SqlScript script = new SqlScript(token); final Iterator<String> it = script.iterator(); assertThat(it.hasNext(), equalTo(Boolean.TRUE)); assertThat(it.next(), equalTo(token)); assertThat(it.hasNext(), equalTo(Boolean.FALSE)); try { it.next(); fail("NoSuchElementException expected"); } catch (final NoSuchElementException e) { } }