Created
December 8, 2021 19:46
-
-
Save KwabenBerko/0109535bd85190ce410400cda2d5de07 to your computer and use it in GitHub Desktop.
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
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