### Question:
LimitDecoratorResultSetMerger extends AbstractDecoratorResultSetMerger { @Override public boolean next() throws SQLException { if (skipAll) { return false; } if (limit.getRowCountValue() > -1) { return ++rowNumber <= limit.getRowCountValue() && getResultSetMerger().next(); } return getResultSetMerger().next(); } LimitDecoratorResultSetMerger(final ResultSetMerger resultSetMerger, final Limit limit); @Override boolean next();  }### Answer:
@Test public void assertNextForSkipAll() throws SQLException { Limit limit = new Limit(true); limit.setOffset(new LimitValue(Integer.MAX_VALUE, -1)); selectStatement.setLimit(limit); for (ResultSet each : resultSets) { when(each.next()).thenReturn(true, true, false); } mergeEngine = new MergeEngine(DatabaseType.MySQL, resultSets, selectStatement); ResultSetMerger actual = mergeEngine.merge(); assertFalse(actual.next()); }
@Test public void assertNextWithoutRowCount() throws SQLException { Limit limit = new Limit(true); limit.setOffset(new LimitValue(2, -1)); selectStatement.setLimit(limit); for (ResultSet each : resultSets) { when(each.next()).thenReturn(true, true, false); } mergeEngine = new MergeEngine(DatabaseType.MySQL, resultSets, selectStatement); ResultSetMerger actual = mergeEngine.merge(); assertTrue(actual.next()); assertTrue(actual.next()); assertTrue(actual.next()); assertTrue(actual.next()); assertTrue(actual.next()); assertTrue(actual.next()); assertFalse(actual.next()); }
@Test public void assertNextWithRewriteRowCount() throws SQLException { Limit limit = new Limit(true); limit.setOffset(new LimitValue(2, -1)); limit.setRowCount(new LimitValue(2, -1)); selectStatement.setLimit(limit); for (ResultSet each : resultSets) { when(each.next()).thenReturn(true, true, false); } mergeEngine = new MergeEngine(DatabaseType.MySQL, resultSets, selectStatement); ResultSetMerger actual = mergeEngine.merge(); assertTrue(actual.next()); assertTrue(actual.next()); assertFalse(actual.next()); }
@Test public void assertNextWithNotRewriteRowCount() throws SQLException { Limit limit = new Limit(false); limit.setOffset(new LimitValue(2, -1)); limit.setRowCount(new LimitValue(4, -1)); selectStatement.setLimit(limit); for (ResultSet each : resultSets) { when(each.next()).thenReturn(true, true, false); } mergeEngine = new MergeEngine(DatabaseType.MySQL, resultSets, selectStatement); ResultSetMerger actual = mergeEngine.merge(); assertTrue(actual.next()); assertTrue(actual.next()); assertFalse(actual.next()); }