<commit_before>package org.hisp.dhis.rules;

import org.hisp.dhis.rules.models.Rule;
import org.hisp.dhis.rules.models.RuleAction;
import org.hisp.dhis.rules.models.RuleActionAssign;
import org.hisp.dhis.rules.models.RuleEffect;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static junit.framework.TestCase.fail;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.mockito.Mockito.when;

@RunWith(JUnit4.class)
public class RuleEngineExecutionShould {

    @Mock
    private RuleExpressionEvaluator evaluator;

    @Mock
    private Rule rule;

    @Mock
    private List<RuleAction> actions;

    @Mock
    private RuleActionAssign ruleActionAssign;

    @Mock
    private HashMap<String, RuleVariableValue> variableMap;

    // Object to test
    private RuleEngineExecution ruleEngineExecution;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);

        when(rule.actions()).thenReturn(actions);
        when(actions.get(0)).thenReturn(RuleActionAssign.create("content", "data", "field"));

        ruleEngineExecution = new RuleEngineExecution(evaluator, Collections.singletonList(rule), variableMap);
    }

    @Test
    public void do_not_crash_on_malformed_expression() throws Exception {
        when(rule.condition()).thenReturn("d2:ceil(4 > 2");

        List<RuleEffect> effects = ruleEngineExecution.call();

        assertThat(effects).isEmpty();
    }

}
<commit_msg>androsdk-295: remove unsed imports<commit_after>package org.hisp.dhis.rules;

import org.hisp.dhis.rules.models.Rule;
import org.hisp.dhis.rules.models.RuleAction;
import org.hisp.dhis.rules.models.RuleActionAssign;
import org.hisp.dhis.rules.models.RuleEffect;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.mockito.Mockito.when;

@RunWith(JUnit4.class)
public class RuleEngineExecutionShould {

    @Mock
    private RuleExpressionEvaluator evaluator;

    @Mock
    private Rule rule;

    @Mock
    private List<RuleAction> actions;

    @Mock
    private HashMap<String, RuleVariableValue> variableMap;

    // Object to test
    private RuleEngineExecution ruleEngineExecution;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);

        when(rule.actions()).thenReturn(actions);
        when(actions.get(0)).thenReturn(RuleActionAssign.create("content", "data", "field"));

        ruleEngineExecution = new RuleEngineExecution(evaluator, Collections.singletonList(rule), variableMap);
    }

    @Test
    public void do_not_crash_on_malformed_expression() throws Exception {
        when(rule.condition()).thenReturn("d2:ceil(4 > 2");

        List<RuleEffect> effects = ruleEngineExecution.call();

        assertThat(effects).isEmpty();
    }

}

{'fraction_non_alphanumeric': 0.10706829704742023, 'fraction_numerical': 0.005070086489710707, 'mean_word_length': 4.273584905660377, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2895132', 'n_tokens_mistral': 1032, 'n_tokens_neox': 1009, 'n_words': 194}