Skip to content

Instantly share code, notes, and snippets.

@KwabenBerko
Created December 8, 2021 19:46
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 KwabenBerko/0109535bd85190ce410400cda2d5de07 to your computer and use it in GitHub Desktop.
Save KwabenBerko/0109535bd85190ce410400cda2d5de07 to your computer and use it in GitHub Desktop.
class FlowViewModelTest {
@get:Rule
val rule = MainCoroutineRule()
private companion object {
val CHARACTERS = listOf('A', 'B', 'C')
}
private val repository = mock<CharacterRepository>().apply {
whenever(getCharacters()).thenReturn(flowOf(CHARACTERS))
}
private lateinit var viewModel: FlowViewModel
private lateinit var stateObserver: TestObserver<State>
@Test
fun `should load characters on subscribe`(){
rule.setup {
viewModel = FlowViewModel(repository)
stateObserver = viewModel.state.test()
}
rule.run {
stateObserver.assertValues(
State(isLoading = false, characters = emptyList()),
State(isLoading = true, characters = emptyList()),
State(isLoading = false, characters = CHARACTERS)
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment