Skip to content

Instantly share code, notes, and snippets.

@ferPrieto
Created November 19, 2019 16:12
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 ferPrieto/7004d4a7768ae0ce51765b25c60b22db to your computer and use it in GitHub Desktop.
Save ferPrieto/7004d4a7768ae0ce51765b25c60b22db to your computer and use it in GitHub Desktop.
const val BASE_URL = "http://127.0.0.1"
class TestConfigurationBuilder {
private lateinit var baseUrl: String
init {
testBaseUrl()
}
fun testBaseUrl() {
baseUrl = "$BASE_URL:${BuildConfig.PORT}"
}
fun inject() {
appComponent {
networkModule(NetworkModule(baseUrl))
}.inject(requireTestedApplication())
}
}
fun injectTestConfiguration(block: TestConfigurationBuilder.() -> Unit) {
TestConfigurationBuilder().apply(block).inject()
}
private fun appComponent(block: DaggerAppComponent.Builder.() -> Unit = {}): AppComponent =
DaggerAppComponent.builder().apply(block).build()
private fun requireTestedApplication() =
(InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as JokesApp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment