Last active
March 22, 2020 15:47
-
-
Save mcatta/9c42af355b3bef09465d6088be2c5fac to your computer and use it in GitHub Desktop.
Test fetchDataViaCallback()
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 fetchDataViaCallback with an result`() { | |
val captureCallback = slot<(data: List<DataModel>) -> Unit>() | |
every { dataRepository.fetchData(capture(captureCallback)) } answers { | |
val fakeList = listOf(DataModel(1, "Value 1")) | |
captureCallback.captured.invoke(fakeList) | |
} | |
mainPresenter.fetchDataViaCallback() | |
val captureData = slot<List<UiDataModel>>() | |
verify(exactly = 1) { view.onResult(capture(captureData)) } | |
captureData.captured.let { res -> | |
assertNotNull(res) | |
assert(res.isNotEmpty()) | |
assertEquals("Value 1", res.first().value) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment