60 lines
1.7 KiB
Kotlin
60 lines
1.7 KiB
Kotlin
@file:Suppress("MemberVisibilityCanBePrivate")
|
|
|
|
package scaffold
|
|
|
|
import com.github.ajalt.clikt.output.CliktConsole
|
|
import io.mockk.clearMocks
|
|
import io.mockk.every
|
|
import io.mockk.mockk
|
|
import io.mockk.verify
|
|
import org.junit.jupiter.api.BeforeEach
|
|
import org.junit.jupiter.api.Test
|
|
import org.junit.jupiter.api.TestInstance
|
|
import org.junit.jupiter.params.ParameterizedTest
|
|
import org.junit.jupiter.params.provider.CsvSource
|
|
import strikt.api.expectThat
|
|
import strikt.assertions.isEqualTo
|
|
|
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
|
class PromptTest {
|
|
|
|
val console = mockk<CliktConsole>()
|
|
val prompt = Prompt(console)
|
|
|
|
@BeforeEach
|
|
fun beforeEach() = clearMocks(console)
|
|
|
|
@CsvSource(
|
|
value = [
|
|
"null, answer, answer",
|
|
"def, answer, answer",
|
|
"def, '', def"
|
|
]
|
|
)
|
|
@ParameterizedTest(name = "prompt string({argumentsWithNames})")
|
|
fun `prompt string`(default: String?, answer: String, expectedValue: String) {
|
|
every { console.promptForLine(any(), any()) } returns answer
|
|
expectThat(prompt.string("test", default)).isEqualTo(expectedValue)
|
|
}
|
|
|
|
@CsvSource(
|
|
value = [
|
|
"null, y, true",
|
|
"null, n, false",
|
|
|
|
"true, '', true",
|
|
"true, y, true",
|
|
"true, n, false",
|
|
|
|
"false, '', false",
|
|
"false, y, true",
|
|
"false, n, false",
|
|
]
|
|
)
|
|
@ParameterizedTest(name = "prompt boolean({argumentsWithNames})")
|
|
fun `prompt boolean`(default: Boolean?, answer: String, expectedValue: Boolean) {
|
|
every { console.promptForLine(any(), any()) } returns answer
|
|
expectThat(prompt.boolean("test", default)).isEqualTo(expectedValue)
|
|
}
|
|
|
|
} |