Skip to content

Instantly share code, notes, and snippets.

@inderisonline
Last active October 27, 2022 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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