com.chutneytesting.kotlin.synchronize.SynchronizeScenariosBuilder.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of chutney-kotlin-dsl Show documentation
Show all versions of chutney-kotlin-dsl Show documentation
Generates Chutney scenarios using Kotlin.
The newest version!
package com.chutneytesting.kotlin.synchronize
import com.chutneytesting.kotlin.annotations.Scenario
import com.chutneytesting.kotlin.dsl.ChutneyScenario
import com.chutneytesting.kotlin.util.ClassGraphUtil
import kotlin.reflect.KFunction
/**
* Cosmetic to create a list of scenarios
*/
class SynchronizeScenariosBuilder {
var scenarios: List = mutableListOf()
companion object {
fun searchScenarios(packageName: String): SynchronizeScenariosBuilder.() -> Unit = {
ClassGraphUtil.findAllAnnotatedFunctions(packageName, Scenario::class).forEach { scenario: KFunction<*> ->
+scenario
}
}
}
operator fun ChutneyScenario.unaryPlus() {
scenarios = scenarios + this
}
operator fun List.unaryPlus() {
scenarios = scenarios + this
}
operator fun KFunction.unaryPlus() {
scenarios = scenarios +
(this.call()?.let {
when (it) {
is ChutneyScenario -> listOf(it)
is List<*> -> it.filterIsInstance()
else -> throw UnsupportedOperationException()
}
})!!
}
operator fun ChutneyScenario.unaryMinus() {
// scenarios = scenarios - this
// cosmetic to ignore scenario
}
}