<commit_before>package com.elpassion.intelijidea.integration

import com.elpassion.intelijidea.configuration.MFConfigurationFactory
import com.elpassion.intelijidea.configuration.MFRunConfiguration
import com.elpassion.intelijidea.configuration.MFRunConfigurationData
import com.elpassion.intelijidea.configuration.MFRunConfigurationType
import com.elpassion.intelijidea.configuration.common.assertThrows
import com.intellij.execution.ExecutionException
import com.intellij.execution.executors.DefaultRunExecutor
import com.intellij.execution.runners.ExecutionEnvironmentBuilder
import com.intellij.openapi.util.io.FileUtil
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase
import java.io.File

class MFRunConfigurationExecutionTest : LightPlatformCodeInsightFixtureTestCase() {

    fun testShouldThrowExecutionExceptionWhenConfigurationDataIsNull() {
        assertThrows(ExecutionException::class.java) {
            buildProjectAndExecute(configurationData = null)
        }
    }

    fun testShouldThrowExecutionExceptionWhenToolNotFound() {
        assertThrows(ExecutionException::class.java) {
            val data = createConfigurationData()
            buildProjectAndExecute(configurationData = data)
        }
    }

    fun testShouldStartExecutionWithoutExceptionOnToolFoundInDefinedPath() {
        val data = createConfigurationData()
        createTool(path = data.mainframerPath)
        buildProjectAndExecute(configurationData = data)
    }

    private fun createTool(path: String?) {
        FileUtil.createTempFile(File(path), "mainframer", ".sh")
    }

    private fun createRunConfiguration(configurationData: MFRunConfigurationData?) =
            MFRunConfiguration(project, MFConfigurationFactory(MFRunConfigurationType()), "", {}).apply {
                data = configurationData
            }

    private fun createConfigurationData(): MFRunConfigurationData {
        with(FileUtil.createTempDirectory("", "mf")) {
            return MFRunConfigurationData(mainframerPath = absolutePath)
        }
    }

    private fun buildProjectAndExecute(configurationData: MFRunConfigurationData? = null) {
        val config = createRunConfiguration(configurationData)
        val executor = DefaultRunExecutor.getRunExecutorInstance()
        ExecutionEnvironmentBuilder.create(project, executor, config).buildAndExecute()
    }
}<commit_msg>[#42] [Refactoring] Change createTool to extension method<commit_after>package com.elpassion.intelijidea.integration

import com.elpassion.intelijidea.configuration.MFConfigurationFactory
import com.elpassion.intelijidea.configuration.MFRunConfiguration
import com.elpassion.intelijidea.configuration.MFRunConfigurationData
import com.elpassion.intelijidea.configuration.MFRunConfigurationType
import com.elpassion.intelijidea.configuration.common.assertThrows
import com.intellij.execution.ExecutionException
import com.intellij.execution.executors.DefaultRunExecutor
import com.intellij.execution.runners.ExecutionEnvironmentBuilder
import com.intellij.openapi.util.io.FileUtil
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase
import java.io.File

class MFRunConfigurationExecutionTest : LightPlatformCodeInsightFixtureTestCase() {

    fun testShouldThrowExecutionExceptionWhenConfigurationDataIsNull() {
        assertThrows(ExecutionException::class.java) {
            buildProjectAndExecute(configurationData = null)
        }
    }

    fun testShouldThrowExecutionExceptionWhenToolNotFound() {
        assertThrows(ExecutionException::class.java) {
            val data = createConfigurationData()
            buildProjectAndExecute(configurationData = data)
        }
    }

    fun testShouldStartExecutionWithoutExceptionOnToolFoundInDefinedPath() {
        val data = createConfigurationData().withToolFile()
        buildProjectAndExecute(configurationData = data)
    }

    private fun MFRunConfigurationData.withToolFile() = apply {
        FileUtil.createTempFile(File(mainframerPath), "mainframer", ".sh")
    }

    private fun createRunConfiguration(configurationData: MFRunConfigurationData?) =
            MFRunConfiguration(project, MFConfigurationFactory(MFRunConfigurationType()), "", {}).apply {
                data = configurationData
            }

    private fun createConfigurationData(): MFRunConfigurationData {
        with(FileUtil.createTempDirectory("", "mf")) {
            return MFRunConfigurationData(mainframerPath = absolutePath)
        }
    }

    private fun buildProjectAndExecute(configurationData: MFRunConfigurationData? = null) {
        val config = createRunConfiguration(configurationData)
        val executor = DefaultRunExecutor.getRunExecutorInstance()
        ExecutionEnvironmentBuilder.create(project, executor, config).buildAndExecute()
    }
}

{'fraction_non_alphanumeric': 0.07554179566563468, 'fraction_numerical': 0.000412796697626419, 'mean_word_length': 4.615295480880649, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1378126', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1197, 'n_words': 180}