Vivek Modi
07/05/2021, 1:51 PMviewModel.onDownloadErrorLiveData.observe(this, { consumable ->
some code
})Matt Thompson
07/05/2021, 8:30 PMcapture in a verify block or in an answers block. Then just manually invoke the observer.Vivek Modi
07/05/2021, 8:35 PMMatt Thompson
07/05/2021, 8:39 PM```lateinit var observer : Observer
every { mockLiveData.observe(any(), any()) } answers { observer = secondArg() as Observer }Matt Thompson
07/05/2021, 8:39 PMVivek Modi
07/15/2021, 4:15 PMprivate fun yo(){
viewModel.consentTag.observe(this, Observer { type ->
typeText.text = type
})
}
this is my functionVivek Modi
07/15/2021, 4:16 PMimport androidx.lifecycle.Observer
which import i need to useVivek Modi
07/15/2021, 4:17 PM@Test
fun `yo `() {
every { mockViewModel.consentTag.observe(any(), any()) } answers {
observer = secondArg() as Observer
}
}
it giving errorMatt Thompson
07/15/2021, 4:17 PMMatt Thompson
07/15/2021, 4:18 PMObserver<TypeHere>Vivek Modi
07/15/2021, 4:19 PMVivek Modi
07/15/2021, 4:20 PMVivek Modi
07/15/2021, 4:21 PMVivek Modi
07/15/2021, 4:22 PMMatt Thompson
07/15/2021, 4:22 PMas you also need to define the typeMatt Thompson
07/15/2021, 4:22 PMsecondArg takes a type argument, you could try putting it thereVivek Modi
07/15/2021, 4:24 PMVivek Modi
07/15/2021, 4:24 PMobserver = secondArg() as ConsentTypeVivek Modi
07/15/2021, 4:24 PMMatt Thompson
07/15/2021, 4:24 PMas Observer<ConsentType>Matt Thompson
07/15/2021, 4:26 PMobserve function is Observer<ConsentType> - kotlin allows you to write it as a lambda with SAM conversionVivek Modi
07/15/2021, 4:28 PMprivate fun yo(){
viewModel.consentTag.observe(this, Observer { type ->
typeText.text = type
})
}
how can i set value type in typeTextMatt Thompson
07/15/2021, 4:29 PMonChangedVivek Modi
07/15/2021, 4:34 PM@Test
fun `yo `() {
val value = ConsentType.GENERAL
every { mockViewModel.consentTag.observe(any(), any()) } answers {
observer = secondArg() as Observer<ConsentType>
}
observer.onChanged(value)
consentActivity.yo()
verify { mockTextView.tag = value }
}Vivek Modi
07/15/2021, 4:38 PMkotlin.UninitializedPropertyAccessException: lateinit property observer has not been initializedMatt Thompson
07/15/2021, 6:36 PMevery / answers works is that the answers block with be run every time the function inside of every gets called. so if this yo function is what calls it, you need to call it in order to initialize your observer varVivek Modi
07/15/2021, 6:46 PMyo at top of function ?