<commit_before>package com.airhacks.headlands.processors.boundary;

import javax.cache.processor.EntryProcessor;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import org.junit.Before;
import org.junit.Test;

/**
 *
 * @author <EMAIL>
 */
public class EntryProcessorExecutorTest {

    EntryProcessorExecutor cut;

    @Before
    public void init() {
        this.cut = new EntryProcessorExecutor();
        this.cut.initializeEngine();
    }

    @Test
    public void createProcessorFromEmptyScript() {
        EntryProcessor<String, String, String> invalid = this.cut.createProcessorFromScript("");
        assertNull(invalid);
    }

    @Test(expected = IllegalStateException.class)
    public void createProcessorFromInvalidScript() {
        EntryProcessor<String, String, String> invalid = this.cut.createProcessorFromScript("INVALID");
        assertNull(invalid);
    }

    @Test
    public void createValidProcessorFromScript() {
        String expected = "works";
        String processorScript = "function process(entry,args){ return \"" + expected + "\"}";
        EntryProcessor<String, String, String> processor = this.cut.createProcessorFromScript(processorScript);
        assertNotNull(processor);
        String result = processor.process(null);
        assertThat(result, is(expected));
    }

    @Test
    public void createValidProcessorWithArgument() {
        String expected = "works";
        String processorScript = "function process(entry,arg){ return arg[0]}";
        EntryProcessor<String, String, String> processor = this.cut.createProcessorFromScript(processorScript);
        assertNotNull(processor);
        String result = processor.process(null, expected);
        assertThat(result, is(expected));
    }

}<commit_msg>test fixed<commit_after>package com.airhacks.headlands.processors.boundary;

import com.airhacks.headlands.cache.boundary.CacheDiscoverer;
import com.airhacks.headlands.engine.control.NashornEngine;
import java.util.HashSet;
import java.util.Map;
import javax.cache.Cache;
import javax.cache.processor.EntryProcessorResult;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
 *
 * @author <EMAIL>hacks.com
 */
public class EntryProcessorExecutorTest {

    EntryProcessorExecutor cut;
    String existingCache = "dukes";
    private Cache cache;

    @Before
    public void init() {
        NashornEngine engine = new NashornEngine();
        engine.initializeEngine();
        this.cut = new EntryProcessorExecutor();
        this.cut.engine = engine;
        this.cut.discoverer = mock(CacheDiscoverer.class);
        this.cache = mock(Cache.class);
        when(this.cut.discoverer.getCache(existingCache)).thenReturn(cache);
    }

    @Test
    public void createValidProcessorFromScript() {
        String expected = "works";
        String processorScript = "function process(entry,args){ return \"" + expected + "\"}";
        Map<String, EntryProcessorResult<String>> result = this.cut.execute(existingCache, processorScript, new HashSet<>(), new HashSet<>());
        assertNotNull(result);
        assertTrue(result.isEmpty());
    }

}
{'fraction_non_alphanumeric': 0.11085043988269795, 'fraction_numerical': 0.0002932551319648094, 'mean_word_length': 3.8177966101694913, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '6652927', 'n_tokens_mistral': 920, 'n_tokens_neox': 910, 'n_words': 192}