Jonathan Lennox
package 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) } } } }
A modern programming language that makes developers happier.