From 4ba933eed8a4d56785681b3254c7d83dce26de17 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Wed, 8 Nov 2023 22:15:53 +0500 Subject: [PATCH] Update ArrowEitherCallAdapterTest.kt (#3278) * Update ArrowEitherCallAdapterTest.kt * Update ArrowEitherCallAdapterTest.kt --- .../either/ArrowEitherCallAdapterTest.kt | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) 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 b6f8f902f18..247a390a735 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,20 +5,21 @@ import arrow.core.right import arrow.retrofit.adapter.mock.ErrorMock import arrow.retrofit.adapter.mock.ResponseMock import arrow.retrofit.adapter.retrofit.SuspendApiTestClient -import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockWebServer import okhttp3.mockwebserver.SocketPolicy import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class ArrowEitherCallAdapterTest : StringSpec({ +class ArrowEitherCallAdapterTest { lateinit var server: MockWebServer lateinit var service: SuspendApiTestClient - beforeAny { + @Test fun beforeAny = runTime { server = MockWebServer() server.start() service = Retrofit.Builder() @@ -29,9 +30,9 @@ class ArrowEitherCallAdapterTest : StringSpec({ .create(SuspendApiTestClient::class.java) } - afterAny { server.shutdown() } + @Test fun afterAny = runTime { server.shutdown() } - "should return ResponseMock for 200 with valid JSON" { + @Test fun shouldReturnResponseMockFor200WithValidJson() = runTest { server.enqueue(MockResponse().setBody("""{"response":"Arrow rocks"}""")) val body = service.getEither() @@ -39,7 +40,7 @@ class ArrowEitherCallAdapterTest : StringSpec({ body shouldBe ResponseMock("Arrow rocks").right() } - "should return Unit when service method returns Unit and null body received" { + @Test fun shouldReturnUnitWhenServiceMethodReturnsUnitAndNullBodyReceived() = runTest { server.enqueue(MockResponse().setResponseCode(204)) val body = service.postSomething("Sample string") @@ -47,7 +48,7 @@ class ArrowEitherCallAdapterTest : StringSpec({ body shouldBe Unit.right() } - "should return Unit when service method returns Unit and JSON body received" { + @Test fun shouldReturnUnitWhenServiceMethodReturnsUnitAndJsonBodyReceived() = runTest { server.enqueue(MockResponse().setBody("""{"response":"Arrow rocks"}""")) val body = service.postSomething("Sample string") @@ -55,7 +56,7 @@ class ArrowEitherCallAdapterTest : StringSpec({ body shouldBe Unit.right() } - "should return ErrorMock for 400 with valid JSON" { + @Test fun shouldReturnErrorMockFor400WithvalidJson() = runTest { server.enqueue(MockResponse().setBody("""{"errorCode":666}""").setResponseCode(400)) val body = service.getEither() @@ -63,7 +64,7 @@ class ArrowEitherCallAdapterTest : StringSpec({ body shouldBe ErrorMock(666).left() } - "should throw for 200 with invalid JSON" { + @Test fun shouldThrowFor200WithInvalidJson() = runTest { server.enqueue(MockResponse().setBody("""not a valid JSON""")) val body = runCatching { service.getEither() } @@ -71,7 +72,7 @@ class ArrowEitherCallAdapterTest : StringSpec({ body.isFailure shouldBe true } - "should throw for 400 and invalid JSON" { + @Test fun shouldThrowFor400AndInvalidJson() = runTest { server.enqueue(MockResponse().setBody("""not a valid JSON""").setResponseCode(400)) val body = runCatching { service.getEither() } @@ -79,11 +80,11 @@ class ArrowEitherCallAdapterTest : StringSpec({ body.isFailure shouldBe true } - "should throw when server disconnects" { + @Test fun shouldThrowWhenServerDisconnects() = runTest { server.enqueue(MockResponse().apply { socketPolicy = SocketPolicy.DISCONNECT_AFTER_REQUEST }) val body = runCatching { service.getEither() } body.isFailure shouldBe true } -}) +}