Last active
May 2, 2020 16:37
-
-
Save pranay1494/46616ffcf1a50660c02c2367c67cd47e 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 UserViewModelTestShould{ | |
@get:Rule | |
val rule = InstantTaskExecutorRule() | |
private lateinit var viewModel: UserViewModel | |
@Mock lateinit var repository: UserRepository | |
@Mock lateinit var observer: Observer<UserViewModel.DisplayData> | |
@Before | |
fun setUp(){ | |
MockitoAnnotations.initMocks(this) | |
viewModel = UserViewModel(repository) | |
viewModel.getData().observeForever(observer) | |
} | |
@Test | |
fun `test user data retrieved successfully`() = runBlockingTest{ | |
val username = "pranay1494" | |
val data = User().apply { name = "Pranay" } | |
Mockito.`when`(repository.fetchRepository(username)).thenReturn(data) | |
viewModel.fetchUserData(username) | |
Mockito.verify(observer,times(1)).onChanged(any()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment