### Question:
OrderByStreamResultSetMerger extends AbstractStreamResultSetMerger { @Override public boolean next() throws SQLException { if (orderByValuesQueue.isEmpty()) { return false; } if (isFirstNext) { isFirstNext = false; return true; } OrderByValue firstOrderByValue = orderByValuesQueue.poll(); if (firstOrderByValue.next()) { orderByValuesQueue.offer(firstOrderByValue); } if (orderByValuesQueue.isEmpty()) { return false; } setCurrentResultSet(orderByValuesQueue.peek().getResultSet()); return true; } OrderByStreamResultSetMerger(final List<ResultSet> resultSets, final List<OrderItem> orderByItems, final OrderType nullOrderType); @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 assertNextForSomeResultSetsEmpty() throws SQLException { mergeEngine = new MergeEngine(DatabaseType.MySQL, resultSets, selectStatement); when(resultSets.get(0).next()).thenReturn(true, false); when(resultSets.get(0).getObject(1)).thenReturn("2"); when(resultSets.get(2).next()).thenReturn(true, true, false); when(resultSets.get(2).getObject(1)).thenReturn("1", "1", "3", "3"); ResultSetMerger actual = mergeEngine.merge(); assertTrue(actual.next()); assertThat(actual.getValue(1, Object.class).toString(), is("1")); assertTrue(actual.next()); assertThat(actual.getValue(1, Object.class).toString(), is("2")); assertTrue(actual.next()); assertThat(actual.getValue(1, Object.class).toString(), is("3")); assertFalse(actual.next()); }
@Test public void assertNextForMix() throws SQLException { mergeEngine = new MergeEngine(DatabaseType.MySQL, resultSets, selectStatement); when(resultSets.get(0).next()).thenReturn(true, false); when(resultSets.get(0).getObject(1)).thenReturn("2"); when(resultSets.get(1).next()).thenReturn(true, true, true, false); when(resultSets.get(1).getObject(1)).thenReturn("2", "2", "3", "3", "4", "4"); when(resultSets.get(2).next()).thenReturn(true, true, false); when(resultSets.get(2).getObject(1)).thenReturn("1", "1", "3", "3"); ResultSetMerger actual = mergeEngine.merge(); assertTrue(actual.next()); assertThat(actual.getValue(1, Object.class).toString(), is("1")); assertTrue(actual.next()); assertThat(actual.getValue(1, Object.class).toString(), is("2")); assertTrue(actual.next()); assertThat(actual.getValue(1, Object.class).toString(), is("2")); assertTrue(actual.next()); assertThat(actual.getValue(1, Object.class).toString(), is("3")); assertTrue(actual.next()); assertThat(actual.getValue(1, Object.class).toString(), is("3")); assertTrue(actual.next()); assertThat(actual.getValue(1, Object.class).toString(), is("4")); assertFalse(actual.next()); }