Skip to content

Commit 2e1cd6b

Browse files
committed
refactor SettingsManagerTest to use Robolectric RuntimeEnvironment for context initialization
1 parent 217b158 commit 2e1cd6b

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/app/src/main/java/com/melodee/autoplayer/MelodeeApplication.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ class MelodeeApplication : Application(), ImageLoaderFactory {
3535
Log.i("MelodeeApplication", "=== APPLICATION STARTUP COMPLETE ===")
3636
}
3737
override fun newImageLoader(): ImageLoader {
38+
val isDebuggable = applicationInfo.flags and android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE != 0
3839
val loggingInterceptor = HttpLoggingInterceptor { message ->
3940
Log.d("OkHttp", message)
4041
}.apply {
41-
val isDebuggable = applicationInfo.flags and android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE != 0
4242
level = if (isDebuggable) {
4343
HttpLoggingInterceptor.Level.BASIC
4444
} else {
@@ -56,7 +56,9 @@ class MelodeeApplication : Application(), ImageLoaderFactory {
5656
.addInterceptor { chain ->
5757
val request = chain.request()
5858
val response = chain.proceed(request)
59-
Log.d("OkHttp", "Response headers for ${request.url}: ${response.headers}")
59+
if (isDebuggable) {
60+
Log.d("OkHttp", "Response headers for ${request.url}: ${response.headers}")
61+
}
6062
response
6163
}
6264
.addInterceptor(loggingInterceptor)

src/app/src/main/java/com/melodee/autoplayer/data/api/NetworkModule.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ object NetworkModule {
8888
authToken = token
8989
refreshToken = refresh
9090
handlingAuthFailure.set(false)
91-
Logger.d("NetworkModule", "Recreating Retrofit instance with updated tokens")
92-
createRetrofitInstance()
91+
if (retrofit == null && baseUrl.isNotEmpty()) {
92+
Logger.d("NetworkModule", "Creating Retrofit instance after token update")
93+
createRetrofitInstance()
94+
}
9395
Logger.logAuth("NetworkModule", "Tokens configured")
9496
}
9597
}

0 commit comments

Comments
 (0)