OrderTask implements Task { @Override public ExecutionResult execute(ExecutionResult previousTaskResult) throws SQLException { try { Comparator<DataRow> comparator = createComparator(null, expressions); if (comparator != null) { return new ExecutionResult(){ { setCount(previousTaskResult.getCount()); DataContainer newData = new DataContainer( previousTaskResult.getData(), rows -> rows.stream() .sorted(comparator) .collect(Collectors.toList()) ); setData(newData); } }; } return previousTaskResult; } catch (Exception e) { throw new SQLException(e); } } @Autowired  OrderTask(ExpressionEvaluator expressionEvaluator); void addExpression(OrderExpression orderExpression); @Override ExecutionResult execute(ExecutionResult previousTaskResult); List<OrderExpression> getExpressions(); @Override String toString();  }
@Test public void testExecute() throws Exception { OrderTask orderTask = applicationContext.getBean(OrderTask.class); orderTask.addExpression(new OrderExpression(new ColumnExpression(FIRST_COLUMN_TO_SORT_BY, TABLE_NAME))); orderTask.addExpression(new OrderExpression(new ColumnExpression(SECOND_COLUMN_TO_SORT_BY, TABLE_NAME), OrderDirection.DESC)); ExecutionResult executionResult = orderTask.execute(getInput()); assertThat(executionResult.getCount(), equalTo(4)); List<DataRow> data = executionResult.getData().getRows(); assertThat(data.get(0).getValues(), equalTo(createRow("a", 4))); assertThat(data.get(1).getValues(), equalTo(createRow("a", 3))); assertThat(data.get(2).getValues(), equalTo(createRow("b", 3))); assertThat(data.get(3).getValues(), equalTo(createRow("b", 2))); }