Skip to content

Commit

Permalink
Revert LruCache change and version name fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 committed Feb 1, 2024
1 parent f1a67ae commit a2fe590
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 14 deletions.
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ accompanist = "0.32.0"
android-gradle-plugin = "8.2.1"
androidx-activity = "1.8.2"
androidx-annotation = "1.7.1"
androidx-collection = "1.4.0"
androidx-compose = "2023.10.01"
androidx-core = "1.12.0"
androidx-fragment = "1.6.2"
Expand Down Expand Up @@ -45,7 +44,6 @@ androidx-activity = { module = "androidx.activity:activity", version.ref = "andr
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" }
androidx-activity-ktx = { module = "androidx.activity:activity-ktx", version.ref = "androidx-activity" }
androidx-annotation = { module = "androidx.annotation:annotation", version.ref = "androidx-annotation" }
androidx-collection = { module = "androidx.collection:collection", version.ref = "androidx-collection" }
androidx-core = { module = "androidx.core:core", version.ref = "androidx-core" }
androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidx-core" }
androidx-fragment = { module = "androidx.fragment:fragment", version.ref = "androidx-fragment" }
Expand Down
1 change: 1 addition & 0 deletions pillarbox-analytics/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ dependencies {
testImplementation(libs.mockk.dsl)
testRuntimeOnly(libs.robolectric)
testImplementation(libs.robolectric.annotations)
testImplementation(libs.robolectric.shadows.framework)
}

kover {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ internal object ComScoreSrg : ComScore {
val userConsentLabel = getUserConsentPair(config.userConsent.comScore)
persistentLabels[userConsentLabel.first] = userConsentLabel.second

val versionName: String = context.applicationContext.packageManager.getPackageInfo(context.applicationContext.packageName, 0).versionName
?: BuildConfig.VERSION_NAME
val applicationContext = context.applicationContext
val versionName: String = applicationContext.packageManager
.getPackageInfo(applicationContext.packageName, 0)
.versionName
persistentLabels[ComScoreLabel.MP_V.label] = versionName
persistentLabels[ComScoreLabel.MP_BRAND.label] = config.vendor.toString()
val publisher = PublisherConfiguration.Builder()
Expand All @@ -69,7 +71,7 @@ internal object ComScoreSrg : ComScore {
if (BuildConfig.DEBUG) {
Analytics.getConfiguration().enableImplementationValidationMode()
}
start(context.applicationContext)
start(applicationContext)
return this
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,26 @@ import com.comscore.Analytics
import io.mockk.mockkStatic
import io.mockk.unmockkAll
import org.junit.runner.RunWith
import org.robolectric.Shadows.shadowOf
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test

@RunWith(AndroidJUnit4::class)
class SRGAnalyticsSingletonTest {

private val config = AnalyticsConfig(
vendor = AnalyticsConfig.Vendor.SRG,
appSiteName = "pillarbox-test-android",
sourceKey = AnalyticsConfig.SOURCE_KEY_SRG_DEBUG
)

private lateinit var context: Context

@BeforeTest
fun setup() {
context = ApplicationProvider.getApplicationContext()
shadowOf(context.packageManager).getInternalMutablePackageInfo(context.packageName).versionName = "1.2.3"

mockkStatic(Analytics::class)
}

Expand All @@ -37,8 +42,8 @@ class SRGAnalyticsSingletonTest {

@Test(expected = IllegalArgumentException::class)
fun testInitTwice() {
val appContext: Context = ApplicationProvider.getApplicationContext()
SRGAnalytics.init(appContext as Application, config)
SRGAnalytics.init(appContext, config.copy(vendor = AnalyticsConfig.Vendor.RSI))
val application = context as Application
SRGAnalytics.init(application, config)
SRGAnalytics.init(application, config.copy(vendor = AnalyticsConfig.Vendor.RSI))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package ch.srgssr.pillarbox.analytics.comscore

import android.content.Context
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.srgssr.pillarbox.analytics.AnalyticsConfig
Expand All @@ -16,23 +17,28 @@ import io.mockk.mockkStatic
import io.mockk.unmockkAll
import io.mockk.verify
import org.junit.runner.RunWith
import org.robolectric.Shadows.shadowOf
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test

@RunWith(AndroidJUnit4::class)
class ComScoreSrgTest {

private val config = AnalyticsConfig(
vendor = AnalyticsConfig.Vendor.SRG,
appSiteName = "pillarbox-test-android",
sourceKey = AnalyticsConfig.SOURCE_KEY_SRG_DEBUG
)

private lateinit var context: Context

@BeforeTest
fun setup() {
context = ApplicationProvider.getApplicationContext()
shadowOf(context.packageManager).getInternalMutablePackageInfo(context.packageName).versionName = "1.2.3"

mockkStatic(Analytics::class)
ComScoreSrg.init(config = config, context = ApplicationProvider.getApplicationContext())
ComScoreSrg.init(config = config, context = context)
}

@AfterTest
Expand All @@ -42,7 +48,7 @@ class ComScoreSrgTest {

@Test(expected = IllegalArgumentException::class)
fun `init a second time with other config should throw exception`() {
ComScoreSrg.init(config = config.copy(vendor = AnalyticsConfig.Vendor.RTS), context = ApplicationProvider.getApplicationContext())
ComScoreSrg.init(config = config.copy(vendor = AnalyticsConfig.Vendor.RTS), context = context)
}

@Test
Expand Down
1 change: 0 additions & 1 deletion pillarbox-player/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ android {

dependencies {
implementation(libs.androidx.annotation)
implementation(libs.androidx.collection)
implementation(libs.androidx.core)
implementation(libs.androidx.media)
api(libs.androidx.media3.common)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.net.Uri
import androidx.collection.LruCache
import android.util.LruCache
import androidx.media3.common.Player
import androidx.media3.ui.PlayerNotificationManager
import androidx.media3.ui.PlayerNotificationManager.MediaDescriptionAdapter
Expand Down

0 comments on commit a2fe590

Please sign in to comment.