feat(android): Create default OkHttpClient only when needed (#4411)
This commit is contained in:
@@ -5,6 +5,8 @@ import org.maplibre.android.utils.ConfigUtils
|
||||
import io.mockk.mockk
|
||||
import okhttp3.Call
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.maplibre.android.BaseTest
|
||||
@@ -17,10 +19,10 @@ class HttpRequestUtilTest : BaseTest() {
|
||||
fun replaceHttpClient() {
|
||||
MapLibreInjector.inject(mockk(relaxed = true), "", ConfigUtils.getMockedOptions())
|
||||
|
||||
assertEquals(HttpRequestImpl.DEFAULT_CLIENT, HttpRequestImpl.client)
|
||||
|
||||
val httpMock = mockk<Call.Factory>()
|
||||
HttpRequestUtil.setOkHttpClient(httpMock)
|
||||
|
||||
assertNull("Default HTTP client should not be initialized", HttpRequestImpl.defaultClient)
|
||||
assertEquals(
|
||||
"Http client should have set to the mocked client",
|
||||
httpMock,
|
||||
@@ -28,9 +30,10 @@ class HttpRequestUtilTest : BaseTest() {
|
||||
)
|
||||
|
||||
HttpRequestUtil.setOkHttpClient(null)
|
||||
assertNotNull("Default HTTP client should be initialized", HttpRequestImpl.defaultClient)
|
||||
assertEquals(
|
||||
"Http client should have been reset to the default client",
|
||||
HttpRequestImpl.DEFAULT_CLIENT,
|
||||
HttpRequestImpl.defaultClient,
|
||||
HttpRequestImpl.client
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user