### Question:
SqlQueryParser implements QueryParser { protected Limit parseLimit( TokenStream tokens ) { if (tokens.canConsume("LIMIT")) { int first = tokens.consumeInteger(); if (tokens.canConsume(',')) { int to = tokens.consumeInteger(); int offset = to - first; if (offset < 0) { Position pos = tokens.previousPosition(); String msg = GraphI18n.secondValueInLimitRangeCannotBeLessThanFirst.text(first, to, pos.getLine(), pos.getColumn()); throw new ParsingException(pos, msg); } return limit(offset, first); } if (tokens.canConsume("OFFSET")) { int offset = tokens.consumeInteger(); return limit(first, offset); } return limit(first, 0); } return null; }  String getLanguage(); @Override String toString(); @Override boolean equals( Object obj ); QueryCommand parseQuery( String query,
                                    TypeSystem typeSystem ); static final String LANGUAGE; }### Answer:
@Test public void shouldParseLimitFromFormWithJustOneNumber() { Limit limit = parser.parseLimit(tokens("LIMIT 10")); assertThat(limit.rowLimit(), is(10)); assertThat(limit.offset(), is(0)); limit = parser.parseLimit(tokens("LIMIT 10 NONOFFSET")); assertThat(limit.rowLimit(), is(10)); assertThat(limit.offset(), is(0)); }
@Test public void shouldParseLimitFromFormWithRowLimitAndOffset() { Limit limit = parser.parseLimit(tokens("LIMIT 10 OFFSET 30")); assertThat(limit.rowLimit(), is(10)); assertThat(limit.offset(), is(30)); limit = parser.parseLimit(tokens("LIMIT 10 OFFSET 30 OTHER")); assertThat(limit.rowLimit(), is(10)); assertThat(limit.offset(), is(30)); }
@Test public void shouldParseLimitFromFormWithTwoCommaSeparatedNumbers() { Limit limit = parser.parseLimit(tokens("LIMIT 10,30")); assertThat(limit.rowLimit(), is(20)); assertThat(limit.offset(), is(10)); }
@Test public void shouldReturnNullFromParseLimitWithNoLimitKeyword() { assertThat(parser.parseLimit(tokens("OTHER")), is(nullValue())); assertThat(parser.parseLimit(tokens(" ")), is(nullValue())); }
@Test( expected = ParsingException.class ) public void shouldFailToParseLimitIfRowLimitNumberTokenIsNotAnInteger() { parser.parseLimit(tokens("LIMIT 10a OFFSET 30")); }
@Test( expected = ParsingException.class ) public void shouldFailToParseLimitIfOffsetNumberTokenIsNotAnInteger() { parser.parseLimit(tokens("LIMIT 10 OFFSET 30a")); }
@Test( expected = ParsingException.class ) public void shouldFailToParseLimitIfStartingRowNumberTokenIsNotAnInteger() { parser.parseLimit(tokens("LIMIT 10a,20")); }
@Test( expected = ParsingException.class ) public void shouldFailToParseLimitIfEndingRowNumberTokenIsNotAnInteger() { parser.parseLimit(tokens("LIMIT 10,20a")); }