static BlockStmt getApplyVariableDeclaration(final String variableName, final Apply apply) {
        final MethodDeclaration methodDeclaration = APPLY_TEMPLATE.getMethodsByName(GETKIEPMMLAPPLY).get(0).clone();
        final BlockStmt applyBody =
                methodDeclaration.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration)));
        final VariableDeclarator variableDeclarator =
                getVariableDeclarator(applyBody, APPLY).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, APPLY, applyBody)));
        variableDeclarator.setName(variableName);
        final BlockStmt toReturn = new BlockStmt();
        int counter = 0;
        final NodeList<Expression> arguments = new NodeList<>();
        for (org.dmg.pmml.Expression expression : apply.getExpressions()) {
            String nestedVariableName = String.format(VARIABLE_NAME_TEMPLATE, variableName, counter);
            arguments.add(new NameExpr(nestedVariableName));
            BlockStmt toAdd = getKiePMMLExpressionBlockStmt(nestedVariableName, expression);
            toAdd.getStatements().forEach(toReturn::addStatement);
            counter++;
        }
        final MethodCallExpr initializer = variableDeclarator.getInitializer()
                .orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, APPLY, toReturn)))
                .asMethodCallExpr();
        final MethodCallExpr builder = getChainedMethodCallExprFrom("builder", initializer);
        final StringLiteralExpr nameExpr = new StringLiteralExpr(variableName);
        final StringLiteralExpr functionExpr = new StringLiteralExpr(apply.getFunction());
        builder.setArgument(0, nameExpr);
        builder.setArgument(2, functionExpr);
        getChainedMethodCallExprFrom("withDefaultValue", initializer).setArgument(0, getExpressionForObject(apply.getDefaultValue()));
        getChainedMethodCallExprFrom("withMapMissingTo", initializer).setArgument(0, getExpressionForObject(apply.getMapMissingTo()));
        final Expression invalidTreatmentExpr = apply.getInvalidValueTreatment() != null ? new StringLiteralExpr(apply.getInvalidValueTreatment().value()) : new NullLiteralExpr();
        getChainedMethodCallExprFrom("withInvalidValueTreatmentMethod", initializer).setArgument(0, invalidTreatmentExpr);
        getChainedMethodCallExprFrom("asList", initializer).setArguments(arguments);
        applyBody.getStatements().forEach(toReturn::addStatement);
        return toReturn;
    }
@Test
    void getApplyVariableDeclarationWithApply() throws IOException {
        String variableName = "variableName";
        Apply nestedApply = new Apply();
        nestedApply.setFunction("nested_function");
        String mapMissingTo = "mapMissingTo";
        nestedApply.setMapMissingTo(mapMissingTo);
        String defaultValue = "defaultValue";
        nestedApply.setDefaultValue(defaultValue);
        InvalidValueTreatmentMethod nestedInvalidValueTreatmentMethod = InvalidValueTreatmentMethod.AS_MISSING;
        nestedApply.setInvalidValueTreatment(nestedInvalidValueTreatmentMethod);
        FieldRef fieldRef1 = new FieldRef();
        fieldRef1.setField(PARAM_1);
        FieldRef fieldRef2 = new FieldRef();
        fieldRef2.setField(PARAM_2);
        nestedApply.addExpressions(fieldRef1, fieldRef2);
        Apply apply = new Apply();
        apply.setFunction(function);
        InvalidValueTreatmentMethod invalidValueTreatmentMethod = InvalidValueTreatmentMethod.AS_MISSING;
        apply.setInvalidValueTreatment(invalidValueTreatmentMethod);
        apply.addExpressions(nestedApply);
        BlockStmt retrieved = KiePMMLApplyFactory.getApplyVariableDeclaration(variableName, apply);
        String text = getFileContent(TEST_03_SOURCE);
        Statement expected = JavaParserUtils.parseBlock(String.format(text, PARAM_1, PARAM_2,
                                                                      defaultValue, mapMissingTo,
                                                                      nestedInvalidValueTreatmentMethod.value(),
                                                                      variableName,
                                                                      invalidValueTreatmentMethod.value()));
        assertThat(JavaParserUtils.equalsNode(expected, retrieved)).isTrue();
        List<Class<?>> imports = Arrays.asList(KiePMMLFieldRef.class, KiePMMLApply.class, Collections.class,
                                               Arrays.class);
        commonValidateCompilationWithImports(retrieved, imports);
    }