<commit_before>package io.redbarn;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import javax.script.ScriptEngine;
import javax.script.ScriptException;
import java.io.IOException;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;

/**
 * Tests the HtmlProcessorScriptImage class.
 *
 * @author <NAME>
 * @since 0.1.0
 */
public class HtmlProcessorScriptImageTest {

    private ScriptEngine scriptEngine;

    @BeforeClass(groups = "Slow")
    public void classSetup() throws IOException, ScriptException {
        RedbarnScriptEngineManager manager = new RedbarnScriptEngineManager();
        scriptEngine = manager.getScriptEngine();
    }

    @Test(groups = "Slow", expectedExceptions = IllegalArgumentException.class)
    public void constructor_ScriptEngineIsNull_Throws()
            throws IOException, ScriptException {
        HtmlProcessorScriptImage processor = new HtmlProcessorScriptImage(
                null,
                "<html></html>",
                "foo",
                "function process() { // do nothing }"
        );
    }

    @Test(groups = "Slow", expectedExceptions = IllegalArgumentException.class)
    public void constructor_KeyIsNull_Throws()
            throws IOException, ScriptException {
        HtmlProcessorScriptImage processor = new HtmlProcessorScriptImage(
                scriptEngine,
                "<html></html>",
                null,
                "function process() { // do nothing }"
        );
    }

    @Test(groups = "Slow", expectedExceptions = IllegalArgumentException.class)
    public void constructor_ProcessFunctionIsNull_Throws()
            throws IOException, ScriptException {
        HtmlProcessorScriptImage processor = new HtmlProcessorScriptImage(
                scriptEngine,
                "<html></html>",
                "foo",
                null
        );
    }

    @Test(groups = "Slow")
    public void params_ProcessorFunctionHasNoParameters_ReturnsNonNull()
            throws IOException, ScriptException {
        String processFunction = "function process() { alert('noop'); }";
        HtmlProcessorScriptImage processor = new HtmlProcessorScriptImage(
                scriptEngine,
                "<html></html>",
                "foo",
                processFunction
        );
        String[] params = processor.getParameters();
        assertNotNull(params);
    }

    @Test(groups = "Slow")
    public void params_ProcessorFunctionHasParameters_ReturnsAllParameters()
            throws IOException, ScriptException {
        String processFunction = "function process(foo, bar, baz) { alert('noop'); }";
        HtmlProcessorScriptImage processor = new HtmlProcessorScriptImage(
                scriptEngine,
                "<html></html>",
                "foo",
                processFunction
        );
        String[] params = processor.getParameters();<commit_msg>[WIP] Renames test methods<commit_after>package io.redbarn;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import javax.script.ScriptEngine;
import javax.script.ScriptException;
import java.io.IOException;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;

/**
 * Tests the HtmlProcessorScriptImage class.
 *
 * @author <NAME>
 * @since 0.1.0
 */
public class HtmlProcessorScriptImageTest {

    private ScriptEngine scriptEngine;

    @BeforeClass(groups = "Slow")
    public void classSetup() throws IOException, ScriptException {
        RedbarnScriptEngineManager manager = new RedbarnScriptEngineManager();
        scriptEngine = manager.getScriptEngine();
    }

    @Test(groups = "Slow", expectedExceptions = IllegalArgumentException.class)
    public void constructor_ScriptEngineIsNull_Throws()
            throws IOException, ScriptException {
        HtmlProcessorScriptImage processor = new HtmlProcessorScriptImage(
                null,
                "<html></html>",
                "foo",
                "function process() { // do nothing }"
        );
    }

    @Test(groups = "Slow", expectedExceptions = IllegalArgumentException.class)
    public void constructor_KeyIsNull_Throws()
            throws IOException, ScriptException {
        HtmlProcessorScriptImage processor = new HtmlProcessorScriptImage(
                scriptEngine,
                "<html></html>",
                null,
                "function process() { // do nothing }"
        );
    }

    @Test(groups = "Slow", expectedExceptions = IllegalArgumentException.class)
    public void constructor_ProcessFunctionIsNull_Throws()
            throws IOException, ScriptException {
        HtmlProcessorScriptImage processor = new HtmlProcessorScriptImage(
                scriptEngine,
                "<html></html>",
                "foo",
                null
        );
    }

    @Test(groups = "Slow")
    public void getParameters_ProcessorFunctionHasNoParameters_ReturnsNonNull()
            throws IOException, ScriptException {
        String processFunction = "function process() { alert('noop'); }";
        HtmlProcessorScriptImage processor = new HtmlProcessorScriptImage(
                scriptEngine,
                "<html></html>",
                "foo",
                processFunction
        );
        String[] params = processor.getParameters();
        assertNotNull(params);
    }

    @Test(groups = "Slow")
    public void getParameters_ProcessorFunctionHasParameters_ReturnsAllParameters()
            throws IOException, ScriptException {
        String processFunction = "function process(foo, bar, baz) { alert('noop'); }";
        HtmlProcessorScriptImage processor = new HtmlProcessorScriptImage(
                scriptEngine,
                "<html></html>",
                "foo",
                processFunction
        );
        String[] params = processor.getParameters();
{'fraction_non_alphanumeric': 0.09110774920154648, 'fraction_numerical': 0.0010085728693898135, 'mean_word_length': 2.4836065573770494, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '12481', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1376, 'n_words': 316}