Skip to content

Instantly share code, notes, and snippets.

@wangerekaharun
Created November 26, 2020 19:58
Show Gist options
  • Save wangerekaharun/30afc1d45367feb86b3cc13750e1730c to your computer and use it in GitHub Desktop.
Save wangerekaharun/30afc1d45367feb86b3cc13750e1730c to your computer and use it in GitHub Desktop.
import com.android254.droidconKE2020.feedback.ui.viewmodels.EventFeedbackViewModel
import com.android254.droidconKE2020.repository.Data
import com.android254.droidconKE2020.repository.feedback.EventFeedbackRepository
import com.android254.droidconKE2020.test_utils.BaseViewModelTest
import com.jraska.livedata.test
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import org.junit.Before
import org.junit.Test
class EventFeedbackViewModelTest : BaseViewModelTest() {
private val eventFeedbackRepository = mockk<EventFeedbackRepository>()
lateinit var eventFeedbackViewModel: EventFeedbackViewModel
@Before
fun setup(){
eventFeedbackViewModel = EventFeedbackViewModel(eventFeedbackRepository)
}
@Test
fun `test event feedback is submitted successfully`(){
coEvery { eventFeedbackRepository.sendEventFeedback("Awesome", 5) } returns Data.Success("Feedback sent successfully, Thank you")
eventFeedbackViewModel.sendEventFeedback("Awesome", 5)
coVerify { eventFeedbackViewModel.sendEventFeedback("Awesome", 5) }
eventFeedbackViewModel.submitFeedback.test().assertValue(Data.Success("Feedback sent successfully, Thank you"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment