Skip to content

Commit 1a65812

Browse files
committed
Remove gson from kotlin-test
1 parent 8cc3c88 commit 1a65812

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

retrofit/kotlin-test/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ apply plugin: 'org.jetbrains.kotlin.jvm'
33
dependencies {
44
testImplementation projects.retrofit
55
testImplementation projects.retrofit.testHelpers
6-
testImplementation projects.retrofitConverters.gson
76
testImplementation libs.junit
87
testImplementation libs.truth
98
testImplementation libs.mockwebserver

retrofit/kotlin-test/src/test/java/retrofit2/KotlinSuspendTest.kt

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import org.junit.Assert.fail
3535
import org.junit.Ignore
3636
import org.junit.Rule
3737
import org.junit.Test
38-
import retrofit2.converter.gson.GsonConverterFactory
3938
import retrofit2.helpers.ToStringConverterFactory
4039
import retrofit2.http.GET
4140
import retrofit2.http.HEAD
@@ -61,7 +60,7 @@ class KotlinSuspendTest {
6160
suspend fun headUnit()
6261

6362
@GET("user")
64-
suspend fun getUser(): Result<User>
63+
suspend fun getString(): Result<String>
6564

6665
@HEAD("user")
6766
suspend fun headUser(): Result<Unit>
@@ -77,8 +76,6 @@ class KotlinSuspendTest {
7776
suspend fun bodyWithCallType(): Call<String>
7877
}
7978

80-
data class User(val id: Int, val name: String, val email: String)
81-
8279
@Test fun body() {
8380
val retrofit = Retrofit.Builder()
8481
.baseUrl(server.url("/"))
@@ -399,27 +396,18 @@ class KotlinSuspendTest {
399396
}
400397

401398
@Test fun returnResultType() = runBlocking {
402-
val responseBody = """
403-
{
404-
"id": 1,
405-
"name": "John Doe",
406-
"email": "[email protected]"
407-
}
408-
""".trimIndent()
409399
val retrofit = Retrofit.Builder()
410400
.baseUrl(server.url("/"))
411401
.addCallAdapterFactory(ResultCallAdapterFactory.create())
412-
.addConverterFactory(GsonConverterFactory.create())
402+
.addConverterFactory(ToStringConverterFactory())
413403
.build()
414404
val service = retrofit.create(Service::class.java)
415405

416406
// Successful response with body.
417-
server.enqueue(MockResponse().setBody(responseBody))
418-
service.getUser().let { result ->
407+
server.enqueue(MockResponse().setBody("Hello World"))
408+
service.getString().let { result ->
419409
assertThat(result.isSuccess).isTrue()
420-
assertThat(result.getOrThrow().id).isEqualTo(1)
421-
assertThat(result.getOrThrow().name).isEqualTo("John Doe")
422-
assertThat(result.getOrThrow().email).isEqualTo("[email protected]")
410+
assertThat(result.getOrThrow()).isEqualTo("Hello World")
423411
}
424412

425413
// Successful response without body.
@@ -431,7 +419,7 @@ class KotlinSuspendTest {
431419

432420
// Error response without body.
433421
server.enqueue(MockResponse().setResponseCode(404))
434-
service.getUser().let { result ->
422+
service.getString().let { result ->
435423
assertThat(result.isFailure).isTrue()
436424
assertThat(result.exceptionOrNull()).let {
437425
it.hasMessageThat().isEqualTo("HTTP 404 Client Error")
@@ -441,7 +429,7 @@ class KotlinSuspendTest {
441429

442430
// Network error.
443431
server.shutdown()
444-
service.getUser().let { result ->
432+
service.getString().let { result ->
445433
assertThat(result.isFailure).isTrue()
446434
assertThat(result.exceptionOrNull()).isInstanceOf(IOException::class.java)
447435
}

0 commit comments

Comments
 (0)