Davide Giuseppe Farella
02/28/2019, 7:26 AMmockk / verify
a lambda?
Looks like
val observer = mockk<(Int) -> Unit>()
observer( 1)
verify { observer( 1 ) }
Is not working.
Tbh I didn't test exactly that code, I was trying within an Android LiveData, but replacing the mockk with a real lambda i can see right output printed in the console. Same with spy
oleksiyp
02/28/2019, 7:27 AMoleksiyp
02/28/2019, 7:28 AMoleksiyp
02/28/2019, 7:28 AMDavide Giuseppe Farella
02/28/2019, 7:31 AMval liveData = MutableLiveData<Int>()
val observer = mockk<(Int) -> Unit>()
val lifecycleOwner = mockk<LifecycleOwner>( relaxed = true )
val lifecycle = LifecycleRegistry( lifecycleOwner )
lifecycle.handleLifecycleEvent( Lifecycle.Event.ON_RESUME )
liveData.observe( lifecycleOwner, observer )
liveData.value = 1
verify( exactly = 1 ) { observer( 1 ) }
Davide Giuseppe Farella
02/28/2019, 7:32 AMverify
says observer( 1 )
has not been called, but replacing the mock with { println( it ) }
I can see 1 printed in the consoleDavide Giuseppe Farella
02/28/2019, 7:34 AM