<commit_before>package org.camunda.bpm.engine.test.fluent;

import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.cdi.impl.util.ProgrammaticBeanLookup;
import org.camunda.bpm.engine.fluent.FluentProcessEngine;
import org.camunda.bpm.engine.fluent.FluentProcessEngineImpl;
import org.camunda.bpm.engine.impl.test.TestHelper;
import org.camunda.bpm.engine.test.ProcessEngineRule;
import org.camunda.bpm.engine.test.ProcessEngineTestCase;
import org.camunda.bpm.engine.test.fluent.mocking.FluentMocks;
import org.camunda.bpm.engine.test.fluent.support.Classes;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

/**
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
public class FluentProcessEngineTestRule implements TestRule {

    private Object test;
    private FluentProcessEngine engine;

    public FluentProcessEngineTestRule(final Object test) {
        this.test = test;
        engine = getEngine();
    }

    @Override
    public Statement apply(final Statement statement, final Description description) {

        return new Statement() {

            @Override
            public void evaluate() throws Throwable {
                before();
                try {
                    statement.evaluate();
                } finally {
                    after();
                }
            }
        };

    }

    public void before() {
        FluentProcessEngineTests.before(engine);
        FluentMocks.before(test);
    }

    public void after() {
        FluentMocks.after(test);
        FluentProcessEngineTests.after();
    }

    protected FluentProcessEngine getEngine() {
        if (engine != null) {
            return engine;
        } else {
            try {
                final ProcessEngine processEngine = ProgrammaticBeanLookup.lookup(ProcessEngine.class);
                return new FluentProcessEngineImpl(processEngine);
            } catch (final ProcessEngineException e) {
            }
            if (test instanceof ProcessEngineTestCase) {
                return engine = new FluentProcessEngineImpl(TestHelper.getProcessEngine(((ProcessEngineTestCase)test).getConfigurationResource()));
            } else {
                try {
                    return engine = new FluentProcessEngineImpl(((ProcessEngineRule)Classes.getFieldByType(test.getClass(), ProcessEngineRule.class).get(
                            test)).getProcessEngine());
                } catch (final IllegalAccessException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }

}
<commit_msg>fluent tests do not require rules<commit_after>package org.camunda.bpm.engine.test.fluent;

import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.cdi.impl.util.ProgrammaticBeanLookup;
import org.camunda.bpm.engine.fluent.FluentProcessEngine;
import org.camunda.bpm.engine.fluent.FluentProcessEngineImpl;
import org.camunda.bpm.engine.impl.test.TestHelper;
import org.camunda.bpm.engine.test.ProcessEngineRule;
import org.camunda.bpm.engine.test.ProcessEngineTestCase;
import org.camunda.bpm.engine.test.fluent.mocking.FluentMocks;
import org.camunda.bpm.engine.test.fluent.support.Classes;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

/**
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
public class FluentProcessEngineTestRule implements TestRule {

    private Object test;
    private FluentProcessEngine engine = null;

    public FluentProcessEngineTestRule(final Object test) {
        this.test = test;
    }

    @Override
    public Statement apply(final Statement statement, final Description description) {

        return new Statement() {

            @Override
            public void evaluate() throws Throwable {
                before();
                try {
                    statement.evaluate();
                } finally {
                    after();
                }
            }
        };

    }

    public void before() {
        FluentProcessEngineTests.before(getEngine());
        FluentMocks.before(test);
    }

    public void after() {
        FluentMocks.after(test);
        FluentProcessEngineTests.after();
    }

    protected FluentProcessEngine getEngine() {
        if (engine != null) {
            return engine;
        } else {
            try {
                final ProcessEngine processEngine = ProgrammaticBeanLookup.lookup(ProcessEngine.class);
                return new FluentProcessEngineImpl(processEngine);
            } catch (final ProcessEngineException e) {
                // fallthrough
            }
            if (test instanceof ProcessEngineTestCase) {
                return engine = new FluentProcessEngineImpl(TestHelper.getProcessEngine(((ProcessEngineTestCase)test).getConfigurationResource()));
            } else {
                try {
                    ProcessEngineRule processEngineRule = (ProcessEngineRule)Classes.getFieldByType(test.getClass(), ProcessEngineRule.class).get(test);
                    if (processEngineRule == null) {
                        // TODO default config name only
                        processEngineRule = new ProcessEngineRule();
                    }

                    return engine = new FluentProcessEngineImpl(processEngineRule.getProcessEngine());
                } catch (final IllegalAccessException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.09213759213759214, 'fraction_numerical': 0.0, 'mean_word_length': 2.2942196531791907, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '2684796', 'n_tokens_mistral': 1496, 'n_tokens_neox': 1442, 'n_words': 278}