Last active
August 10, 2020 16:23
-
-
Save catalinghita8/c46b3d2b0ddc31109f40c5d18cca131a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 DataViewModelTest { | |
| @Mock | |
| lateinit var mockedDataSource: DataSource // Our mocked dependency | |
| lateinit var dataViewModel: DataViewModel | |
| @Before | |
| fun setup() { | |
| dataViewModel = DataViewModel(mockedDataSource) // This will now work! | |
| } | |
| fun testCorrectCall() { | |
| // Let's first tell Mockito what our mocked dependency should return when queried | |
| Mockito.`when`(mockedDataSource.getCachedData()).thenReturn("Mocked json value") | |
| // Let's trigger the action on the ViewModel | |
| dataViewModel.getCachedData() | |
| // And finally let's test that our ViewModel called the right methods on its dependency | |
| Mockito.verify(mockedDataSource).getCachedData() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment