diff --git a/player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/PlayLogTest.kt b/player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/SingleMediaProductPlayLogTest.kt similarity index 79% rename from player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/PlayLogTest.kt rename to player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/SingleMediaProductPlayLogTest.kt index 5cbce756..f3899c23 100644 --- a/player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/PlayLogTest.kt +++ b/player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/SingleMediaProductPlayLogTest.kt @@ -27,8 +27,6 @@ import com.tidal.sdk.player.events.reflectionComponentFactoryF import com.tidal.sdk.player.playbackengine.model.Event import com.tidal.sdk.player.playbackengine.model.Event.MediaProductEnded import com.tidal.sdk.player.setBodyFromFile -import kotlin.time.Duration.Companion.milliseconds -import kotlin.time.Duration.Companion.seconds import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow @@ -53,6 +51,8 @@ import org.junit.Before import org.junit.BeforeClass import org.junit.Rule import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.Parameterized import org.mockito.Mockito.atMost import org.mockito.Mockito.mock import org.mockito.Mockito.verifyNoMoreInteractions @@ -60,8 +60,11 @@ import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.argThat import org.mockito.kotlin.eq import org.mockito.kotlin.verify +import kotlin.time.Duration.Companion.milliseconds +import kotlin.time.Duration.Companion.seconds -class PlayLogTest { +@RunWith(Parameterized::class) +internal class SingleMediaProductPlayLogTest(private val mediaProduct: MediaProduct) { @get:Rule val server = MockWebServer() @@ -74,6 +77,16 @@ class PlayLogTest { @Before fun setUp() { + responseDispatcher[ + "https://api.tidal.com/v1/tracks/${mediaProduct.productId}/playbackinfo?playbackmode=STREAM&assetpresentation=FULL&audioquality=LOW&immersiveaudio=true".toHttpUrl(), + ] = { + MockResponse().setBodyFromFile( + "api-responses/playbackinfo/tracks/playlogtest/get_1_bts.json", + ) + } + responseDispatcher["https://test.audio.tidal.com/1_bts.m4a".toHttpUrl()] = { + MockResponse().setBodyFromFile("raw/playlogtest/1_bts.m4a") + } EventReporterModuleRoot.reflectionComponentFactoryF = { PlayLogTestDefaultEventReporterComponentFactory(eventReporterCoroutineScope) } @@ -118,6 +131,7 @@ class PlayLogTest { companion object { private lateinit var originalEventReporterComponentFactoryF: () -> DefaultEventReporterComponent.Factory + private const val MEDIA_PRODUCT_DURATION_SECONDS = 5.055 @BeforeClass @JvmStatic @@ -125,6 +139,15 @@ class PlayLogTest { originalEventReporterComponentFactoryF = EventReporterModuleRoot.reflectionComponentFactoryF } + + @JvmStatic + @Parameterized.Parameters + fun parameters() = setOf( + MediaProduct(ProductType.TRACK, "1", "TESTA", "456"), + MediaProduct(ProductType.TRACK, "1", null, "789"), + MediaProduct(ProductType.TRACK, "1", "TESTB", null), + MediaProduct(ProductType.TRACK, "1", null, null), + ) } @After @@ -143,33 +166,7 @@ class PlayLogTest { } @Test - fun loadAndPlayUntilEndNoNulls() = - loadAndPlayUntilEnd(MediaProduct(ProductType.TRACK, "1", "TESTA", "456")) - - @Test - fun loadAndPlayUntilEndNullSourceType() = - loadAndPlayUntilEnd(MediaProduct(ProductType.TRACK, "1", null, "789")) - - @Test - fun loadAndPlayUntilEndNullSourceId() = - loadAndPlayUntilEnd(MediaProduct(ProductType.TRACK, "1", "TESTB", null)) - - @Test - fun loadAndPlayUntilEndNullSourceTypeNullSourceId() = - loadAndPlayUntilEnd(MediaProduct(ProductType.TRACK, "1", null, null)) - - private fun loadAndPlayUntilEnd(mediaProduct: MediaProduct) = runTest { - responseDispatcher[ - "https://api.tidal.com/v1/tracks/1/playbackinfo?playbackmode=STREAM&assetpresentation=FULL&audioquality=LOW&immersiveaudio=true".toHttpUrl(), - ] = { - MockResponse().setBodyFromFile( - "api-responses/playbackinfo/tracks/playlogtest/get_1_bts.json" - ) - } - responseDispatcher["https://test.audio.tidal.com/1_bts.m4a".toHttpUrl()] = { - MockResponse().setBodyFromFile("raw/playlogtest/1_bts.m4a") - } - + fun loadAndPlayUntilEnd() = runTest { player.playbackEngine.load(mediaProduct) player.playbackEngine.play() withContext(Dispatchers.Default.limitedParallelism(1)) { @@ -188,7 +185,7 @@ class PlayLogTest { assertThat(get("startAssetPosition").asDouble).isAssetPositionEqualTo(0.0) // https://github.com/androidx/media/issues/1253 assertThat(get("endAssetPosition").asDouble) - .isAssetPositionEqualTo(MEDIA_PRODUCT_DURATION_1_SECONDS) + .isAssetPositionEqualTo(MEDIA_PRODUCT_DURATION_SECONDS) assertThat(get("actualProductId").asString).isEqualTo(mediaProduct.productId) assertThat(get("sourceType")?.asString).isEqualTo(mediaProduct.sourceType) assertThat(get("sourceId")?.asString).isEqualTo(mediaProduct.sourceId) @@ -200,35 +197,10 @@ class PlayLogTest { ) } - @Test - fun loadAndPlayThenPauseThenPlayNoNulls() = - loadAndPlayThenPauseThenPlay(MediaProduct(ProductType.TRACK, "1", "TESTA", "456")) - - @Test - fun loadAndPlayThenPauseThenPlayNullSourceType() = - loadAndPlayThenPauseThenPlay(MediaProduct(ProductType.TRACK, "1", null, "789")) - - @Test - fun loadAndPlayThenPauseThenPlayNullSourceId() = - loadAndPlayThenPauseThenPlay(MediaProduct(ProductType.TRACK, "1", "TESTB", null)) - - @Test - fun loadAndPlayThenPauseThenPlayNullSourceTypeNullSourceId() = - loadAndPlayThenPauseThenPlay(MediaProduct(ProductType.TRACK, "1", null, null)) - @Suppress("LongMethod") - private fun loadAndPlayThenPauseThenPlay(mediaProduct: MediaProduct) = runTest { + @Test + fun loadAndPlayThenPauseThenPlay() = runTest { val gson = Gson() - responseDispatcher[ - "https://api.tidal.com/v1/tracks/1/playbackinfo?playbackmode=STREAM&assetpresentation=FULL&audioquality=LOW&immersiveaudio=true".toHttpUrl(), - ] = { - MockResponse().setBodyFromFile( - "api-responses/playbackinfo/tracks/playlogtest/get_1_bts.json", - ) - } - responseDispatcher["https://test.audio.tidal.com/1_bts.m4a".toHttpUrl()] = { - MockResponse().setBodyFromFile("raw/playlogtest/1_bts.m4a") - } player.playbackEngine.load(mediaProduct) player.playbackEngine.play() @@ -256,7 +228,7 @@ class PlayLogTest { with(gson.fromJson(this, JsonObject::class.java)["payload"].asJsonObject) { assertThat(get("startAssetPosition").asDouble).isAssetPositionEqualTo(0.0) assertThat(get("endAssetPosition").asDouble) - .isAssetPositionEqualTo(MEDIA_PRODUCT_DURATION_1_SECONDS) + .isAssetPositionEqualTo(MEDIA_PRODUCT_DURATION_SECONDS) assertThat(get("actualProductId").asString).isEqualTo(mediaProduct.productId) assertThat(get("sourceType")?.asString).isEqualTo(mediaProduct.sourceType) assertThat(get("sourceId")?.asString).isEqualTo(mediaProduct.sourceId) @@ -285,35 +257,10 @@ class PlayLogTest { ) } - @Test - fun loadAndPlayThenSeekForwardNoNulls() = - loadAndPlayThenSeekForward(MediaProduct(ProductType.TRACK, "1", "TESTA", "456")) - - @Test - fun loadAndPlayThenSeekForwardNullSourceType() = - loadAndPlayThenSeekForward(MediaProduct(ProductType.TRACK, "1", null, "789")) - - @Test - fun loadAndPlayThenSeekForwardNullSourceId() = - loadAndPlayThenSeekForward(MediaProduct(ProductType.TRACK, "1", "TESTB", null)) - - @Test - fun loadAndPlayThenSeekForwardNullSourceTypeNullSourceId() = - loadAndPlayThenSeekForward(MediaProduct(ProductType.TRACK, "1", null, null)) - @Suppress("LongMethod") - private fun loadAndPlayThenSeekForward(mediaProduct: MediaProduct) = runTest { + @Test + fun loadAndPlayThenSeekForward() = runTest { val gson = Gson() - responseDispatcher[ - "https://api.tidal.com/v1/tracks/1/playbackinfo?playbackmode=STREAM&assetpresentation=FULL&audioquality=LOW&immersiveaudio=true".toHttpUrl(), - ] = { - MockResponse().setBodyFromFile( - "api-responses/playbackinfo/tracks/playlogtest/get_1_bts.json", - ) - } - responseDispatcher["https://test.audio.tidal.com/1_bts.m4a".toHttpUrl()] = { - MockResponse().setBodyFromFile("raw/playlogtest/1_bts.m4a") - } player.playbackEngine.load(mediaProduct) player.playbackEngine.play() @@ -339,7 +286,7 @@ class PlayLogTest { with(gson.fromJson(this, JsonObject::class.java)["payload"].asJsonObject) { assertThat(get("startAssetPosition").asDouble).isAssetPositionEqualTo(0.0) assertThat(get("endAssetPosition").asDouble) - .isAssetPositionEqualTo(MEDIA_PRODUCT_DURATION_1_SECONDS) + .isAssetPositionEqualTo(MEDIA_PRODUCT_DURATION_SECONDS) assertThat(get("actualProductId").asString).isEqualTo(mediaProduct.productId) assertThat(get("sourceType")?.asString).isEqualTo(mediaProduct.sourceType) assertThat(get("sourceId")?.asString).isEqualTo(mediaProduct.sourceId) @@ -369,5 +316,3 @@ class PlayLogTest { isCloseTo(targetPosition, 0.5) } } - -private const val MEDIA_PRODUCT_DURATION_1_SECONDS = 5.055