feat(android): Create default OkHttpClient only when needed (#4411)

This commit is contained in:
Jaakko Malkki
2026-07-21 18:45:06 +03:00
committed by GitHub
parent d866b289cc
commit 63293b3b2e
2 changed files with 33 additions and 10 deletions

View File

@@ -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
)