Skip to content

Instantly share code, notes, and snippets.

@inderisonline
Last active October 27, 2022 12:38
Show Gist options
  • Save inderisonline/c40cc0249521907ba187f3d9c77a3a2e to your computer and use it in GitHub Desktop.
Save inderisonline/c40cc0249521907ba187f3d9c77a3a2e to your computer and use it in GitHub Desktop.
MqttConnectTest demo code for higher order function as an argument
class HighOrderDemoTest {
private lateinit var highOrderDemo: HighOrderDemo
private var connectRemote: ConnectRemote = mockk(relaxed = true)
@Before
fun before() {
highOrderDemo = HighOrderDemo(
connectRemote
)
}
@Test
fun `test successful connection`() {
every { connectRemote.connect(captureLambda<(isConnected: Boolean) -> Unit>()) } answers {
lambda<(isConnected: Boolean) -> Unit>().captured.invoke(true)
}
highOrderDemo.connect {
assertEquals(it, true)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment