From dd0d3f3c12d11d43f21565f5a64fec602154c28e Mon Sep 17 00:00:00 2001 From: Lukasz Kalnik Date: Tue, 4 Jan 2022 14:10:33 +0100 Subject: [PATCH 1/2] Fix Arrow Retrofit adapter tests configuration --- .../either/ArrowEitherCallAdapterTest.kt | 28 ++++++++++--------- .../either/ArrowResponseEAdapterTest.kt | 28 ++++++++++--------- ...iClientTest.kt => TestSuspendApiClient.kt} | 2 +- 3 files changed, 31 insertions(+), 27 deletions(-) rename arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/retrofit/{SuspedApiClientTest.kt => TestSuspendApiClient.kt} (92%) diff --git a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt index 3089af5b731..ab2077e9468 100644 --- a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt +++ b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt @@ -5,7 +5,7 @@ import arrow.core.right import arrow.core.test.UnitSpec import arrow.retrofit.adapter.mock.ErrorMock import arrow.retrofit.adapter.mock.ResponseMock -import arrow.retrofit.adapter.retrofit.SuspedApiClientTest +import arrow.retrofit.adapter.retrofit.TestSuspendApiClient import io.kotest.matchers.shouldBe import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockWebServer @@ -15,21 +15,23 @@ import retrofit2.converter.gson.GsonConverterFactory class ArrowEitherCallAdapterTest : UnitSpec() { - private val server = MockWebServer() - - private val service: SuspedApiClientTest by lazy { - Retrofit.Builder() - .baseUrl(server.url("/")) - .addConverterFactory(GsonConverterFactory.create()) - .addCallAdapterFactory(EitherCallAdapterFactory.create()) - .build() - .create(SuspedApiClientTest::class.java) - } + private lateinit var server: MockWebServer + private lateinit var service: TestSuspendApiClient init { - beforeSpec { server.start() } - afterSpec { server.shutdown() } + beforeAny { + server = MockWebServer() + server.start() + service = Retrofit.Builder() + .baseUrl(server.url("/")) + .addConverterFactory(GsonConverterFactory.create()) + .addCallAdapterFactory(EitherCallAdapterFactory.create()) + .build() + .create(TestSuspendApiClient::class.java) + } + + afterAny { server.shutdown() } "should return ResponseMock for 200 with valid JSON" { server.enqueue(MockResponse().setBody("""{"response":"Arrow rocks"}""")) diff --git a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt index 9681c76704f..d7a4eb72fd4 100644 --- a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt +++ b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt @@ -5,7 +5,7 @@ import arrow.core.right import arrow.core.test.UnitSpec import arrow.retrofit.adapter.mock.ErrorMock import arrow.retrofit.adapter.mock.ResponseMock -import arrow.retrofit.adapter.retrofit.SuspedApiClientTest +import arrow.retrofit.adapter.retrofit.TestSuspendApiClient import io.kotest.matchers.shouldBe import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockWebServer @@ -15,21 +15,23 @@ import retrofit2.converter.gson.GsonConverterFactory class ArrowResponseEAdapterTest : UnitSpec() { - private val server = MockWebServer() - - private val service: SuspedApiClientTest by lazy { - Retrofit.Builder() - .baseUrl(server.url("/")) - .addConverterFactory(GsonConverterFactory.create()) - .addCallAdapterFactory(EitherCallAdapterFactory.create()) - .build() - .create(SuspedApiClientTest::class.java) - } + private lateinit var server: MockWebServer + private lateinit var service: TestSuspendApiClient init { - beforeSpec { server.start() } - afterSpec { server.shutdown() } + beforeAny { + server = MockWebServer() + server.start() + service = Retrofit.Builder() + .baseUrl(server.url("/")) + .addConverterFactory(GsonConverterFactory.create()) + .addCallAdapterFactory(EitherCallAdapterFactory.create()) + .build() + .create(TestSuspendApiClient::class.java) + } + + afterAny { server.shutdown() } "should return ResponseMock for 200 with valid JSON" { server.enqueue(MockResponse().setBody("""{"response":"Arrow rocks"}""")) diff --git a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/retrofit/SuspedApiClientTest.kt b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/retrofit/TestSuspendApiClient.kt similarity index 92% rename from arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/retrofit/SuspedApiClientTest.kt rename to arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/retrofit/TestSuspendApiClient.kt index d884ceed91d..254c52ebdd2 100644 --- a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/retrofit/SuspedApiClientTest.kt +++ b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/retrofit/TestSuspendApiClient.kt @@ -6,7 +6,7 @@ import arrow.retrofit.adapter.mock.ErrorMock import arrow.retrofit.adapter.mock.ResponseMock import retrofit2.http.GET -interface SuspedApiClientTest { +interface TestSuspendApiClient { @GET("/") suspend fun getEither(): Either From 5d499b7a51b5fe6c2053db8bc262fc685bcb8079 Mon Sep 17 00:00:00 2001 From: Lukasz Kalnik Date: Tue, 4 Jan 2022 14:12:11 +0100 Subject: [PATCH 2/2] Rename test client to SuspendApiTestClient --- .../retrofit/adapter/either/ArrowEitherCallAdapterTest.kt | 6 +++--- .../retrofit/adapter/either/ArrowResponseEAdapterTest.kt | 6 +++--- .../{TestSuspendApiClient.kt => SuspendApiTestClient.kt} | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) rename arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/retrofit/{TestSuspendApiClient.kt => SuspendApiTestClient.kt} (92%) diff --git a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt index ab2077e9468..a1c16bd47c5 100644 --- a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt +++ b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowEitherCallAdapterTest.kt @@ -5,7 +5,7 @@ import arrow.core.right import arrow.core.test.UnitSpec import arrow.retrofit.adapter.mock.ErrorMock import arrow.retrofit.adapter.mock.ResponseMock -import arrow.retrofit.adapter.retrofit.TestSuspendApiClient +import arrow.retrofit.adapter.retrofit.SuspendApiTestClient import io.kotest.matchers.shouldBe import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockWebServer @@ -16,7 +16,7 @@ import retrofit2.converter.gson.GsonConverterFactory class ArrowEitherCallAdapterTest : UnitSpec() { private lateinit var server: MockWebServer - private lateinit var service: TestSuspendApiClient + private lateinit var service: SuspendApiTestClient init { @@ -28,7 +28,7 @@ class ArrowEitherCallAdapterTest : UnitSpec() { .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(EitherCallAdapterFactory.create()) .build() - .create(TestSuspendApiClient::class.java) + .create(SuspendApiTestClient::class.java) } afterAny { server.shutdown() } diff --git a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt index d7a4eb72fd4..36f45a90995 100644 --- a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt +++ b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/either/ArrowResponseEAdapterTest.kt @@ -5,7 +5,7 @@ import arrow.core.right import arrow.core.test.UnitSpec import arrow.retrofit.adapter.mock.ErrorMock import arrow.retrofit.adapter.mock.ResponseMock -import arrow.retrofit.adapter.retrofit.TestSuspendApiClient +import arrow.retrofit.adapter.retrofit.SuspendApiTestClient import io.kotest.matchers.shouldBe import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockWebServer @@ -16,7 +16,7 @@ import retrofit2.converter.gson.GsonConverterFactory class ArrowResponseEAdapterTest : UnitSpec() { private lateinit var server: MockWebServer - private lateinit var service: TestSuspendApiClient + private lateinit var service: SuspendApiTestClient init { @@ -28,7 +28,7 @@ class ArrowResponseEAdapterTest : UnitSpec() { .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(EitherCallAdapterFactory.create()) .build() - .create(TestSuspendApiClient::class.java) + .create(SuspendApiTestClient::class.java) } afterAny { server.shutdown() } diff --git a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/retrofit/TestSuspendApiClient.kt b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/retrofit/SuspendApiTestClient.kt similarity index 92% rename from arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/retrofit/TestSuspendApiClient.kt rename to arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/retrofit/SuspendApiTestClient.kt index 254c52ebdd2..f44336b4ae8 100644 --- a/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/retrofit/TestSuspendApiClient.kt +++ b/arrow-libs/core/arrow-core-retrofit/src/test/kotlin/arrow/retrofit/adapter/retrofit/SuspendApiTestClient.kt @@ -6,7 +6,7 @@ import arrow.retrofit.adapter.mock.ErrorMock import arrow.retrofit.adapter.mock.ResponseMock import retrofit2.http.GET -interface TestSuspendApiClient { +interface SuspendApiTestClient { @GET("/") suspend fun getEither(): Either