Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Retrofit adapter test configuration #2624

Merged
merged 3 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.SuspendApiTestClient
import io.kotest.matchers.shouldBe
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
Expand All @@ -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: SuspendApiTestClient

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(SuspendApiTestClient::class.java)
}

afterAny { server.shutdown() }

"should return ResponseMock for 200 with valid JSON" {
server.enqueue(MockResponse().setBody("""{"response":"Arrow rocks"}"""))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.SuspendApiTestClient
import io.kotest.matchers.shouldBe
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
Expand All @@ -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: SuspendApiTestClient

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(SuspendApiTestClient::class.java)
}

afterAny { server.shutdown() }

"should return ResponseMock for 200 with valid JSON" {
server.enqueue(MockResponse().setBody("""{"response":"Arrow rocks"}"""))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import arrow.retrofit.adapter.mock.ErrorMock
import arrow.retrofit.adapter.mock.ResponseMock
import retrofit2.http.GET

interface SuspedApiClientTest {
interface SuspendApiTestClient {

@GET("/")
suspend fun getEither(): Either<ErrorMock, ResponseMock>
Expand Down