### Question:
OrderByBinder { List<SortField<Object>> getOrderByFields() { if (orderAttributes.isEmpty()) return Collections.emptyList(); List<SortField<Object>> orderFields = new ArrayList<>(); for (OrderAttribute orderAttribute : orderAttributes) { SortField<Object> field; String fieldIdentifier = null; if (variableDefinitions != null) { Iterator<I_VariableDefinition> localIterator = variableDefinitions.iterator(); while (localIterator.hasNext()) { I_VariableDefinition variableDefinition = localIterator.next(); if (orderAttribute.getVariableDefinition().getPath() != null && orderAttribute.getVariableDefinition().getPath().equals(variableDefinition.getPath())) { if (variableDefinition.getAlias() != null) fieldIdentifier = variableDefinition.getAlias(); else fieldIdentifier = "/" + orderAttribute.getVariableDefinition().getPath(); break; } else if (orderAttribute.getVariableDefinition().getAlias() != null) fieldIdentifier = orderAttribute.getVariableDefinition().getAlias(); } } if (fieldIdentifier == null) { fieldIdentifier = orderAttribute.getVariableDefinition().getAlias() == null ? "/"+orderAttribute.getVariableDefinition().getPath() : orderAttribute.getVariableDefinition().getAlias(); orderAttribute.getVariableDefinition().setHidden(true); } if (!fieldIdentifier.startsWith("\"")) fieldIdentifier = "\""+fieldIdentifier+"\""; if (orderAttribute.getDirection() != null && orderAttribute.getDirection().equals(OrderAttribute.OrderDirection.DESC)) { field = DSL.field(fieldIdentifier).desc(); } else field = DSL.field(fieldIdentifier).asc(); orderFields.add(field); } return orderFields; } OrderByBinder(VariableDefinitions variableDefinitions, List<OrderAttribute> orderAttributes, SelectQuery<Record> select); SelectQuery<Record> bind();  }### Answer:
@Test public void getOrderByFields() { { OrderAttribute orderAttribute = new OrderAttribute(I_VariableDefinitionHelper.build(null, "date_created", null, false, false, false)); orderAttribute.setDirection(OrderAttribute.OrderDirection.ASC); OrderByBinder cut = new OrderByBinder(null, Collections.singletonList(orderAttribute), DSLContextHelper.buildContext().selectQuery()); List<SortField<Object>> actual = cut.getOrderByFields(); assertThat(actual).size().isEqualTo(1); SortField<?> sortField = actual.get(0); assertThat(sortField.toString()).isEqualTo("\"date_created\" asc"); } { OrderAttribute orderAttribute = new OrderAttribute(I_VariableDefinitionHelper.build(null, "date_created", null, false, false, false)); orderAttribute.setDirection(OrderAttribute.OrderDirection.DESC); OrderByBinder cut = new OrderByBinder(null, Collections.singletonList(orderAttribute), DSLContextHelper.buildContext().selectQuery()); List<SortField<Object>> actual = cut.getOrderByFields(); assertThat(actual).size().isEqualTo(1); SortField<?> sortField = actual.get(0); assertThat(sortField.toString()).isEqualTo("\"date_created\" desc"); } { OrderAttribute orderAttribute = new OrderAttribute(I_VariableDefinitionHelper.build(null, "date_created", null, false, false, false)); OrderByBinder cut = new OrderByBinder(null, Collections.singletonList(orderAttribute), DSLContextHelper.buildContext().selectQuery()); List<SortField<Object>> actual = cut.getOrderByFields(); assertThat(actual).size().isEqualTo(1); SortField<?> sortField = actual.get(0); assertThat(sortField.toString()).isEqualTo("\"date_created\" asc"); } }