### Question:
MongodbSerializer implements Visitor<Object, Void> { public DBObject toSort(List<OrderSpecifier<?>> orderBys) { BasicDBObject sort = new BasicDBObject(); for (OrderSpecifier<?> orderBy : orderBys) { Object key = orderBy.getTarget().accept(this, null); sort.append(key.toString(), orderBy.getOrder() == Order.ASC ? 1 : -1); } return sort; }  Object handle(Expression<?> expression); DBObject toSort(List<OrderSpecifier<?>> orderBys); @Override Object visit(Constant<?> expr, Void context); @Override Object visit(TemplateExpression<?> expr, Void context); @Override Object visit(FactoryExpression<?> expr, Void context); @SuppressWarnings("unchecked") @Override Object visit(Operation<?> expr, Void context); @Override String visit(Path<?> expr, Void context); @Override Object visit(SubQueryExpression<?> expr, Void context); @Override Object visit(ParamExpression<?> expr, Void context);  }### Answer:
@Test public void orderBy() { DBObject orderBy = serializer.toSort(sortList(year.asc())); assertEquals(dbo("year", 1), orderBy); orderBy = serializer.toSort(sortList(year.desc())); assertEquals(dbo("year", -1), orderBy); orderBy = serializer.toSort(sortList(year.desc(), title.asc())); assertEquals(dbo("year", -1).append("title", 1), orderBy); }