@Override public boolean hasNext() { return mLastReturned == null || mLastReturned.previous() != null; }
@Override public SqlPart next() { if (mLastReturned == null) { mLastReturned = mFirst; return mFirst; } SqlPart next = mLastReturned.previous(); if (next == null) { throw new NoSuchElementException("No previous SqlPart."); } mLastReturned = next; return mLastReturned; }
@Test public void nextWhenThereIsANext_returnsProperItem() { /* Given */ SqlPart first = mock(SqlPart.class); SqlPart second = mock(SqlPart.class); when(first.previous()).thenReturn(second); SqlPartIterator iterator = new SqlPartIterator(first); iterator.next(); /* When */ SqlPart result = iterator.next(); /* Then */ assertThat(result, is(second)); } }