I have created a module httpClientModule i.e.
val httpClientModule = module {
single(named(OK_HTTP_CLIENT)) { (sslSocketFactory: SSLSocketFactory?) ->
RetrofitFactory.buildHttpClient(sslSocketFactory = sslSocketFactory)
}
}
In the app there are some requests that needs to have a SSLSocketFactory and others that doesn't need for the SSLSocketFactory i.e.
request that needs SSLSocketFactory
fun buildHttpClientWithCertificate(): OkHttpClient {
return get(named(OK_HTTP_CLIENT)) {
parametersOf(playerLegacy.getOpVaultSSLSocketFactory())
}
}
request that doesn't need SSLSocketFactory
fun buildOkHttpClient(): OkHttpClient =
get(named(OK_HTTP_CLIENT)) { parametersOf(null) }
I am wondering if there is a way to test with Unit tests or functional tests to be sure that when we do a request with the SSLSocketFactory the okHttp instance use the given one ?
Same thing When there is no need for the SSLSocketFactory, the same okHttp instance created doesn't use the SSLSocketFactory instead it will use the null value given in the parametersOf ?
Thanks for your help 馃憤
To me this approach is not the way to go. If you have requests that require a (certain) SSLSocketfactory and others don't, than you seem to have two logically different setups. Indeed, OkHttp's client is immutable and you can't just live switch.
Instead, I suggest you set up 2 (named) instances of OkHttp, one with and one without the ssl factory, and use them appropriatedly in your app. That also solves your problem of having to test if the paramter given is the correct one - there will be no parameter, but only the (correct) OkHttp client instance.
Most helpful comment
To me this approach is not the way to go. If you have requests that require a (certain) SSLSocketfactory and others don't, than you seem to have two logically different setups. Indeed, OkHttp's client is immutable and you can't just live switch.
Instead, I suggest you set up 2 (named) instances of OkHttp, one with and one without the ssl factory, and use them appropriatedly in your app. That also solves your problem of having to test if the paramter given is the correct one - there will be no parameter, but only the (correct) OkHttp client instance.