From 775e0342ad56aee32fcd262e3e140361ed32289c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Muller?= Date: Thu, 19 Dec 2024 09:19:31 +0100 Subject: [PATCH] Migrate remaining jUnit tests to Kotlin Test --- pillarbox-demo-shared/build.gradle.kts | 1 + .../ui/integrationLayer/data/ContentTest.kt | 4 +-- pillarbox-player/build.gradle.kts | 1 + .../player/IsPlayingAllTypeOfContentTest.kt | 14 ++++---- .../TestIsPlaybackSpeedPossibleAtPosition.kt | 10 +++--- .../TestPillarboxExoPlayerPlaybackSpeed.kt | 35 ++++++++++--------- 6 files changed, 35 insertions(+), 30 deletions(-) diff --git a/pillarbox-demo-shared/build.gradle.kts b/pillarbox-demo-shared/build.gradle.kts index 937816ba4..95694962f 100644 --- a/pillarbox-demo-shared/build.gradle.kts +++ b/pillarbox-demo-shared/build.gradle.kts @@ -50,4 +50,5 @@ dependencies { debugImplementation(libs.androidx.compose.ui.tooling) testImplementation(libs.junit) + testImplementation(libs.kotlin.test) } diff --git a/pillarbox-demo-shared/src/test/java/ch/srgssr/pillarbox/demo/shared/ui/integrationLayer/data/ContentTest.kt b/pillarbox-demo-shared/src/test/java/ch/srgssr/pillarbox/demo/shared/ui/integrationLayer/data/ContentTest.kt index e0c62c548..92588877e 100644 --- a/pillarbox-demo-shared/src/test/java/ch/srgssr/pillarbox/demo/shared/ui/integrationLayer/data/ContentTest.kt +++ b/pillarbox-demo-shared/src/test/java/ch/srgssr/pillarbox/demo/shared/ui/integrationLayer/data/ContentTest.kt @@ -9,10 +9,10 @@ import ch.srg.dataProvider.integrationlayer.data.remote.Media import ch.srg.dataProvider.integrationlayer.data.remote.MediaType import ch.srg.dataProvider.integrationlayer.data.remote.Type import ch.srg.dataProvider.integrationlayer.data.remote.Vendor -import org.junit.Assert.assertEquals -import org.junit.Test import java.util.Date import java.util.Locale +import kotlin.test.Test +import kotlin.test.assertEquals import kotlin.time.Duration.Companion.hours import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds diff --git a/pillarbox-player/build.gradle.kts b/pillarbox-player/build.gradle.kts index 218ee7504..b8321a1cb 100644 --- a/pillarbox-player/build.gradle.kts +++ b/pillarbox-player/build.gradle.kts @@ -72,6 +72,7 @@ dependencies { androidTestImplementation(libs.androidx.test.monitor) androidTestRuntimeOnly(libs.androidx.test.runner) androidTestImplementation(libs.junit) + androidTestImplementation(libs.kotlin.test) androidTestRuntimeOnly(libs.kotlinx.coroutines.android) androidTestImplementation(libs.mockk) } diff --git a/pillarbox-player/src/androidTest/java/ch/srgssr/pillarbox/player/IsPlayingAllTypeOfContentTest.kt b/pillarbox-player/src/androidTest/java/ch/srgssr/pillarbox/player/IsPlayingAllTypeOfContentTest.kt index 35ddfbcdb..471805226 100644 --- a/pillarbox-player/src/androidTest/java/ch/srgssr/pillarbox/player/IsPlayingAllTypeOfContentTest.kt +++ b/pillarbox-player/src/androidTest/java/ch/srgssr/pillarbox/player/IsPlayingAllTypeOfContentTest.kt @@ -11,11 +11,13 @@ import androidx.media3.common.Player import androidx.media3.common.util.ConditionVariable import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation import ch.srgssr.pillarbox.player.utils.ContentUrls -import org.junit.Assert -import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.Parameterized import java.util.concurrent.atomic.AtomicReference +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotNull +import kotlin.test.assertTrue /** * Instrumented test, which will execute on an Android device. @@ -50,10 +52,10 @@ class IsPlayingAllTypeOfContentTest { if (player.playerError != null) { throw Exception(player.playerError) } - Assert.assertEquals(Player.STATE_READY, player.playbackState) - Assert.assertTrue(player.isPlaying) - Assert.assertNotNull(player.currentMediaItem) - Assert.assertEquals(player.currentMediaItem?.localConfiguration?.uri, Uri.parse(urlToTest)) + assertEquals(Player.STATE_READY, player.playbackState) + assertTrue(player.isPlaying) + assertNotNull(player.currentMediaItem) + assertEquals(player.currentMediaItem?.localConfiguration?.uri, Uri.parse(urlToTest)) player.release() } } diff --git a/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/TestIsPlaybackSpeedPossibleAtPosition.kt b/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/TestIsPlaybackSpeedPossibleAtPosition.kt index 4273cc7e0..52b785e7e 100644 --- a/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/TestIsPlaybackSpeedPossibleAtPosition.kt +++ b/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/TestIsPlaybackSpeedPossibleAtPosition.kt @@ -12,17 +12,17 @@ import ch.srgssr.pillarbox.player.test.utils.TestTimeline import io.mockk.clearAllMocks import io.mockk.every import io.mockk.mockk -import org.junit.After -import org.junit.Assert.assertFalse -import org.junit.Assert.assertTrue -import org.junit.Test +import kotlin.test.AfterTest +import kotlin.test.Test +import kotlin.test.assertFalse +import kotlin.test.assertTrue import kotlin.time.Duration.Companion.hours import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds class TestIsPlaybackSpeedPossibleAtPosition { - @After + @AfterTest fun tearDown() { clearAllMocks() } diff --git a/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/TestPillarboxExoPlayerPlaybackSpeed.kt b/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/TestPillarboxExoPlayerPlaybackSpeed.kt index 08979adb6..f74f785ef 100644 --- a/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/TestPillarboxExoPlayerPlaybackSpeed.kt +++ b/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/TestPillarboxExoPlayerPlaybackSpeed.kt @@ -13,23 +13,24 @@ import androidx.media3.test.utils.robolectric.TestPlayerRunHelper import androidx.test.ext.junit.runners.AndroidJUnit4 import ch.srgssr.pillarbox.player.extension.getPlaybackSpeed import ch.srgssr.pillarbox.player.test.utils.TestPillarboxRunHelper -import org.junit.After -import org.junit.Assert -import org.junit.Before -import org.junit.Test import org.junit.runner.RunWith import org.robolectric.Shadows.shadowOf +import kotlin.test.AfterTest +import kotlin.test.BeforeTest +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals @RunWith(AndroidJUnit4::class) class TestPillarboxExoPlayerPlaybackSpeed { private lateinit var player: PillarboxExoPlayer - @Before + @BeforeTest fun createPlayer() { player = PillarboxExoPlayer() } - @After + @AfterTest fun releasePlayer() { player.release() shadowOf(Looper.getMainLooper()).idle() @@ -43,15 +44,15 @@ class TestPillarboxExoPlayerPlaybackSpeed { play() } TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY) - Assert.assertEquals(Player.STATE_READY, player.playbackState) + assertEquals(Player.STATE_READY, player.playbackState) player.setPlaybackSpeed(2f) - Assert.assertEquals(1f, player.getPlaybackSpeed()) + assertEquals(1f, player.getPlaybackSpeed()) player.seekTo(0) TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY) player.setPlaybackSpeed(2f) - Assert.assertEquals(1f, player.getPlaybackSpeed()) + assertEquals(1f, player.getPlaybackSpeed()) } @Test @@ -63,15 +64,15 @@ class TestPillarboxExoPlayerPlaybackSpeed { TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY) player.setPlaybackSpeed(2f) - Assert.assertEquals(1f, player.getPlaybackSpeed()) + assertEquals(1f, player.getPlaybackSpeed()) player.seekTo(0) TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY) player.setPlaybackSpeed(2f) - Assert.assertEquals(2f, player.getPlaybackSpeed()) + assertEquals(2f, player.getPlaybackSpeed()) TestPillarboxRunHelper.runUntilEvents(player, Player.EVENT_IS_LOADING_CHANGED) - Assert.assertEquals(2f, player.getPlaybackSpeed()) + assertEquals(2f, player.getPlaybackSpeed()) } @Test @@ -82,16 +83,16 @@ class TestPillarboxExoPlayerPlaybackSpeed { TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY) val liveEdgePosition = player.currentTimeline.getWindow(0, Window()).defaultPositionMs - Assert.assertNotEquals(C.TIME_UNSET, liveEdgePosition) + assertNotEquals(C.TIME_UNSET, liveEdgePosition) player.seekTo(liveEdgePosition - 5_000) TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY) val speed = 2f player.setPlaybackSpeed(speed) - Assert.assertEquals(speed, player.getPlaybackSpeed()) + assertEquals(speed, player.getPlaybackSpeed()) TestPillarboxRunHelper.runUntilPlaybackParametersChanged(player) - Assert.assertEquals(1f, player.getPlaybackSpeed()) + assertEquals(1f, player.getPlaybackSpeed()) } @Test @@ -104,11 +105,11 @@ class TestPillarboxExoPlayerPlaybackSpeed { val speed = 2f player.setPlaybackSpeed(speed) TestPillarboxRunHelper.runUntilEvents(player) - Assert.assertEquals(speed, player.getPlaybackSpeed()) + assertEquals(speed, player.getPlaybackSpeed()) player.setPlaybackSpeed(1f) TestPillarboxRunHelper.runUntilEvents(player) - Assert.assertEquals(1f, player.getPlaybackSpeed()) + assertEquals(1f, player.getPlaybackSpeed()) } private companion object {