Skip to content

Commit

Permalink
Remove suspend keyword from getBaseUrl function #ANDROID-15254 (#23)
Browse files Browse the repository at this point in the history
* remove suspend keyword from getBaseUrl function #ANDROID-15254

* fix provideMockApiClient #ANDROID-15254
  • Loading branch information
juangardi21 authored Oct 2, 2024
1 parent 3c26f86 commit 2b2d2a0
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@ import com.telefonica.mock.MockHelper
import com.telefonica.mocks.BuildConfig
import com.telefonica.mocks.common.Environment
import com.telefonica.mocks.data.backend.BackendRepository
import com.telefonica.mocks.di.IoDispatcher
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
import javax.inject.Inject

open class InitBackendUrl @Inject constructor(
private val mockHelper: MockHelper,
private val backendRepository: BackendRepository,
@IoDispatcher private val dispatcher: CoroutineDispatcher,
) {

open suspend operator fun invoke() = withContext(dispatcher) {
open operator fun invoke() {
backendRepository.backendUrl = when (BuildConfig.DEFAULT_ENVIRONMENT == Environment.DEMO) {
true -> mockHelper.getBaseUrl()
false -> BuildConfig.DEFAULT_ENVIRONMENT.baseUrl
Expand Down
2 changes: 1 addition & 1 deletion mock/src/main/java/com/telefonica/mock/MockHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MockHelper(context: Context) {
mockApiClient.stopServer()
}

suspend fun getBaseUrl(): String = mockApiClient.getBaseUrl()
fun getBaseUrl(): String = mockApiClient.getBaseUrl()

fun setUp(
port: Int = 0,
Expand Down
7 changes: 1 addition & 6 deletions mock/src/main/java/com/telefonica/mock/MockedServer.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.telefonica.mock

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
import okhttp3.mockwebserver.Dispatcher
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
Expand All @@ -11,7 +9,6 @@ import okhttp3.tls.HeldCertificate
import javax.inject.Inject

open class MockedServer @Inject constructor(
private val coroutineDispatcher: CoroutineDispatcher,
private val mockWebServer: MockWebServer,
private val responseDispatcher: ResponseDispatcher,
) {
Expand All @@ -31,9 +28,7 @@ open class MockedServer @Inject constructor(
mockWebServer.shutdown()
}

suspend fun getBaseUrl(): String = withContext(coroutineDispatcher) {
mockWebServer.url("/").toString()
}
fun getBaseUrl(): String = mockWebServer.url("/").toString()

internal fun enqueue(requestInfo: RequestInfo, mockedResponse: MockedResponse) {
responseDispatcher.enqueue(requestInfo, mockedResponse)
Expand Down
2 changes: 1 addition & 1 deletion mock/src/main/java/com/telefonica/mock/di/MockApiModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ class MockApiModule(private val context: Context) {
fun provideMockApiClient(
mockWebServer: MockWebServer,
responseDispatcher: ResponseDispatcher,
): MockedServer = MockedServer(Dispatchers.IO, mockWebServer, responseDispatcher)
): MockedServer = MockedServer(mockWebServer, responseDispatcher)
}

0 comments on commit 2b2d2a0

Please sign in to comment.