Last active
March 28, 2020 14:13
-
-
Save mcatta/760a0d1b508572b3791f27f7aaf7dd8e to your computer and use it in GitHub Desktop.
How mock a static method on a class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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