0
 @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.

1
  • Please post your SharedViewModel class. Commented Sep 16, 2020 at 7:40

1 Answer 1

0

It seems as if you'd compare a String to some Event, which equals apples & pears.

It might rather be something alike:

sharedViewModel.clearNoteText.value.equals("Note Saved Successfully")

or:

sharedViewModel.clearNoteText.value == "Note Saved Successfully"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.