main.kotlin.ch.tutteli.atrium.logic.creating.impl.RootExpectOptionsChooserImpl.kt Maven / Gradle / Ivy
package ch.tutteli.atrium.logic.creating.impl
import ch.tutteli.atrium.core.ExperimentalNewExpectTypes
import ch.tutteli.atrium.creating.ComponentFactory
import ch.tutteli.atrium.creating.ComponentFactoryContainer
import ch.tutteli.atrium.creating.ExperimentalComponentFactoryContainer
import ch.tutteli.atrium.creating.RootExpectOptions
import ch.tutteli.atrium.logic.creating.RootExpectBuilder
import ch.tutteli.atrium.reporting.translating.Translatable
import kotlin.reflect.KClass
@ExperimentalComponentFactoryContainer
@ExperimentalNewExpectTypes
class RootExpectOptionsChooserImpl : RootExpectBuilder.OptionsChooser {
private var description: Translatable? = null
private var representationInsteadOfSubject: ((T) -> Any)? = null
private var components = mutableMapOf, ComponentFactory>()
private var chainedComponents = mutableMapOf, Sequence>()
override fun withVerb(verb: Translatable) {
this.description = verb
}
override fun withRepresentation(representationProvider: (T) -> Any) {
this.representationInsteadOfSubject = representationProvider
}
@ExperimentalComponentFactoryContainer
override fun withComponent(kClass: KClass, factory: (ComponentFactoryContainer) -> I) {
components[kClass] = ComponentFactory(factory, producesSingleton = false)
}
@ExperimentalComponentFactoryContainer
override fun withSingletonComponent(kClass: KClass, factory: (ComponentFactoryContainer) -> I) {
components[kClass] = ComponentFactory(factory, producesSingleton = true)
}
@ExperimentalComponentFactoryContainer
override fun prependChainedComponents(kClass: KClass, factories: Sequence) {
chainedComponents[kClass] = factories
}
fun build(): RootExpectOptions =
RootExpectOptions(
description,
representationInsteadOfSubject,
ComponentFactoryContainer.createIfNotEmpty(components, chainedComponents)
)
}