From cfda2d2b48cbaaaa271396fb43803e05e34eada8 Mon Sep 17 00:00:00 2001 From: Jorge Antonio Diaz-Benito Soriano Date: Thu, 27 Jun 2024 16:41:20 +0200 Subject: [PATCH] MF-171: Drop extra MediaProducts for additional coverage This also allows reusing the dispatcher configuration which all tests using a single MediaProduct need. --- ...st.kt => SingleMediaProductPlayLogTest.kt} | 107 ++++-------------- 1 file changed, 21 insertions(+), 86 deletions(-) rename player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/{PlayLogTest.kt => SingleMediaProductPlayLogTest.kt} (79%) 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..77454102 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 @@ -61,7 +61,7 @@ import org.mockito.kotlin.argThat import org.mockito.kotlin.eq import org.mockito.kotlin.verify -class PlayLogTest { +internal class SingleMediaProductPlayLogTest { @get:Rule val server = MockWebServer() @@ -70,6 +70,7 @@ class PlayLogTest { TestScope(StandardTestDispatcher(TestCoroutineScheduler())) private val responseDispatcher = PlayLogTestMockWebServerDispatcher(server) private val eventSender = mock() + private val mediaProduct = MediaProduct(ProductType.TRACK, "1", "TEST_1", "456") private lateinit var player: Player @Before @@ -77,6 +78,16 @@ class PlayLogTest { EventReporterModuleRoot.reflectionComponentFactoryF = { PlayLogTestDefaultEventReporterComponentFactory(eventReporterCoroutineScope) } + 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") + } server.dispatcher = responseDispatcher player = Player( @@ -143,33 +154,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 +173,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 +185,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 +216,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 +245,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 +274,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) @@ -370,4 +305,4 @@ class PlayLogTest { } } -private const val MEDIA_PRODUCT_DURATION_1_SECONDS = 5.055 +private const val MEDIA_PRODUCT_DURATION_SECONDS = 5.055