SortTokenParserAdapter { public SortNodeList parse(String sortExpression) { try { return createParser(sortExpression).parse(); } catch (ParseException | Error e) { throw new SortParsingException(e); } }  SortNodeList parse(String sortExpression);  }
@Test public void parseSingleSort_Ascending() { String sortExpression = "sort (+ employee.name) "; SortNodeList sortNodeList = new SortTokenParserAdapter().parse(sortExpression); assertNotNull(sortNodeList); List<SortNode> sortNodes = sortNodeList.getNodes(); assertEquals(1, sortNodes.size()); SortNode sortNode = sortNodes.get(0); assertEquals("employee.name", sortNode.getField()); assertEquals(SortNode.Order.ASC, sortNode.getOrder()); }
@Test public void parseSingleSort_Descending() { String sortExpression = "sort ( - employee.name) "; SortNodeList sortNodeList = new SortTokenParserAdapter().parse(sortExpression); assertNotNull(sortNodeList); List<SortNode> sortNodes = sortNodeList.getNodes(); assertEquals(1, sortNodes.size()); SortNode sortNode = sortNodes.get(0); assertEquals("employee.name", sortNode.getField()); assertEquals(SortNode.Order.DESC, sortNode.getOrder()); }
@Test public void parseSingleSort_Error() { String sortExpression = "sort (+- employee.name) "; thrown.expect(SortParsingException.class); new SortTokenParserAdapter().parse(sortExpression); }
@Test public void parseMultipleSort() { String sortExpression = "sort ( + employee.name, - company.code) "; SortNodeList sortNodeList = new SortTokenParserAdapter().parse(sortExpression); assertNotNull(sortNodeList); List<SortNode> sortNodes = sortNodeList.getNodes(); assertEquals(2, sortNodes.size()); SortNode sortNode = sortNodes.get(0); assertEquals("employee.name", sortNode.getField()); assertEquals(SortNode.Order.ASC, sortNode.getOrder()); SortNode sortNode2 = sortNodes.get(1); assertEquals("company.code", sortNode2.getField()); assertEquals(SortNode.Order.DESC, sortNode2.getOrder()); }