<commit_before><commit_msg>Test AndTrigger.<commit_after>package com.collective.celos;

import org.junit.Assert;
import org.junit.Test;

import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

public class AndTriggerTest {

    @Test
    public void returnsTrueWhenAllSubTriggersReturnTrue() throws Exception {
        ArrayNode subTriggersArray = Util.newArrayNode();
        subTriggersArray.add(createAlwaysTriggerConfiguration());
        subTriggersArray.add(createAlwaysTriggerConfiguration());
        subTriggersArray.add(createAlwaysTriggerConfiguration());
        ObjectNode properties = Util.newObjectNode();
        properties.put(AndTrigger.TRIGGERS_PROP, subTriggersArray);
        AndTrigger trigger = new AndTrigger(properties);
        Assert.assertTrue(trigger.isDataAvailable(new ScheduledTime("2014-02-26T16:13:00Z")));
    }
    
    @Test
    public void returnsFalseWhenOnlyOneSubTriggerReturnsTrue() throws Exception {
        ArrayNode subTriggersArray = Util.newArrayNode();
        subTriggersArray.add(createNeverTriggerConfiguration());
        subTriggersArray.add(createAlwaysTriggerConfiguration());
        subTriggersArray.add(createNeverTriggerConfiguration());
        ObjectNode properties = Util.newObjectNode();
        properties.put(AndTrigger.TRIGGERS_PROP, subTriggersArray);
        AndTrigger trigger = new AndTrigger(properties);
        Assert.assertFalse(trigger.isDataAvailable(new ScheduledTime("2014-02-26T16:13:00Z")));
    }

    @Test
    public void returnsFalseWhenNoSubTriggersReturnsTrue() throws Exception {
        ArrayNode subTriggersArray = Util.newArrayNode();
        subTriggersArray.add(createNeverTriggerConfiguration());
        subTriggersArray.add(createNeverTriggerConfiguration());
        subTriggersArray.add(createNeverTriggerConfiguration());
        ObjectNode properties = Util.newObjectNode();
        properties.put(AndTrigger.TRIGGERS_PROP, subTriggersArray);
        AndTrigger trigger = new AndTrigger(properties);
        Assert.assertFalse(trigger.isDataAvailable(new ScheduledTime("2014-02-26T16:13:00Z")));
    }

    private ObjectNode createAlwaysTriggerConfiguration() {
        ObjectNode config = Util.newObjectNode();
        config.put("type", "com.collective.celos.AlwaysTrigger");
        return config;
    }
    
    private ObjectNode createNeverTriggerConfiguration() {
        ObjectNode config = Util.newObjectNode();
        config.put("type", "com.collective.celos.NeverTrigger");
        return config;
    }
    
}
{'fraction_non_alphanumeric': 0.09627329192546584, 'fraction_numerical': 0.016304347826086956, 'mean_word_length': 4.16432865731463, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '132738', 'n_tokens_mistral': 706, 'n_tokens_neox': 683, 'n_words': 103}