### Question:
IteratorStreamResultSetMerger extends AbstractStreamResultSetMerger { @Override public boolean next() throws SQLException { if (getCurrentResultSet().next()) { return true; } if (!resultSets.hasNext()) { return false; } setCurrentResultSet(resultSets.next()); boolean hasNext = getCurrentResultSet().next(); if (hasNext) { return true; } while (!hasNext && resultSets.hasNext()) { setCurrentResultSet(resultSets.next()); hasNext = getCurrentResultSet().next(); } return hasNext; } IteratorStreamResultSetMerger(final List<ResultSet> resultSets); @Override boolean next();  }### Answer:
@Test public void assertNextForResultSetsAllEmpty() throws SQLException { mergeEngine = new MergeEngine(DatabaseType.MySQL, resultSets, selectStatement); ResultSetMerger actual = mergeEngine.merge(); assertFalse(actual.next()); }
@Test public void assertNextForResultSetsAllNotEmpty() throws SQLException { for (ResultSet each : resultSets) { when(each.next()).thenReturn(true, false); } mergeEngine = new MergeEngine(DatabaseType.MySQL, resultSets, selectStatement); ResultSetMerger actual = mergeEngine.merge(); assertTrue(actual.next()); assertTrue(actual.next()); assertTrue(actual.next()); assertFalse(actual.next()); }
@Test public void assertNextForFirstResultSetsNotEmptyOnly() throws SQLException { when(resultSets.get(0).next()).thenReturn(true, false); mergeEngine = new MergeEngine(DatabaseType.MySQL, resultSets, selectStatement); ResultSetMerger actual = mergeEngine.merge(); assertTrue(actual.next()); assertFalse(actual.next()); }
@Test public void assertNextForMiddleResultSetsNotEmpty() throws SQLException { when(resultSets.get(1).next()).thenReturn(true, false); mergeEngine = new MergeEngine(DatabaseType.MySQL, resultSets, selectStatement); ResultSetMerger actual = mergeEngine.merge(); assertTrue(actual.next()); assertFalse(actual.next()); }
@Test public void assertNextForLastResultSetsNotEmptyOnly() throws SQLException { when(resultSets.get(2).next()).thenReturn(true, false); mergeEngine = new MergeEngine(DatabaseType.MySQL, resultSets, selectStatement); ResultSetMerger actual = mergeEngine.merge(); assertTrue(actual.next()); assertFalse(actual.next()); }
@Test public void assertNextForMix() throws SQLException { resultSets.add(mock(ResultSet.class)); resultSets.add(mock(ResultSet.class)); resultSets.add(mock(ResultSet.class)); when(resultSets.get(1).next()).thenReturn(true, false); when(resultSets.get(3).next()).thenReturn(true, false); when(resultSets.get(5).next()).thenReturn(true, false); mergeEngine = new MergeEngine(DatabaseType.MySQL, resultSets, selectStatement); ResultSetMerger actual = mergeEngine.merge(); assertTrue(actual.next()); assertTrue(actual.next()); assertTrue(actual.next()); assertFalse(actual.next()); }