package com.elpassion.intelijidea.common

import com.elpassion.intelijidea.util.mfFilename
import org.junit.Assert.assertEquals
import org.junit.Test

class MFCommandLineTest {

    @Test
    fun shouldGenerateCommandLineToExecute() {
        val commandLine = MFCommandLine(
                buildCommand = "./gradlew",
                taskName = "build")
        commandLine.verify()
    }

    @Test
    fun shouldGenerateProperCommandLineToExecute() {
        val commandLine = MFCommandLine(
                buildCommand = "gradle",
                taskName = "assembleDebug")
        commandLine.verify()
    }

    @Test
    fun shouldGenerateProperCommandLineWithCustomPathToExecute() {
        val commandLine = MFCommandLine(
                mfPath = "/customPath",
                buildCommand = "gradle",
                taskName = "build")
        commandLine.verify()
    }

    @Test
    fun shouldGenerateProperCommandLineWithWhiteSpacePathToExecute() {
        val commandLine = MFCommandLine(
                mfPath = "/White Spaced Path",
                buildCommand = "gradle",
                taskName = "build")
        commandLine.verify()
    }

    private fun MFCommandLine.verify() {
        val expectedParams = listOf(
                "${if (mfPath != null) "$mfPath/" else ""}$mfFilename",
                "$buildCommand $taskName"
        ).map { if (it.contains(" ")) "\"$it\"" else it }
        assertEquals("bash ${expectedParams.joinToString(separator = " ")}", commandLineString)
    }
}
package com.elpassion.intelijidea.common

import com.elpassion.intelijidea.util.mfFilename
import org.junit.Assert.assertEquals
import org.junit.Test

class MFCommandLineTest {

    @Test
    fun shouldGenerateCommandLineToExecute() {
        val commandLine = createCommandLine()
        commandLine.verify()
    }

    @Test
    fun shouldGenerateProperCommandLineToExecute() {
        val commandLine = createCommandLine(buildCommand = "gradle", taskName = "assembleDebug")
        commandLine.verify()
    }

    @Test
    fun shouldGenerateProperCommandLineWithCustomPathToExecute() {
        val commandLine = createCommandLine(mfPath = "/customPath")
        commandLine.verify()
    }

    @Test
    fun shouldGenerateProperCommandLineWithWhiteSpacePathToExecute() {
        val commandLine = createCommandLine(mfPath = "/White Spaced Path")
        commandLine.verify()
    }

    private fun MFCommandLine.verify() {
        val expectedParams = listOf(
                "${if (mfPath != null) "$mfPath/" else ""}$mfFilename",
                "$buildCommand $taskName"
        ).map { if (it.contains(" ")) "\"$it\"" else it }
        assertEquals("bash ${expectedParams.joinToString(separator = " ")}", commandLineString)
    }

    private fun createCommandLine(mfPath: String = "", buildCommand: String = "./gradlew", taskName: String = "build")
            = MFCommandLine(mfPath, buildCommand, taskName)
}
Add command line factory for test purpose
[Refactoring] Add command line factory for test purpose

elpassion/mainframer-intellij-plugin,elpassion/mainframer-intellij-plugin,elpassion/mainframer-intellij-plugin