Skip to content

Instantly share code, notes, and snippets.

@mcatta
Last active March 28, 2020 14:13
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 mcatta/760a0d1b508572b3791f27f7aaf7dd8e to your computer and use it in GitHub Desktop.
Save mcatta/760a0d1b508572b3791f27f7aaf7dd8e to your computer and use it in GitHub Desktop.
How mock a static method on a class
@Test
fun `test fetchData with a different behaviour of UUID generation`() {
val uuid = "my-fake-uuid"
mockkObject(MyUselessUtils)
every { MyUselessUtils.generateUUID() } returns uuid
every { dataRepository.fetchData() } returns listOf(DataModel(1, "Value"))
mainPresenter.fetchData()
val captureData = slot<List<UiDataModel>>()
verify(exactly = 1) { view.onResult(capture(captureData)) }
captureData.captured.let { res ->
assert(res.isNotEmpty())
assertEquals(uuid, res.first().uuid)
}
unmockkObject(MyUselessUtils)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment