### Question:
SqlQueryParser implements QueryParser { protected List<Ordering> parseOrderBy( TokenStream tokens, TypeSystem typeSystem, Source source, List<ColumnExpression> columnExpressions ) { columnExpressions.addAll(parseOrderingColumn(tokens, new AtomicBoolean(false), typeSystem)); return parseOrderBy(tokens, typeSystem, source); }  String getLanguage(); @Override String toString(); @Override boolean equals( Object obj ); QueryCommand parseQuery( String query,
                                    TypeSystem typeSystem ); static final String LANGUAGE; }### Answer:
@Test public void shouldParserOrderByWithOneOrdering() { List<Ordering> orderBy = parser.parseOrderBy(tokens("ORDER BY NAME(tableA) ASC"), typeSystem, mock(Source.class)); assertThat(orderBy.size(), is(1)); Ordering first = orderBy.get(0); assertThat(first.operand(), is(instanceOf(NodeName.class))); assertThat(first.order(), is(Order.ASCENDING)); }
@Test public void shouldParserOrderByWithTwoOrderings() { List<Ordering> orderBy = parser.parseOrderBy(tokens("ORDER BY NAME(tableA) ASC, SCORE(tableB) DESC"), typeSystem, mock(Source.class)); assertThat(orderBy.size(), is(2)); Ordering first = orderBy.get(0); assertThat(first.operand(), is(instanceOf(NodeName.class))); assertThat(first.order(), is(Order.ASCENDING)); Ordering second = orderBy.get(1); assertThat(second.operand(), is(instanceOf(FullTextSearchScore.class))); assertThat(second.order(), is(Order.DESCENDING)); }
@Test public void shouldParserOrderByWithMultipleOrderings() { List<Ordering> orderBy = parser.parseOrderBy(tokens("ORDER BY NAME(tableA) ASC, SCORE(tableB) DESC, LENGTH(tableC.id) ASC"), typeSystem, mock(Source.class)); assertThat(orderBy.size(), is(3)); Ordering first = orderBy.get(0); assertThat(first.operand(), is(instanceOf(NodeName.class))); assertThat(first.order(), is(Order.ASCENDING)); Ordering second = orderBy.get(1); assertThat(second.operand(), is(instanceOf(FullTextSearchScore.class))); assertThat(second.order(), is(Order.DESCENDING)); Ordering third = orderBy.get(2); assertThat(third.operand(), is(instanceOf(Length.class))); assertThat(third.order(), is(Order.ASCENDING)); }
@Test( expected = ParsingException.class ) public void shouldFailToParseOrderByIfCommaNotFollowedByAnotherOrdering() { parser.parseOrderBy(tokens("ORDER BY NAME(tableA) ASC, NOT A VALID ORDERING"), typeSystem, mock(Source.class)); }
@Test public void shouldReturnNullFromParseOrderByWithoutOrderByKeywords() { assertThat(parser.parseOrderBy(tokens("NOT ORDER BY"), typeSystem, mock(Source.class)), is(nullValue())); }