mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-18 13:47:02 +05:30
model: don't unit test against the live server
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
76f613f82f
commit
e504a2c591
3 changed files with 22 additions and 2 deletions
|
@ -15,6 +15,13 @@ import retrofit2.create
|
||||||
@Module
|
@Module
|
||||||
@InstallIn(ActivityComponent::class)
|
@InstallIn(ActivityComponent::class)
|
||||||
object ApiModule {
|
object ApiModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@BaseUrlQualifier
|
||||||
|
fun provideBaseUrl(): String {
|
||||||
|
return LobstersApi.BASE_URL
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideClient(): OkHttpClient {
|
fun provideClient(): OkHttpClient {
|
||||||
return OkHttpClient.Builder()
|
return OkHttpClient.Builder()
|
||||||
|
@ -29,10 +36,11 @@ object ApiModule {
|
||||||
fun provideRetrofit(
|
fun provideRetrofit(
|
||||||
client: Lazy<OkHttpClient>,
|
client: Lazy<OkHttpClient>,
|
||||||
moshi: Lazy<Moshi>,
|
moshi: Lazy<Moshi>,
|
||||||
|
@BaseUrlQualifier baseUrl: String
|
||||||
): Retrofit {
|
): Retrofit {
|
||||||
return Retrofit.Builder()
|
return Retrofit.Builder()
|
||||||
.client(client.get())
|
.client(client.get())
|
||||||
.baseUrl(LobstersApi.BASE_URL)
|
.baseUrl(baseUrl)
|
||||||
.addConverterFactory(MoshiConverterFactory.create(moshi.get()))
|
.addConverterFactory(MoshiConverterFactory.create(moshi.get()))
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package dev.msfjarvis.lobsters.injection
|
||||||
|
|
||||||
|
import javax.inject.Qualifier
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Qualifier for a string value that needs to be provided to the [ApiModule.provideRetrofit] method
|
||||||
|
* as the base URL of our API.
|
||||||
|
*/
|
||||||
|
@Qualifier
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
annotation class BaseUrlQualifier
|
|
@ -22,7 +22,8 @@ class LobstersApiTest {
|
||||||
private val okHttp = ApiModule.provideClient()
|
private val okHttp = ApiModule.provideClient()
|
||||||
private val retrofit = ApiModule.provideRetrofit(
|
private val retrofit = ApiModule.provideRetrofit(
|
||||||
{ okHttp },
|
{ okHttp },
|
||||||
{ MoshiModule.provideMoshi() }
|
{ MoshiModule.provideMoshi() },
|
||||||
|
"http://localhost:8080/"
|
||||||
)
|
)
|
||||||
private val apiClient = ApiModule.provideApi(retrofit)
|
private val apiClient = ApiModule.provideApi(retrofit)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue