AstToMongoDBQuery { Criteria chainCriteriaByAndOperator(List<Predicate> predicates) { List<SqlPredicate> sqlPredicates = predicates.stream() .map(predicate -> new PredicateConverter(predicate).astToSqlPredicate()) .collect(toList()); Criteria result = new Criteria(); if (sqlPredicates.isEmpty()) { return result; } SqlPredicate firstIndexSqlPredicate = sqlPredicates.get(0); Criteria whereCriteria = initialCriteria(firstIndexSqlPredicate); int size = sqlPredicates.size(); if (size == 1) { return whereCriteria; } for (int x = 1; x < size; x++) { SqlPredicate sqlPredicate = sqlPredicates.get(x); result = andCriteria(sqlPredicate, whereCriteria); } return result; } AstToMongoDBQuery(OpaCompilerResponse opaCompilerResponse); Query createQuery();  }
@Test void shouldChainCriteriaByAndOperationCriteria() { List<Predicate> predicates = opaCompilerResponse.getResult().getQueries().get(0); Criteria result = target.chainCriteriaByAndOperator(predicates); String resultInString = result.getCriteriaObject().toJson(); assertThat(resultInString, is("{\"owner\": \"alice\", \"name\": \"fluffy\"}")); }