matt tighe
01/10/2019, 1:00 AM@Test
fun `Submits app selection if selections can be made`() {
mainActivityViewModel.submitAppSelection(selectedApp)
runBlocking {
verify(mockAppsStartupFsm).submitEvent(AppSelected(selectedApp))
}
}
class MainActivityViewModel {
fun submitAppSelection(app: App) {
if (!selectionsCanBeMade()) return
lastSelectedApp = app
val coroutineScope = CoroutineScope(Dispatchers.Default)
coroutineScope.launch { appsStartupFsm.submitEvent(AppSelected(app)) }
}
}
AppsStartupFsm#submitEvent
is a suspending function.
Changing the runBlocking scope to be function level doesn’t seem to help. Is there something I’m missing with verification of suspending functions?Saiedmomen
01/18/2019, 7:10 PMSaiedmomen
01/18/2019, 7:10 PMSaiedmomen
01/18/2019, 7:11 PMmatt tighe
01/18/2019, 7:21 PMlaunch
may not actually launch the coroutine before verify
runs. Verification of suspending functions works, you just have to do it right. I’m still working on how to fix it in my own code. In the simplified example I posted it would need to be something like
suspend fun submitAppSelection(app: App) {
if (!selectionsCanBeMade()) return
lastSelectedApp = app
appsStartupFsm.submitEvent(AppSelected(app)
}
matt tighe
01/18/2019, 7:21 PMSaiedmomen
01/18/2019, 7:38 PMSaiedmomen
01/18/2019, 7:40 PM