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
|
||||
@InstallIn(ActivityComponent::class)
|
||||
object ApiModule {
|
||||
|
||||
@Provides
|
||||
@BaseUrlQualifier
|
||||
fun provideBaseUrl(): String {
|
||||
return LobstersApi.BASE_URL
|
||||
}
|
||||
|
||||
@Provides
|
||||
fun provideClient(): OkHttpClient {
|
||||
return OkHttpClient.Builder()
|
||||
|
@ -29,10 +36,11 @@ object ApiModule {
|
|||
fun provideRetrofit(
|
||||
client: Lazy<OkHttpClient>,
|
||||
moshi: Lazy<Moshi>,
|
||||
@BaseUrlQualifier baseUrl: String
|
||||
): Retrofit {
|
||||
return Retrofit.Builder()
|
||||
.client(client.get())
|
||||
.baseUrl(LobstersApi.BASE_URL)
|
||||
.baseUrl(baseUrl)
|
||||
.addConverterFactory(MoshiConverterFactory.create(moshi.get()))
|
||||
.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 retrofit = ApiModule.provideRetrofit(
|
||||
{ okHttp },
|
||||
{ MoshiModule.provideMoshi() }
|
||||
{ MoshiModule.provideMoshi() },
|
||||
"http://localhost:8080/"
|
||||
)
|
||||
private val apiClient = ApiModule.provideApi(retrofit)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue