@Test
public void populateKiePMMLFieldOperatorValueListWithCompoundPredicates() {

    final List<KiePMMLFieldOperatorValue> toPopulate = new ArrayList<>();
    KiePMMLASTFactoryUtils.populateKiePMMLFieldOperatorValueListWithCompoundPredicates(toPopulate,
                                                                                       compoundPredicates,
                                                                                       fieldTypeMap);
    assertFalse(toPopulate.isEmpty());
    assertEquals(2, toPopulate.size()); // one entry is for "AND" compounds and the other is for "OR" ones
    final Map<CompoundPredicate.BooleanOperator, List<CompoundPredicate>> partitionedCompoundPredicates =
            compoundPredicates.stream()
            .collect(Collectors.groupingBy(CompoundPredicate::getBooleanOperator));
    partitionedCompoundPredicates.forEach((booleanOperator, compoundPredicates) -> {
        final KiePMMLFieldOperatorValue operatorValue = toPopulate.stream()
                .filter(kiePMMLFieldOperatorValue -> kiePMMLFieldOperatorValue.getOperator().equals(BOOLEAN_OPERATOR.byName(booleanOperator.value())))
                .findFirst()
                .orElseThrow(() -> new RuntimeException("Failed toRetrieve KiePMMLFieldOperatorValue for " +
                                                                "BooleanOperator " + booleanOperator));
        final List<KiePMMLFieldOperatorValue> nestedKiePMMLFieldOperatorValues =
                operatorValue.getNestedKiePMMLFieldOperatorValues();
        final List<Predicate> nestedPredicates =
                compoundPredicates.stream().flatMap(compoundPredicate -> compoundPredicate.getPredicates().stream()).collect(Collectors.toList());
        assertEquals(nestedPredicates.size(), nestedKiePMMLFieldOperatorValues.size());
        nestedKiePMMLFieldOperatorValues.forEach(new Consumer<KiePMMLFieldOperatorValue>() {
            @Override
            public void accept(KiePMMLFieldOperatorValue kiePMMLFieldOperatorValue) {
                assertEquals(1, kiePMMLFieldOperatorValue.getKiePMMLOperatorValues().size());
                final KiePMMLOperatorValue kiePMMLOperatorValue =
                        kiePMMLFieldOperatorValue.getKiePMMLOperatorValues().get(0);
                SimplePredicate simplePredicate = nestedPredicates.stream()
                        .map(predicate -> (SimplePredicate) predicate)
                        .filter(predicate -> predicate.getField().getValue().equals(getOriginalPredicateName(kiePMMLFieldOperatorValue.getName())))
                        .findFirst()
                        .orElseThrow(() -> new RuntimeException("Failed to find SimplePredicate for " + kiePMMLFieldOperatorValue.getName()));
                commonVerifyKiePMMLOperatorValue(kiePMMLOperatorValue, simplePredicate);
                nestedPredicates.remove(simplePredicate);
            }
        });
        assertTrue(nestedPredicates.isEmpty());
    });
}