ubu
10/02/2019, 9:52 AMViewModelBaseUseCaseabstract class BaseUseCase<out Type, in Params> where Type : Any {
    abstract suspend fun run(params: Params): Either<Throwable, Type>
    open operator fun invoke(
        scope: CoroutineScope,
        params: Params,
        onResult: (Either<Throwable, Type>) -> Unit = {}
    ) {
        val backgroundJob = scope.async { run(params) }
        scope.launch { onResult(backgroundJob.await()) }
    }
}open class SetupWallet(
    private val repository: AuthRepository
) : BaseUseCase<Unit, SetupWallet.Params>() {
    override suspend fun run(params: Params) = try {
        val wallet = repository.createWallet(
            path = params.path
        )
        repository.saveMnemonic(wallet.mnemonic).let {
            Either.Right(it)
        }
    } catch (e: Throwable) {
        Either.Left(e)
    }
    class Params(val path: String)
}ViewModelSetupWalletfun onSignUpClicked() {
        setupWallet.invoke(
            scope = viewModelScope,
            params = SetupWallet.Params(
                path = pathProvider.providePath()
            )
        ) { result ->
            result.either(
                fnL = {
                    throw IllegalStateException()
                },
                fnR = { navigation.accept(NavigationCommand.OpenCreateProfile) }
            )
        }
    }@Test
    fun `when sign-up button clicked, should setup wallet`() {
        val path = "path"
        stubProvidePath(path)
        setupWallet.stub {
            onBlocking { run(params = any()) } doReturn Either.Left(Exception("!"))
        }
        vm.onSignUpClicked()
    }SetupWalletIllegalStateException