Last active
July 13, 2022 08:49
-
-
Save Raiden18/8e5d6748bf08dcfee1b38714e2236642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private inner class ViewModelBuilder { | |
fun withLoadingData(): ViewModelBuilder { | |
// For RxJava it would be every { someInteractor.loadSomething() } returns Single.never() | |
coEvery { someInteractor.loadSomething() } coAnswers { | |
delay(1_000) | |
"result is not important" | |
} | |
return this | |
} | |
fun withDataLoadedWithError(throwable: Throwable): ViewModelBuilder { | |
coEvery { someInteractor.loadSomething() } coAnswers { throw throwable } | |
return this | |
} | |
fun withLoadedData(dataToLoad: String): ViewModelBuilder { | |
coEvery { someInteractor.loadSomething() } returns dataToLoad | |
return this | |
} | |
fun build(testScheduler: TestCoroutineScheduler): SomeViewModel { | |
val dispatechers = TestDispatchersProvider(testScheduler) | |
val viewModel = SomeViewModel(someInteractor, dispatechers) | |
return viewModel | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment