diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index cc61af4..41594c1 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -26,6 +26,8 @@ ktor = "2.3.7" kotlinx-serialization = "1.6.2" kover = "0.7.5" +kotlinx-coroutines = "1.7.3" + junit = "5.10.1" mockito-junit-jupiter = "5.8.0" mockito-kotlin = "5.2.1" @@ -37,7 +39,7 @@ touchlab-kmmbridge = "0.5.1" [libraries] -kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlin" } +kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" } ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" } ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" } @@ -49,6 +51,9 @@ ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negoti ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" } kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } + +kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" } + kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" } junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" } diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 13f994a..651048c 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -22,6 +22,7 @@ kotlin { commonMain.dependencies { // put your Multiplatform dependencies here implementation(libs.kotlinx.serialization.json) + implementation(libs.kotlinx.coroutines.core) implementation(libs.bundles.ktor.client) } @@ -35,6 +36,7 @@ kotlin { jvmTest.dependencies { implementation(project.dependencies.platform(libs.junit.bom)) + implementation(libs.kotlinx.coroutines.test) implementation(libs.bundles.jvm.test) } } diff --git a/shared/src/jvmTest/kotlin/com/tddworks/lemonsqueezy/api/internal/network/ktor/DefaultHttpRequesterTest.kt b/shared/src/jvmTest/kotlin/com/tddworks/lemonsqueezy/api/internal/network/ktor/DefaultHttpRequesterTest.kt index 83edac0..54dbf49 100644 --- a/shared/src/jvmTest/kotlin/com/tddworks/lemonsqueezy/api/internal/network/ktor/DefaultHttpRequesterTest.kt +++ b/shared/src/jvmTest/kotlin/com/tddworks/lemonsqueezy/api/internal/network/ktor/DefaultHttpRequesterTest.kt @@ -3,7 +3,7 @@ package com.tddworks.lemonsqueezy.api.internal.network.ktor import com.tddworks.lemonsqueezy.api.mockHttpClient import io.ktor.client.* import io.ktor.client.request.* -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test @@ -11,7 +11,7 @@ class DefaultHttpRequesterTest { private lateinit var httpClient: HttpClient @Test - fun `should return activation success when activated`() = runBlocking { + fun `should return activation success when activated`() = runTest { val mockResponse = """ { "activated": true, @@ -57,7 +57,7 @@ class DefaultHttpRequesterTest { } @Test - fun `should return activation error when not activated`() = runBlocking { + fun `should return activation error when not activated`() = runTest { val mockResponse = """ { "activated": false, diff --git a/shared/src/jvmTest/kotlin/com/tddworks/lemonsqueezy/api/license/LicenseKeysApiTest.kt b/shared/src/jvmTest/kotlin/com/tddworks/lemonsqueezy/api/license/LicenseKeysApiTest.kt index d272820..9227057 100644 --- a/shared/src/jvmTest/kotlin/com/tddworks/lemonsqueezy/api/license/LicenseKeysApiTest.kt +++ b/shared/src/jvmTest/kotlin/com/tddworks/lemonsqueezy/api/license/LicenseKeysApiTest.kt @@ -1,9 +1,9 @@ package com.tddworks.lemonsqueezy.api.license +import com.tddworks.lemonsqueezy.api.internal.network.ktor.HttpRequester import com.tddworks.lemonsqueezy.api.license.data.Instance import com.tddworks.lemonsqueezy.api.license.data.LicenseKey import com.tddworks.lemonsqueezy.api.license.data.Meta -import com.tddworks.lemonsqueezy.api.internal.network.ktor.HttpRequester import com.tddworks.lemonsqueezy.api.license.request.LicenseActivationRequest import com.tddworks.lemonsqueezy.api.license.request.LicenseDeactivationRequest import com.tddworks.lemonsqueezy.api.license.response.LicenseActivationErrorResponse @@ -12,7 +12,7 @@ import com.tddworks.lemonsqueezy.api.license.response.LicenseDeactivationRespons import io.ktor.client.request.* import io.ktor.http.* import io.ktor.util.reflect.* -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.mockito.Mockito.mock @@ -25,7 +25,7 @@ class LicenseKeysApiTest { private var requester: HttpRequester = mock() @Test - fun `should return deactivation success when deactivated`() = runBlocking { + fun `should return deactivation success when deactivated`() = runTest { val expectedResponse = LicenseDeactivationResponse( deactivated = true, error = null, @@ -80,7 +80,7 @@ class LicenseKeysApiTest { } @Test - fun `should return activation error when not activated`() = runBlocking { + fun `should return activation error when not activated`() = runTest { val responseJson = """ { "activated": false, @@ -156,7 +156,7 @@ class LicenseKeysApiTest { } @Test - fun `should return activation success when activated`() = runBlocking { + fun `should return activation success when activated`() = runTest { val responseJson = """ { "activated": true, diff --git a/shared/src/jvmTest/kotlin/com/tddworks/lemonsqueezy/api/user/UsersApiTest.kt b/shared/src/jvmTest/kotlin/com/tddworks/lemonsqueezy/api/user/UsersApiTest.kt index bc6cac8..7346e94 100644 --- a/shared/src/jvmTest/kotlin/com/tddworks/lemonsqueezy/api/user/UsersApiTest.kt +++ b/shared/src/jvmTest/kotlin/com/tddworks/lemonsqueezy/api/user/UsersApiTest.kt @@ -6,19 +6,19 @@ import com.tddworks.lemonsqueezy.api.user.response.UserResponse import io.ktor.client.request.* import io.ktor.http.* import io.ktor.util.reflect.* -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test -import org.mockito.Mockito import org.mockito.kotlin.argThat import org.mockito.kotlin.argumentCaptor +import org.mockito.kotlin.mock import org.mockito.kotlin.whenever class UsersApiTest { - private var requester: HttpRequester = Mockito.mock() + private var requester: HttpRequester = mock() @Test - fun `should return me when success`() = runBlocking { + fun `should return me when success`() = runTest { val httpRequestCaptor = argumentCaptor Unit>() val expectedResponse = UserResponse( type = "users",