diff options
author | Florian Dold <florian@dold.me> | 2022-06-01 13:31:38 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-06-01 13:31:38 +0200 |
commit | a229b33997842a66295aa4d8dfb5dab6d2f769df (patch) | |
tree | 72031a742800ceaae337f04377fb052c91cc2068 /merchant-lib/src/test | |
parent | 1ef7ae77475f5dd99401a992a92f6c622b29c0a6 (diff) | |
download | taler-android-a229b33997842a66295aa4d8dfb5dab6d2f769df.tar.gz taler-android-a229b33997842a66295aa4d8dfb5dab6d2f769df.tar.bz2 taler-android-a229b33997842a66295aa4d8dfb5dab6d2f769df.zip |
use new annotation for polymorphic serialization
Diffstat (limited to 'merchant-lib/src/test')
-rw-r--r-- | merchant-lib/src/test/java/net/taler/merchantlib/MerchantApiTest.kt | 3 | ||||
-rw-r--r-- | merchant-lib/src/test/java/net/taler/merchantlib/MockHttpClient.kt | 12 |
2 files changed, 13 insertions, 2 deletions
diff --git a/merchant-lib/src/test/java/net/taler/merchantlib/MerchantApiTest.kt b/merchant-lib/src/test/java/net/taler/merchantlib/MerchantApiTest.kt index 8a45c9f..a89e2d3 100644 --- a/merchant-lib/src/test/java/net/taler/merchantlib/MerchantApiTest.kt +++ b/merchant-lib/src/test/java/net/taler/merchantlib/MerchantApiTest.kt @@ -20,6 +20,7 @@ import io.ktor.http.HttpStatusCode.Companion.NotFound import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.TestCoroutineDispatcher +import kotlinx.coroutines.test.UnconfinedTestDispatcher import net.taler.common.Amount import net.taler.common.ContractProduct import net.taler.common.ContractTerms @@ -33,7 +34,7 @@ import org.junit.Test @ExperimentalCoroutinesApi class MerchantApiTest { - private val api = MerchantApi(httpClient, TestCoroutineDispatcher()) + private val api = MerchantApi(httpClient, UnconfinedTestDispatcher()) private val merchantConfig = MerchantConfig( baseUrl = "http://example.net/instances/testInstance", apiKey = "apiKeyFooBar" diff --git a/merchant-lib/src/test/java/net/taler/merchantlib/MockHttpClient.kt b/merchant-lib/src/test/java/net/taler/merchantlib/MockHttpClient.kt index 880228c..32c7ee1 100644 --- a/merchant-lib/src/test/java/net/taler/merchantlib/MockHttpClient.kt +++ b/merchant-lib/src/test/java/net/taler/merchantlib/MockHttpClient.kt @@ -20,6 +20,7 @@ import io.ktor.client.HttpClient import io.ktor.client.engine.mock.MockEngine import io.ktor.client.engine.mock.MockEngineConfig import io.ktor.client.engine.mock.respond +import io.ktor.client.plugins.contentnegotiation.ContentNegotiation import io.ktor.http.ContentType.Application.Json import io.ktor.http.HttpStatusCode import io.ktor.http.Url @@ -27,6 +28,8 @@ import io.ktor.http.content.TextContent import io.ktor.http.fullPath import io.ktor.http.headersOf import io.ktor.http.hostWithPort +import io.ktor.serialization.kotlinx.json.json +import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json.Default.parseToJsonElement import org.junit.Assert.assertEquals @@ -36,13 +39,20 @@ object MockHttpClient { engine { addHandler { error("No response handler set") } } + expectSuccess = true + install(ContentNegotiation) { + json(Json { + encodeDefaults = false + ignoreUnknownKeys = true + }) + } } fun HttpClient.giveJsonResponse( url: String, expectedBody: String? = null, statusCode: HttpStatusCode = HttpStatusCode.OK, - jsonProducer: () -> String + jsonProducer: () -> String, ) { val httpConfig = engineConfig as MockEngineConfig httpConfig.requestHandlers.removeAt(0) |