Created
October 5, 2021 20:01
-
-
Save brunogabriel/7e8fe17f99061e9b5aaafbb9f1567d7d to your computer and use it in GitHub Desktop.
Testes para o PostsViewModel
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 `should take posts and display it when call takePosts`() { | |
// given | |
val posts = listOf<Post>(mockk(), mockk()) | |
val observerDisplayingView = spyk<Observer<Int>>() | |
val displayingViewResults = mutableListOf<Int>() | |
val observerPostResult = spyk<Observer<List<Post>>>() | |
val postResults = mutableListOf<List<Post>>() | |
every { useCase.takePosts() } returns Single.just(posts) | |
viewModel.displayingView.observeForever(observerDisplayingView) | |
viewModel.postResult.observeForever(observerPostResult) | |
// when | |
viewModel.takePosts() | |
// then | |
verify { observerDisplayingView.onChanged(capture(displayingViewResults)) } | |
verify { observerPostResult.onChanged(capture(postResults)) } | |
assertThat(displayingViewResults).isEqualTo( | |
listOf( | |
PostsViewModel.DisplayingView.Loading.ordinal, | |
PostsViewModel.DisplayingView.Success.ordinal | |
) | |
) | |
assertThat(postResults.size).isEqualTo(1) | |
assertThat(postResults.first()).isEqualTo(posts) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment