All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.chutneytesting.kotlin.synchronize.SynchronizeScenariosBuilder.kt Maven / Gradle / Ivy

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
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy