From 685dc9da0037a3e696b4984d0f2bc9a9ae3077d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Muller?= Date: Tue, 30 Jan 2024 16:22:45 +0100 Subject: [PATCH] Replace jUnit with kotlin.test where possible --- build.gradle.kts | 3 +- gradle.properties | 5 +- gradle/libs.versions.toml | 7 ++- pillarbox-analytics/build.gradle.kts | 6 +-- .../commandersact/CommandersActSrg.kt | 12 ++--- .../analytics/SRGAnalyticsSingletonTest.kt | 2 +- .../commandersact/CommandersActSrgTest.kt | 48 +++++++++-------- .../analytics/comscore/ComScoreSrgTest.kt | 2 +- pillarbox-core-business/build.gradle.kts | 6 +-- .../core/business/ImageScalingServiceTest.kt | 4 +- .../MediaCompositionMediaItemSourceTest.kt | 25 +++++---- .../core/business/ResourceSelectorTest.kt | 54 ++++++++++--------- .../core/business/TestJsonSerialization.kt | 17 +++--- .../akamai/AkamaiTokenProviderTest.kt | 38 +++++++------ 14 files changed, 121 insertions(+), 108 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 0bf3e9b9e..a4e1981ed 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -84,10 +84,11 @@ dependencyAnalysis { } } - // Required because of https://github.com/autonomousapps/dependency-analysis-gradle-plugin/issues/892 structure { // https://github.com/autonomousapps/dependency-analysis-gradle-plugin/wiki/Customizing-plugin-behavior ignoreKtx(true) // default is false + + // Required because of https://github.com/autonomousapps/dependency-analysis-gradle-plugin/issues/892 bundle("kotlin-test") { includeDependency(libs.kotlin.test) } diff --git a/gradle.properties b/gradle.properties index 2e3870f55..81879c2e1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,10 +19,11 @@ org.gradle.parallel=true # https://developer.android.com/topic/libraries/support-library/androidx-rn android.useAndroidX=true +# https://github.com/autonomousapps/dependency-analysis-gradle-plugin/issues/1079#issuecomment-1862266603 +dependency.analysis.test.analysis=false + # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official org.gradle.caching=true org.gradle.configuration-cache=true -# https://github.com/autonomousapps/dependency-analysis-gradle-plugin/issues/1079#issuecomment-1862266603 -dependency.analysis.test.analysis=false diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c6b19413c..9e197ebf2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -12,13 +12,13 @@ androidx-media = "1.7.0" androidx-media3 = "1.2.1" androidx-navigation = "2.7.6" androidx-paging = "3.2.1" +androidx-test-core = "1.5.0" androidx-test-ext-junit = "1.1.5" androidx-test-monitor = "1.6.1" androidx-test-runner = "1.5.2" androidx-tv = "1.0.0-alpha10" coil = "2.5.0" comscore = "6.10.0" -core = "1.5.0" dependency-analysis-gradle-plugin = "1.29.0" detekt = "1.23.4" guava = "31.1-android" @@ -37,7 +37,6 @@ srg-data-provider = "0.8.0" tag-commander-core = "5.4.2" tag-commander-server-side = "5.5.2" turbine = "1.0.0" -junit-ktx = "1.1.5" [libraries] accompanist-navigation-material = { module = "com.google.accompanist:accompanist-navigation-material", version.ref = "accompanist" } @@ -59,12 +58,12 @@ androidx-navigation-runtime = { module = "androidx.navigation:navigation-runtime androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "androidx-navigation" } androidx-paging-common = { module = "androidx.paging:paging-common", version.ref = "androidx-paging" } androidx-paging-compose = { module = "androidx.paging:paging-compose", version.ref = "androidx-paging" } +androidx-test-core = { module = "androidx.test:core-ktx", version.ref = "androidx-test-core" } androidx-test-monitor = { module = "androidx.test:monitor", version.ref = "androidx-test-monitor" } androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidx-test-runner" } androidx-tv-foundation = { module = "androidx.tv:tv-foundation", version.ref = "androidx-tv" } androidx-tv-material = { module = "androidx.tv:tv-material", version.ref = "androidx-tv" } coil = { group = "io.coil-kt", name = "coil-compose", version.ref = "coil" } -core = { module = "androidx.test:core-ktx", version.ref = "core" } json = { module = "org.json:json", version.ref = "json" } kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" } kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } @@ -126,9 +125,9 @@ androidx-compose-runtime = { module = "androidx.compose.runtime:runtime" } androidx-compose-runtime-saveable = { module = "androidx.compose.runtime:runtime-saveable" } leanback = { group = "androidx.leanback", name = "leanback", version.ref = "androidx-leanback" } androidx-test-ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-ext-junit" } +androidx-test-ext-junit-ktx = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "androidx-test-ext-junit" } guava = { module = "com.google.guava:guava", version.ref = "guava" } turbine = { module = "app.cash.turbine:turbine", version.ref = "turbine" } -androidx-junit-ktx = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "junit-ktx" } [plugins] android-application = { id = "com.android.application", version.ref = "android-gradle-plugin" } diff --git a/pillarbox-analytics/build.gradle.kts b/pillarbox-analytics/build.gradle.kts index 318574a2e..b6e328946 100644 --- a/pillarbox-analytics/build.gradle.kts +++ b/pillarbox-analytics/build.gradle.kts @@ -62,9 +62,8 @@ dependencies { implementation(libs.tagcommander.core) api(libs.tagcommander.serverside) - testImplementation(libs.androidx.junit.ktx) - testImplementation(libs.core) - testImplementation(libs.robolectric) + testImplementation(libs.androidx.test.core) + testImplementation(libs.androidx.test.ext.junit.ktx) testImplementation(libs.json) { because("The 'org.json' package is included in the Android SDK. Adding this dependency allows us to not mock the Android SDK in unit tests.") } @@ -72,6 +71,7 @@ dependencies { testImplementation(libs.kotlin.test) testImplementation(libs.mockk) testImplementation(libs.mockk.dsl) + testImplementation(libs.robolectric) } kover { diff --git a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActSrg.kt b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActSrg.kt index 847543bb0..6aad567f3 100644 --- a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActSrg.kt +++ b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActSrg.kt @@ -116,12 +116,12 @@ internal class CommandersActSrg( } /* - * From issue : - * - https://github.com/SRGSSR/srgletterbox-android/issues/522 - * - https://github.com/CommandersAct/iOSV5/issues/13 - * - * And after discussion with CommandersAct teams and SRG ADI team. - */ + * From issue : + * - https://github.com/SRGSSR/srgletterbox-android/issues/522 + * - https://github.com/CommandersAct/iOSV5/issues/13 + * + * And after discussion with CommandersAct teams and SRG ADI team. + */ private fun workaroundUniqueIdV4Tov5() { // 1. Use the TC unique id value for new `device.sdk_id` property. useLegacyUniqueIDForSdkID() diff --git a/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/SRGAnalyticsSingletonTest.kt b/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/SRGAnalyticsSingletonTest.kt index 7aadb58bf..517cef651 100644 --- a/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/SRGAnalyticsSingletonTest.kt +++ b/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/SRGAnalyticsSingletonTest.kt @@ -11,10 +11,10 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import com.comscore.Analytics import io.mockk.mockkStatic import io.mockk.unmockkAll -import org.junit.Test import org.junit.runner.RunWith import kotlin.test.AfterTest import kotlin.test.BeforeTest +import kotlin.test.Test @RunWith(AndroidJUnit4::class) class SRGAnalyticsSingletonTest { diff --git a/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActSrgTest.kt b/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActSrgTest.kt index 080733455..6a9db81ca 100644 --- a/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActSrgTest.kt +++ b/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActSrgTest.kt @@ -14,10 +14,12 @@ import com.tagcommander.lib.serverside.schemas.TCDevice import io.mockk.mockk import io.mockk.slot import io.mockk.verify -import org.junit.Assert -import org.junit.Test import org.junit.runner.RunWith import org.robolectric.annotation.Config +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull +import kotlin.test.assertTrue @RunWith(AndroidJUnit4::class) class CommandersActSrgTest { @@ -32,32 +34,32 @@ class CommandersActSrgTest { @Config(qualifiers = "television") fun `navigation device is tvbox`() { val actual = commandersAct.getPermanentDataLabel("navigation_device") - Assert.assertEquals("tvbox", actual) + assertEquals("tvbox", actual) } @Test @Config fun `navigation device is phone`() { val actual = commandersAct.getPermanentDataLabel("navigation_device") - Assert.assertEquals("phone", actual) + assertEquals("phone", actual) } @Test @Config(qualifiers = "sw600dp") fun `test navigation device is tablet`() { val actual = commandersAct.getPermanentDataLabel("navigation_device") - Assert.assertEquals("tablet", actual) + assertEquals("tablet", actual) } @Test @Config(qualifiers = "car") fun `navigation device is auto`() { val actual = commandersAct.getPermanentDataLabel("navigation_device") - Assert.assertEquals("auto", actual) + assertEquals("auto", actual) } @Test - fun `sendEvent() with CommandersActEvent`() { + fun `sendEvent() with CommandersActEvent`() { val serverSide = mockk(relaxed = true) val commandersAct = CommandersActSrg(tcServerSide = serverSide, config = analyticsConfig, "tests") val eventSlot = slot() @@ -67,8 +69,8 @@ class CommandersActSrgTest { serverSide.execute(capture(eventSlot)) } - Assert.assertTrue(eventSlot.isCaptured) - Assert.assertEquals(eventSlot.captured.name, "dummy") + assertTrue(eventSlot.isCaptured) + assertEquals(eventSlot.captured.name, "dummy") } @Test @@ -88,18 +90,18 @@ class CommandersActSrgTest { verify(exactly = 1) { serverSide.execute(capture(eventSlot)) } - Assert.assertTrue(eventSlot.isCaptured) + assertTrue(eventSlot.isCaptured) val capturedEvent = eventSlot.captured - Assert.assertEquals("page_view", capturedEvent.name) - Assert.assertEquals("PageTitle1", capturedEvent.pageName) - Assert.assertEquals("UnitTest", capturedEvent.pageType) - Assert.assertEquals("pillarbox", capturedEvent.additionalProperties["navigation_level_1"]) - Assert.assertEquals("unit-test", capturedEvent.additionalProperties["navigation_level_2"]) - Assert.assertNull(capturedEvent.additionalProperties["navigation_level_3"]) + assertEquals("page_view", capturedEvent.name) + assertEquals("PageTitle1", capturedEvent.pageName) + assertEquals("UnitTest", capturedEvent.pageType) + assertEquals("pillarbox", capturedEvent.additionalProperties["navigation_level_1"]) + assertEquals("unit-test", capturedEvent.additionalProperties["navigation_level_2"]) + assertNull(capturedEvent.additionalProperties["navigation_level_3"]) } @Test - fun `sendTcMediaEvent() with TCMediaEvent`() { + fun `sendTcMediaEvent() with TCMediaEvent`() { val serverSide = mockk(relaxed = true) val commandersAct = CommandersActSrg(tcServerSide = serverSide, config = analyticsConfig, "tests") val eventSlot = slot() @@ -109,13 +111,13 @@ class CommandersActSrgTest { serverSide.execute(capture(eventSlot)) } - Assert.assertTrue(eventSlot.isCaptured) - Assert.assertEquals("eof", eventSlot.captured.name) + assertTrue(eventSlot.isCaptured) + assertEquals("eof", eventSlot.captured.name) } @Test fun `initial consent services`() { - Assert.assertNull(commandersAct.getPermanentDataLabel(CommandersActLabels.CONSENT_SERVICES.label)) + assertNull(commandersAct.getPermanentDataLabel(CommandersActLabels.CONSENT_SERVICES.label)) } @Test @@ -123,13 +125,13 @@ class CommandersActSrgTest { val services = listOf("service1", "service2") val expected = "service1,service2" commandersAct.setConsentServices(services) - Assert.assertEquals(expected, commandersAct.getPermanentDataLabel(CommandersActLabels.CONSENT_SERVICES.label)) + assertEquals(expected, commandersAct.getPermanentDataLabel(CommandersActLabels.CONSENT_SERVICES.label)) } @Test fun `legacyUniqueID is used for sdkID and anonymous_id`() { val legacyUniqueId: String = TCPredefinedVariables.getInstance().uniqueIdentifier - Assert.assertEquals(legacyUniqueId, TCDevice.getInstance().sdkID) - Assert.assertEquals(legacyUniqueId, TCUser.getInstance().anonymous_id) + assertEquals(legacyUniqueId, TCDevice.getInstance().sdkID) + assertEquals(legacyUniqueId, TCUser.getInstance().anonymous_id) } } diff --git a/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/comscore/ComScoreSrgTest.kt b/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/comscore/ComScoreSrgTest.kt index 8cd23c3a0..d5386024f 100644 --- a/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/comscore/ComScoreSrgTest.kt +++ b/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/comscore/ComScoreSrgTest.kt @@ -15,10 +15,10 @@ import io.mockk.mockk import io.mockk.mockkStatic import io.mockk.unmockkAll import io.mockk.verify -import org.junit.Test import org.junit.runner.RunWith import kotlin.test.AfterTest import kotlin.test.BeforeTest +import kotlin.test.Test @RunWith(AndroidJUnit4::class) class ComScoreSrgTest { diff --git a/pillarbox-core-business/build.gradle.kts b/pillarbox-core-business/build.gradle.kts index 8dc75829b..017041609 100644 --- a/pillarbox-core-business/build.gradle.kts +++ b/pillarbox-core-business/build.gradle.kts @@ -76,15 +76,15 @@ dependencies { implementation(libs.okhttp.logging.interceptor) api(libs.tagcommander.core) - testImplementation(libs.androidx.junit.ktx) - testImplementation(libs.core) - testImplementation(libs.robolectric) + testImplementation(libs.androidx.test.core) + testImplementation(libs.androidx.test.ext.junit.ktx) testImplementation(libs.junit) testImplementation(libs.kotlin.test) testImplementation(libs.kotlinx.coroutines.test) testImplementation(libs.ktor.client.mock) testImplementation(libs.mockk) testImplementation(libs.mockk.dsl) + testImplementation(libs.robolectric) androidTestImplementation(project(":pillarbox-player-testutils")) diff --git a/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/ImageScalingServiceTest.kt b/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/ImageScalingServiceTest.kt index f1689a405..2dab8f92f 100644 --- a/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/ImageScalingServiceTest.kt +++ b/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/ImageScalingServiceTest.kt @@ -6,9 +6,9 @@ package ch.srgssr.pillarbox.core.business import ch.srgssr.pillarbox.core.business.MediaCompositionMediaItemSource.ImageScalingService import ch.srgssr.pillarbox.core.business.integrationlayer.service.IlHost -import org.junit.Assert.assertEquals -import org.junit.Test import java.net.URLEncoder +import kotlin.test.Test +import kotlin.test.assertEquals class ImageScalingServiceTest { @Test diff --git a/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/MediaCompositionMediaItemSourceTest.kt b/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/MediaCompositionMediaItemSourceTest.kt index c25c77e02..f8e45c465 100644 --- a/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/MediaCompositionMediaItemSourceTest.kt +++ b/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/MediaCompositionMediaItemSourceTest.kt @@ -15,8 +15,10 @@ import ch.srgssr.pillarbox.core.business.integrationlayer.data.Resource import ch.srgssr.pillarbox.core.business.integrationlayer.data.Segment import ch.srgssr.pillarbox.core.business.integrationlayer.service.MediaCompositionDataSource import kotlinx.coroutines.runBlocking -import org.junit.Assert -import org.junit.Test +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotNull +import kotlin.test.assertTrue class MediaCompositionMediaItemSourceTest { @@ -51,20 +53,21 @@ class MediaCompositionMediaItemSourceTest { @Test fun testCompatibleResource() = runBlocking { val mediaItem = mediaItemSource.loadMediaItem(createMediaItem(DummyMediaCompositionProvider.URN_HLS_RESOURCE)) - Assert.assertNotNull(mediaItem) + assertNotNull(mediaItem) + Unit } @Test fun testMetadata() = runBlocking { val mediaItem = mediaItemSource.loadMediaItem(createMediaItem(DummyMediaCompositionProvider.URN_METADATA)) - Assert.assertNotNull(mediaItem) + assertNotNull(mediaItem) val metadata = mediaItem.mediaMetadata val expected = MediaMetadata.Builder() .setTitle("Title") .setSubtitle("Lead") .setDescription("Description") .build() - Assert.assertEquals(expected, metadata) + assertEquals(expected, metadata) } @Test @@ -75,10 +78,10 @@ class MediaCompositionMediaItemSourceTest { .setDescription("CustomDescription") .build() val mediaItem = mediaItemSource.loadMediaItem(createMediaItem(DummyMediaCompositionProvider.URN_METADATA, input)) - Assert.assertNotNull(mediaItem) + assertNotNull(mediaItem) val metadata = mediaItem.mediaMetadata val expected = input.buildUpon().build() - Assert.assertEquals(expected, metadata) + assertEquals(expected, metadata) } @Test @@ -87,28 +90,28 @@ class MediaCompositionMediaItemSourceTest { .setTitle("CustomTitle") .build() val mediaItem = mediaItemSource.loadMediaItem(createMediaItem(DummyMediaCompositionProvider.URN_METADATA, input)) - Assert.assertNotNull(mediaItem) + assertNotNull(mediaItem) val metadata = mediaItem.mediaMetadata val expected = MediaMetadata.Builder() .setTitle("CustomTitle") .setSubtitle("Lead") .setDescription("Description") .build() - Assert.assertEquals(expected, metadata) + assertEquals(expected, metadata) } @Test(expected = BlockReasonException::class) fun testBlockReason() = runBlocking { val input = MediaMetadata.Builder().build() mediaItemSource.loadMediaItem(createMediaItem(DummyMediaCompositionProvider.URN_BLOCK_REASON, input)) - Assert.assertTrue(false) + assertTrue(false) } @Test(expected = BlockReasonException::class) fun testBlockedSegment() = runBlocking { val input = MediaMetadata.Builder().build() mediaItemSource.loadMediaItem(createMediaItem(DummyMediaCompositionProvider.URN_SEGMENT_BLOCK_REASON, input)) - Assert.assertTrue(false) + assertTrue(false) } internal class DummyMediaCompositionProvider : MediaCompositionDataSource { diff --git a/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/ResourceSelectorTest.kt b/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/ResourceSelectorTest.kt index 901204eaa..1a9c54624 100644 --- a/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/ResourceSelectorTest.kt +++ b/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/ResourceSelectorTest.kt @@ -7,8 +7,10 @@ package ch.srgssr.pillarbox.core.business import ch.srgssr.pillarbox.core.business.integrationlayer.data.Chapter import ch.srgssr.pillarbox.core.business.integrationlayer.data.Drm import ch.srgssr.pillarbox.core.business.integrationlayer.data.Resource -import org.junit.Assert -import org.junit.Test +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotNull +import kotlin.test.assertNull class ResourceSelectorTest { @@ -18,14 +20,14 @@ class ResourceSelectorTest { fun testNull() { val chapter = createChapter(null) val result = resourceSelector.selectResourceFromChapter(chapter) - Assert.assertNull(result) + assertNull(result) } @Test fun testEmptyList() { val chapter = createChapter(emptyList()) val result = resourceSelector.selectResourceFromChapter(chapter) - Assert.assertNull(result) + assertNull(result) } @Test @@ -39,7 +41,7 @@ class ResourceSelectorTest { ) ) val result = resourceSelector.selectResourceFromChapter(chapter) - Assert.assertNull(result) + assertNull(result) } @Test @@ -55,8 +57,8 @@ class ResourceSelectorTest { ) ) val result = resourceSelector.selectResourceFromChapter(chapter) - Assert.assertNotNull(result) - Assert.assertEquals(createResource(type), result) + assertNotNull(result) + assertEquals(createResource(type), result) } @Test @@ -72,8 +74,8 @@ class ResourceSelectorTest { ) ) val result = resourceSelector.selectResourceFromChapter(chapter) - Assert.assertNotNull(result) - Assert.assertEquals(createResource(type), result) + assertNotNull(result) + assertEquals(createResource(type), result) } @Test @@ -89,8 +91,8 @@ class ResourceSelectorTest { ) ) val result = resourceSelector.selectResourceFromChapter(chapter) - Assert.assertNotNull(result) - Assert.assertEquals(createResource(type), result) + assertNotNull(result) + assertEquals(createResource(type), result) } @Test @@ -108,8 +110,8 @@ class ResourceSelectorTest { ) ) val result = resourceSelector.selectResourceFromChapter(chapter) - Assert.assertNotNull(result) - Assert.assertEquals(createResource(type), result) + assertNotNull(result) + assertEquals(createResource(type), result) } @Test @@ -127,8 +129,8 @@ class ResourceSelectorTest { ) ) val result = resourceSelector.selectResourceFromChapter(chapter) - Assert.assertNotNull(result) - Assert.assertEquals(createResource(type), result) + assertNotNull(result) + assertEquals(createResource(type), result) } @Test @@ -146,15 +148,15 @@ class ResourceSelectorTest { ) ) val result = resourceSelector.selectResourceFromChapter(chapter) - Assert.assertNotNull(result) - Assert.assertEquals(createResource(type), result) + assertNotNull(result) + assertEquals(createResource(type), result) } @Test fun testUnsupportedDrmOnly() { val chapter = createChapter(listOf(createUnsupportedDrmResource())) val result = resourceSelector.selectResourceFromChapter(chapter) - Assert.assertNull(result) + assertNull(result) } @Test @@ -167,8 +169,8 @@ class ResourceSelectorTest { ) ) val result = resourceSelector.selectResourceFromChapter(chapter) - Assert.assertNotNull(result) - Assert.assertEquals(createResource(type), result) + assertNotNull(result) + assertEquals(createResource(type), result) } @Test @@ -179,8 +181,8 @@ class ResourceSelectorTest { ) ) val result = resourceSelector.selectResourceFromChapter(chapter) - Assert.assertNotNull(result) - Assert.assertEquals(createSupportedDrmResource(), result) + assertNotNull(result) + assertEquals(createSupportedDrmResource(), result) } @Test @@ -193,8 +195,8 @@ class ResourceSelectorTest { ) ) val result = resourceSelector.selectResourceFromChapter(chapter) - Assert.assertNotNull(result) - Assert.assertEquals(createResource(Resource.Type.HLS), result) + assertNotNull(result) + assertEquals(createResource(Resource.Type.HLS), result) } @Test @@ -209,8 +211,8 @@ class ResourceSelectorTest { ) ) val result = resourceSelector.selectResourceFromChapter(chapter) - Assert.assertNotNull(result) - Assert.assertEquals(createSupportedDrmResource(), result) + assertNotNull(result) + assertEquals(createSupportedDrmResource(), result) } companion object { diff --git a/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/TestJsonSerialization.kt b/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/TestJsonSerialization.kt index 5a316b3d0..8e61f3158 100644 --- a/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/TestJsonSerialization.kt +++ b/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/TestJsonSerialization.kt @@ -9,24 +9,25 @@ import ch.srgssr.pillarbox.core.business.integrationlayer.data.Chapter import ch.srgssr.pillarbox.core.business.integrationlayer.data.MediaComposition import ch.srgssr.pillarbox.core.business.integrationlayer.service.DefaultHttpClient.jsonSerializer import kotlinx.serialization.SerializationException -import org.junit.Assert -import org.junit.Test +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotNull class TestJsonSerialization { @Test fun testChapterValidJson() { val json = "{\"urn\":\"urn:srf:video:12343\",\"title\":\"Chapter title\",\"imageUrl\":\"https://image.png\",\"blockReason\": \"UNKNOWN\"}" val chapter = jsonSerializer.decodeFromString(json) - Assert.assertNotNull(chapter) - Assert.assertEquals(BlockReason.UNKNOWN, chapter.blockReason) + assertNotNull(chapter) + assertEquals(BlockReason.UNKNOWN, chapter.blockReason) } @Test(expected = SerializationException::class) fun testChapterValidJsonUnknownBlockreason() { val json = "{\"urn\":\"urn:srf:video:12343\",\"title\":\"Chapter title\",\"imageUrl\":\"https://image.png\",\"blockReason\": \"TOTO\"}" val chapter = jsonSerializer.decodeFromString(json) - Assert.assertNotNull(chapter) - Assert.assertNotNull(chapter.blockReason) + assertNotNull(chapter) + assertNotNull(chapter.blockReason) } @Test(expected = SerializationException::class) @@ -45,7 +46,7 @@ class TestJsonSerialization { fun testMediaCompositionWithNullJsonFields() { val json = "{\"chapterList\": [{\"title\":\"Chapter title\",\"imageUrl\":\"https://image.png\"}]}" val mediaComposition = jsonSerializer.decodeFromString(json) - Assert.assertNotNull(mediaComposition) + assertNotNull(mediaComposition) } @Test @@ -63,6 +64,6 @@ class TestJsonSerialization { } """ val mediaComposition = jsonSerializer.decodeFromString(json) - Assert.assertNotNull(mediaComposition) + assertNotNull(mediaComposition) } } diff --git a/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/akamai/AkamaiTokenProviderTest.kt b/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/akamai/AkamaiTokenProviderTest.kt index 9bd519541..8400136e7 100644 --- a/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/akamai/AkamaiTokenProviderTest.kt +++ b/pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/akamai/AkamaiTokenProviderTest.kt @@ -6,9 +6,13 @@ package ch.srgssr.pillarbox.core.business.akamai import android.net.Uri import androidx.test.ext.junit.runners.AndroidJUnit4 -import org.junit.Assert -import org.junit.Test import org.junit.runner.RunWith +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals +import kotlin.test.assertNotNull +import kotlin.test.assertNull +import kotlin.test.assertTrue @RunWith(AndroidJUnit4::class) class AkamaiTokenProviderTest { @@ -17,7 +21,7 @@ class AkamaiTokenProviderTest { fun `getAcl() from a simple uri return null`() { val uri = Uri.parse("https://www.fake.url") val acl = AkamaiTokenProvider.getAcl(uri) - Assert.assertNull(acl) + assertNull(acl) } @Test @@ -25,8 +29,8 @@ class AkamaiTokenProviderTest { val uri = Uri.parse("https://fake.url/content/not/playingLive/with/a/very/long/pat") val expectedAcl = "/content/not/playingLive/with/a/very/long/*" val acl = AkamaiTokenProvider.getAcl(uri) - Assert.assertNotNull(acl) - Assert.assertEquals(expectedAcl, acl) + assertNotNull(acl) + assertEquals(expectedAcl, acl) } @Test @@ -34,8 +38,8 @@ class AkamaiTokenProviderTest { val uri = Uri.parse("https://fake.url/content/not/playingLive/with/a/very/long/pat/playlist.mp3") val expectedAcl = "/content/not/playingLive/with/a/very/long/pat/*" val acl = AkamaiTokenProvider.getAcl(uri) - Assert.assertNotNull(acl) - Assert.assertEquals(expectedAcl, acl) + assertNotNull(acl) + assertEquals(expectedAcl, acl) } @Test @@ -43,8 +47,8 @@ class AkamaiTokenProviderTest { val uri = Uri.parse("https://fake.url/content/playlist.m3u8") val expectedAcl = "/content/*" val acl = AkamaiTokenProvider.getAcl(uri) - Assert.assertNotNull(acl) - Assert.assertEquals(expectedAcl, acl) + assertNotNull(acl) + assertEquals(expectedAcl, acl) } @Test @@ -52,8 +56,8 @@ class AkamaiTokenProviderTest { val uri = Uri.parse("https://fake.url/playlist.m3u8") val expectedAcl = "/*" val acl = AkamaiTokenProvider.getAcl(uri) - Assert.assertNotNull(acl) - Assert.assertEquals(expectedAcl, acl) + assertNotNull(acl) + assertEquals(expectedAcl, acl) } @Test @@ -61,8 +65,8 @@ class AkamaiTokenProviderTest { val uri = Uri.parse("https://fake.url/content/hls/playingLive/additional/path") val expectedAcl = "/content/hls/playingLive/additional/*" val acl = AkamaiTokenProvider.getAcl(uri) - Assert.assertNotNull(acl) - Assert.assertEquals(expectedAcl, acl) + assertNotNull(acl) + assertEquals(expectedAcl, acl) } @Test @@ -70,8 +74,8 @@ class AkamaiTokenProviderTest { val uri = Uri.parse("https://srgssrch.akamaized.net/hls/live/2022027/srgssr-hls-stream15-ch-dvr/master.m3u8?start=1697860830&end=1697867100") val expectedAcl = "/hls/live/2022027/srgssr-hls-stream15-ch-dvr/*" val acl = AkamaiTokenProvider.getAcl(uri) - Assert.assertNotNull(acl) - Assert.assertEquals(expectedAcl, acl) + assertNotNull(acl) + assertEquals(expectedAcl, acl) } @Test @@ -79,7 +83,7 @@ class AkamaiTokenProviderTest { val uri = Uri.parse("https://srgssrch.akamaized.net/hls/live/2022027/srgssr-hls-stream15-ch-dvr/master.m3u8?start=1697860830&end=1697867100") val fakeToken = AkamaiTokenProvider.Token(authParams = "Token") val actual = AkamaiTokenProvider.appendTokenToUri(uri, fakeToken) - Assert.assertNotEquals(uri, actual) - Assert.assertTrue("Contains base url", actual.toString().contains(uri.toString())) + assertNotEquals(uri, actual) + assertTrue(actual.toString().contains(uri.toString()), "Contains base url") } }