Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jeremyrempel/79bb987b2608045d425bcfe4476450f6 to your computer and use it in GitHub Desktop.
Save jeremyrempel/79bb987b2608045d425bcfe4476450f6 to your computer and use it in GitHub Desktop.
class FakeViewModelFactory(private val testviewModel: ViewModel) : ViewModelProvider.Factory {
override fun <T : ViewModel?> create(modelClass: Class<T>) = testviewModel as T
}
class FragFactoryFake(private val viewModel: ViewModel) : FragmentFactory() {
override fun instantiate(classLoader: ClassLoader, className: String): Fragment {
val fakeViewModelFactory = FakeViewModelFactory(viewModel)
return MainFragment(fakeViewModelFactory)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment