@Test
  public void query() {
    final PersonRepository.Criteria criteria = repository.criteria();


    repository.find(criteria)
            .orderByAliases()
            .orderByNameDesceding();

    validate(criteria.name("foo"), BsonDocument.parse("{\"name\":\"foo\"}"));
    validate(criteria.name("foo").age(8), BsonDocument.parse("{\"name\":\"foo\", \"age\": 8}"));
    validate(criteria.name("foo").ageLessThan(8), BsonDocument.parse("{\"name\":\"foo\", \"age\": {\"$lt\": 8}}"));
    validate(criteria.ageLessThan(8).ageNot(5),
            BsonDocument.parse("{\"$and\": [{\"age\":{ \"$lt\": 8}}, {\"age\": {\"$ne\": 5}} ] }"));
    // pass as-is without optimizations
    validate(criteria.name("foo").name("bar"),
            BsonDocument.parse("{\"$and\": [{\"name\": \"foo\"}, {\"name\": \"bar\"}]}"));
    validate(criteria.name("foo").name("bar").name("qux"),
            BsonDocument.parse("{\"$and\": [{\"name\": \"foo\"}, {\"name\": \"bar\"}, {\"name\":\"qux\"}]}"));
    validate(criteria.name("foo").or().nameNot("bar"),
            BsonDocument.parse("{\"$or\": [{\"name\": \"foo\"}, {\"name\": {\"$ne\": \"bar\"}} ] }"));
    validate(criteria.nameIn("foo", "bar").name("bar"),
            BsonDocument.parse("{\"$and\":[ {\"name\": {\"$in\": [\"foo\", \"bar\"]}}, {\"name\": \"bar\"} ] }"));

    validate(criteria.name("foo").age(22).or().name("bar").age(33),
            BsonDocument.parse("{\"$or\": [" +
                    "{\"name\": \"foo\", \"age\": 22}, " +
                    "{\"name\": \"bar\", \"age\": 33}" +
                    "]}"));
  }
Comparing queries generated directly by criteria.
mongo/test/org/immutables/mongo/fixture/criteria/QueryTest.java