Skip to content

Commit 1551a7f

Browse files
Remove Retrofit dependency from the :quickeditor module (#604)
* Remove retrofit from the quick-editor module * Remove Retrofit from libs.versions.toml * Fix some leftover Retrofit mentiones in the README.md
1 parent 3ee0155 commit 1551a7f

File tree

4 files changed

+31
-37
lines changed

4 files changed

+31
-37
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ The OpenAPI definitions are located in the `openapi` directory. In the same dire
142142
the custom templates used by the OpenAPI Generator to generate the code that the Gravatar library needs. You can obtain the default templates by running the following command:
143143

144144
```sh
145-
openapi-generator author template -g kotlin --library jvm-retrofit2
145+
openapi-generator author template -g kotlin --library jvm-okhttp4
146146
```
147147

148148
The [OpenAPI Generator documentation](https://openapi-generator.tech/docs/templating) provides more information about the templates.

gradle/libs.versions.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ moshi = "1.15.1"
2828
navigationCompose = "2.8.3"
2929
okhttp = "4.12.0"
3030
openapi = "7.4.0"
31-
retrofit = "2.11.0"
3231
robolectric = "4.12.2"
3332
roborazzi = "1.26.0"
3433
startup = "1.1.1"
@@ -73,8 +72,6 @@ mockwebserver = { group = "com.squareup.okhttp3", name = "mockwebserver", versio
7372
moshi = { group = "com.squareup.moshi", name = "moshi", version.ref = "moshi" }
7473
moshi-kotlin-codegen = { group = "com.squareup.moshi", name = "moshi-kotlin-codegen", version.ref = "moshi" }
7574
okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp" }
76-
retrofit = { group = "com.squareup.retrofit2", name = "retrofit", version.ref = "retrofit" }
77-
retrofit-moshi-converter = { group = "com.squareup.retrofit2", name = "converter-moshi", version.ref = "retrofit" }
7875
robolectric = { group = "org.robolectric", name = "robolectric", version.ref = "robolectric" }
7976
roborazzi = { group = "io.github.takahirom.roborazzi", name = "roborazzi", version.ref = "roborazzi" }
8077
roborazzi-compose = { group = "io.github.takahirom.roborazzi", name = "roborazzi-compose", version.ref = "roborazzi" }

gravatar-quickeditor/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ dependencies {
3636
implementation(libs.androidx.startup)
3737

3838
implementation(libs.coil.compose)
39-
implementation(libs.retrofit)
40-
implementation(libs.retrofit.moshi.converter)
4139
implementation(libs.ucrop)
4240

4341
// Jetpack Compose

gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/data/AcceptedLanguageInterceptorTest.kt

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,73 +6,72 @@ import androidx.test.core.app.ApplicationProvider
66
import io.mockk.every
77
import io.mockk.mockkStatic
88
import okhttp3.OkHttpClient
9+
import okhttp3.Request
910
import okhttp3.mockwebserver.MockResponse
1011
import okhttp3.mockwebserver.MockWebServer
12+
import org.junit.After
1113
import org.junit.Assert.assertEquals
1214
import org.junit.Before
1315
import org.junit.Test
1416
import org.junit.runner.RunWith
1517
import org.robolectric.RobolectricTestRunner
16-
import retrofit2.Call
17-
import retrofit2.Retrofit
18-
import retrofit2.converter.moshi.MoshiConverterFactory
19-
import retrofit2.http.GET
2018
import java.util.Locale
2119

2220
@RunWith(RobolectricTestRunner::class)
2321
class AcceptedLanguageInterceptorTest {
2422
private val mockWebServer = MockWebServer()
2523

26-
private lateinit var api: TestApi
24+
private lateinit var client: OkHttpClient
2725

2826
private val context = ApplicationProvider.getApplicationContext<Context>()
2927

30-
private val testResponse = "\"name\""
31-
3228
@Before
3329
fun setUp() {
34-
val client = OkHttpClient.Builder()
30+
client = OkHttpClient.Builder()
3531
.addInterceptor(AcceptedLanguageInterceptor(context))
3632
.build()
33+
}
3734

38-
api = Retrofit.Builder()
39-
.baseUrl(mockWebServer.url("/"))
40-
.addConverterFactory(MoshiConverterFactory.create())
41-
.client(client)
42-
.build()
43-
.create(TestApi::class.java)
35+
@After
36+
fun after() {
37+
mockWebServer.shutdown()
4438
}
4539

4640
@Test
4741
fun `given one languages when intercepting then Accept-Language header set`() {
4842
mockkStatic(Context::languagesList)
4943
every { context.languagesList } returns LocaleListCompat.create(Locale.ENGLISH)
50-
val successResponse = MockResponse().setBody(testResponse)
51-
mockWebServer.enqueue(successResponse)
5244

53-
api.test().execute()
45+
val mockResponse = MockResponse().setResponseCode(200)
46+
mockWebServer.enqueue(mockResponse)
47+
mockWebServer.start()
48+
49+
val request = Request.Builder()
50+
.url(mockWebServer.url("/test"))
51+
.build()
52+
53+
client.newCall(request).execute()
5454

55-
val request = mockWebServer.takeRequest()
56-
val header = request.getHeader("Accept-Language")
57-
assertEquals("en", header)
55+
val recordedRequest = mockWebServer.takeRequest()
56+
assertEquals("en", recordedRequest.getHeader("Accept-Language"))
5857
}
5958

6059
@Test
6160
fun `given many languages when intercepting then Accept-Language header set`() {
6261
mockkStatic(Context::languagesList)
6362
every { context.languagesList } returns LocaleListCompat.create(Locale.ENGLISH, Locale.FRENCH, Locale.GERMANY)
64-
val successResponse = MockResponse().setBody(testResponse)
65-
mockWebServer.enqueue(successResponse)
6663

67-
api.test().execute()
64+
val mockResponse = MockResponse().setResponseCode(200)
65+
mockWebServer.enqueue(mockResponse)
66+
mockWebServer.start()
6867

69-
val request = mockWebServer.takeRequest()
70-
val header = request.getHeader("Accept-Language")
71-
assertEquals("en,fr;q=0.9,de;q=0.8", header)
72-
}
73-
}
68+
val request = Request.Builder()
69+
.url(mockWebServer.url("/test"))
70+
.build()
7471

75-
private interface TestApi {
76-
@GET("/test")
77-
fun test(): Call<String>
72+
client.newCall(request).execute()
73+
74+
val recordedRequest = mockWebServer.takeRequest()
75+
assertEquals("en,fr;q=0.9,de;q=0.8", recordedRequest.getHeader("Accept-Language"))
76+
}
7877
}

0 commit comments

Comments
 (0)