Skip to content

Instantly share code, notes, and snippets.

@BenHenning
Created October 25, 2019 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenHenning/d648b73e2cb500a8a135bc2e2398287f to your computer and use it in GitHub Desktop.
Save BenHenning/d648b73e2cb500a8a135bc2e2398287f to your computer and use it in GitHub Desktop.
@Inject lateinit var seedProvider: SeedProvider
@Test
fun testSomething() {
// Set the random seed after injection, but before the seed is provided (may require changes in the underlying controller, see note below).
seedProvider.seed = 1234L
}
@Singleton
inner class SeedProvider @Inject constructor() {
var seed: Long = 0L
}
@Module
class TestModule {
@Provides
@QuestionTrainingSeed
// NOTE TO READER: This is an unscoped value, so each time the class containing it is constructed this will be called again.
// Whether you can change the seed mid-test depends on whether the downstream components also can be recreated each time, or
// if they are Singleton scoped.
fun provideQuestionTrainingSeed(seedProvider: SeedProvider): Long {
return seedProvider.seed
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment