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 cc43ff7d359..4d3d2c4ca16 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,20 +5,24 @@ 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.AfterTest +import kotlin.test.BeforeTest +import kotlin.test.Test +import kotlinx.coroutines.test.runTest -class ArrowResponseEAdapterTest : StringSpec({ +class ArrowResponseEAdapterTest { lateinit var server: MockWebServer lateinit var service: SuspendApiTestClient - beforeAny { + @BeforeTest + fun initialize() { server = MockWebServer() server.start() service = Retrofit.Builder() @@ -29,9 +33,13 @@ class ArrowResponseEAdapterTest : StringSpec({ .create(SuspendApiTestClient::class.java) } - afterAny { server.shutdown() } - - "should return ResponseMock for 200 with valid JSON" { + @AfterTest + fun shutdown() { + server.shutdown() + } + + @Test + fun shouldReturnResponseMockFor200WithValidJson() = runTest { server.enqueue(MockResponse().setBody("""{"response":"Arrow rocks"}""")) val responseE = service.getResponseE() @@ -42,7 +50,8 @@ class ArrowResponseEAdapterTest : StringSpec({ } } - "should return Unit when service method returns Unit and null body received" { + @Test + fun shouldReturnUnitWhenServiceMethodReturnsUnitAndNullBodyReceived() = runTest { server.enqueue(MockResponse().setResponseCode(204)) val responseE = service.postSomethingResponseE("Sample string") @@ -52,8 +61,9 @@ class ArrowResponseEAdapterTest : 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 responseE = service.postSomethingResponseE("Sample string") @@ -64,7 +74,8 @@ class ArrowResponseEAdapterTest : StringSpec({ } } - "should return ErrorMock for 400 with valid JSON" { + @Test + fun shouldReturnErrorMockFor400WithValidJson() = runTest { server.enqueue(MockResponse().setBody("""{"errorCode":42}""").setResponseCode(400)) val responseE = service.getResponseE() @@ -74,28 +85,31 @@ class ArrowResponseEAdapterTest : StringSpec({ body shouldBe ErrorMock(42).left() } } - - "should throw for 200 with invalid JSON" { + + @Test + fun shouldThrowFor200WithInvalidJson() = runTest { server.enqueue(MockResponse().setBody("""not a valid JSON""")) val responseE = runCatching { service.getResponseE() } responseE.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 responseE = runCatching { service.getResponseE() } responseE.isFailure shouldBe true } - - "should throw when server disconnects" { + + @Test + fun shouldThrowWhenServerDisconnects() = runTest { server.enqueue(MockResponse().apply { socketPolicy = SocketPolicy.DISCONNECT_AFTER_REQUEST }) val responseE = runCatching { service.getResponseE() } responseE.isFailure shouldBe true } -}) +}