Skip to content

Instantly share code, notes, and snippets.

@LordRaydenMK
Created January 9, 2021 09:45
Show Gist options
  • Save LordRaydenMK/5c0f5d0cf061e993ea48adbb052429e6 to your computer and use it in GitHub Desktop.
Save LordRaydenMK/5c0f5d0cf061e993ea48adbb052429e6 to your computer and use it in GitHub Desktop.
Tests part v1
@Test
fun `execute - first call succeeds, one failed call to #2 - one full item, one item with default value`() {
val items = listOf("Item 1" to "https://item1.jpg", "Item 2" to "invalid url")
val service = successService(items) // Fake implementation of a retrofit service, always returns success
val viewModel = ViewModel(service)
val expected = listOf(
ViewEntity("Item 1", "https://item1.jpg".toHttpUrl()),
ViewEntity("Item 2", null)
)
viewModel.state
.test()
.also { viewModel.execute() }
.awaitCount(2) // (0) Loading, (1) Content
.assertValueAt(1, Content(expected))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment