jvmMain.tech.skot.core.test.SKDataMock.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of viewmodelTests Show documentation
Show all versions of viewmodelTests Show documentation
viewmodelTests description
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
var error:Exception? = 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() =error?.let { throw it } ?: internalManual?._current ?: throw errorNotSetMessage
override suspend fun update(): D {
return error?.let { throw it } ?: internalManual?.update() ?: throw errorNotSetMessage
}
override suspend fun fallBackValue(): D? {
return error?.let { throw it } ?: internalManual?.fallBackValue() ?: throw errorNotSetMessage
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy