Jonathan Lennox
09/29/2023, 3:47 PMpackage org.example
import io.kotest.core.spec.style.ShouldSpec
import io.kotest.matchers.shouldBe
import io.mockk.every
import io.mockk.spyk
@JvmInline
value class LongWrapper(val value: Long)
class StateHolder() {
var state = -1L
fun setState(v: LongWrapper?) {
state = v?.value ?: -1L
}
fun getState(): LongWrapper? {
return if (state < 0) { null } else {
LongWrapper(state)
}
}
}
class MockTest: ShouldSpec() {
init {
context("Mocking a function") {
should("work correctly") {
val mockObj = spyk<StateHolder>()
every { mockObj.getState() } returns LongWrapper(42)
mockObj.getState() shouldBe LongWrapper(42)
}
}
}
}