@Before
fun setUp() {
val compositeDisposable = CompositeDisposable()
testScheduler = TestScheduler()
val testSchedulerProvider = TestSchedulerProvider(testScheduler)
sharedViewModel = SharedViewModel(
testSchedulerProvider,
compositeDisposable,
networkHelper,
repository, notesRepository, userPreferences
)
sharedViewModel.noteSaving.observeForever(
noteSavingObserver
)
sharedViewModel.clearNoteText.observeForever(clearNoteTextObserver)
}
@Test
fun givenServerResponse200_whenNotesSaved_shouldclearTextField() {
val notes = "testNote"
val latitude = 3.62176
val longitude = -7.932457
sharedViewModel.notesField.value = notes
sharedViewModel.latLongField.value =
LocationModel(latitude, longitude)
sharedViewModel.currentLocation.value = "test location"
val newNote = Notes(latitude, longitude, notes, userPreferences.getUserId())
doReturn(true)
.`when`(networkHelper)
.isNetworkConnected()
doReturn(Single.just(true))
.`when`(notesRepository).addNotes(newNote)
assert(sharedViewModel.clearNoteText.value == Event("Note Saved Successfully"))
sharedViewModel.addNote()
testScheduler.triggerActions()
}
I am not able to assert a statement which is getting failed for some reason though I have mocked the requirements. I couldn't identify the reason
Any help would be appreciated.