protected void commonDeclareThen(final KiePMMLDroolsRule rule, final StringJoiner joiner) {
        if (rule.getFocusedAgendaGroup() != null) {
            joiner.add(String.format(FOCUS_AGENDA_GROUP, rule.getFocusedAgendaGroup()));
        }
        if (rule.getToAccumulate() != null) {
            joiner.add(String.format(UPDATE_STATUS_HOLDER_ACCUMULATE, rule.getToAccumulate()));
        }
        if (rule.isAccumulationResult()) {
            joiner.add(RETURN_ACCUMULATION);
        }
        if (rule.getResultCode() != null) {
            joiner.add(String.format(SET_PMML4_RESULT_CODE, rule.getResultCode()));
        }
        if (rule.getResult() != null) {
            joiner.add(String.format(ADD_PMML4_RESULT_VARIABLE, rule.getResult()));
        }
        if (rule.getReasonCodeAndValue() != null) {
            final KiePMMLReasonCodeAndValue reasonCodeAndValue = rule.getReasonCodeAndValue();
            joiner.add(String.format(ADD_OUTPUTFIELD_VALUE, reasonCodeAndValue.getReasonCode(), reasonCodeAndValue.getValue()));
        }
        if (rule.getOutputFields() != null) {
            if (rule.getResult() != null) {
                commonDeclareOutputFields(rule.getOutputFields(), rule.getResult(), joiner);
            } else if (rule.isAccumulationResult()) {
                commonDeclareOutputFields(rule.getOutputFields(), "$statusHolder.getAccumulator()", joiner);
            }
        }
    }
@Test
    void commonDeclareThen() {
        String ruleName = "RULENAME";
        String statusToSet = "STATUSTOSET";
        String outputFieldName = "OUTPUTFIELDNAME";
        Object result = "RESULT";
        OutputField outputField = new OutputField();
        outputField.setName(outputFieldName);
        outputField.setResultFeature(ResultFeature.PREDICTED_VALUE);
        List<OutputField> outputFields = Collections.singletonList(outputField);
        KiePMMLDroolsRule.Builder builder = KiePMMLDroolsRule.builder(ruleName, statusToSet, outputFields);
        KiePMMLDroolsRule rule = builder.build();
        StringJoiner joiner = new StringJoiner("");
        KiePMMLDescrRhsFactory.factory(ruleBuilder).commonDeclareThen(rule, joiner);
        String retrieved = joiner.toString();
        assertThat(retrieved).isEmpty();
        //
        ResultCode resultCode = ResultCode.OK;
        builder = builder.withResultCode(resultCode);
        rule = builder.build();
        joiner = new StringJoiner("");
        KiePMMLDescrRhsFactory.factory(ruleBuilder).commonDeclareThen(rule, joiner);
        retrieved = joiner.toString();
        String expected = String.format(SET_PMML4_RESULT_CODE, resultCode);
        assertThat(retrieved).contains(expected);
        //
        builder = builder.withResult(result);
        rule = builder.build();
        joiner = new StringJoiner("");
        KiePMMLDescrRhsFactory.factory(ruleBuilder).commonDeclareThen(rule, joiner);
        retrieved = joiner.toString();
        expected = String.format(ADD_PMML4_RESULT_VARIABLE, result);
        assertThat(retrieved).contains(expected);
        expected = String.format(ADD_PMML4_OUTPUT_FIELD, outputFieldName, result);
        assertThat(retrieved).contains(expected);
        //
        String focusedAgendaGroup = "FOCUSEDAGENDAGROUP";
        builder = builder.withFocusedAgendaGroup(focusedAgendaGroup);
        rule = builder.build();
        joiner = new StringJoiner("");
        KiePMMLDescrRhsFactory.factory(ruleBuilder).commonDeclareThen(rule, joiner);
        retrieved = joiner.toString();
        expected = String.format(FOCUS_AGENDA_GROUP, focusedAgendaGroup);
        assertThat(retrieved).contains(expected);
        //
    }