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

jvmMain.tech.skot.core.test.SKDataMock.kt Maven / Gradle / Ivy

There is a newer version: 1.2.9
Show newest version
package tech.skot.core.test

import kotlinx.coroutines.flow.Flow
import tech.skot.model.DatedData
import tech.skot.model.SKData
import tech.skot.model.SKManualData

class SKDataMock(val name:String): SKData {

    private var internalManual:SKManualData? = null

    fun setValue(newVal:D) {
        val currentInternal = internalManual
        if (currentInternal == null) {
            internalManual = SKManualData(newVal)
        }
        else {
            currentInternal.value = newVal
        }
    }

    private val errorNotSetMessage: Exception by lazy {
        Exception("You have to set a value for SKData $name before it is watched")
    }

    override val flow: Flow?>
        get() = internalManual?.flow ?: throw errorNotSetMessage
    override val defaultValidity: Long
        get() = internalManual?.defaultValidity ?: throw errorNotSetMessage
    override val _current: DatedData?
        get() = internalManual?._current ?: throw errorNotSetMessage

    override suspend fun update(): D {
        return internalManual?.update() ?: throw errorNotSetMessage
    }

    override suspend fun fallBackValue(): D? {
        return internalManual?.fallBackValue() ?: throw errorNotSetMessage
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy