Skip to content

Commit

Permalink
Remove TestPillarboxRunHelper.runUntilStartOfMediaItem in favor of …
Browse files Browse the repository at this point in the history
…`TestPillarboxRunHelper.playUntilStartOfMediaItem`
  • Loading branch information
MGaetan89 committed Mar 8, 2024
1 parent d1e236b commit 8a606fd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 64 deletions.
2 changes: 0 additions & 2 deletions pillarbox-core-business/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ dependencies {
implementation(libs.okhttp.logging.interceptor)
api(libs.tagcommander.core)

testImplementation(project(":pillarbox-player-testutils"))

testImplementation(libs.androidx.media3.test.utils)
testImplementation(libs.androidx.media3.test.utils.robolectric)
testImplementation(libs.androidx.test.core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import ch.srgssr.pillarbox.core.business.integrationlayer.service.MediaCompositi
import ch.srgssr.pillarbox.core.business.tracker.DefaultMediaItemTrackerRepository
import ch.srgssr.pillarbox.core.business.tracker.comscore.ComScoreTracker
import ch.srgssr.pillarbox.player.data.MediaItemSource
import ch.srgssr.pillarbox.player.test.utils.TestPillarboxRunHelper
import ch.srgssr.pillarbox.player.tracker.MediaItemTrackerRepository
import io.mockk.Called
import io.mockk.confirmVerified
Expand Down Expand Up @@ -136,7 +135,7 @@ class CommandersActTrackerIntegrationTest {
player.playWhenReady = true

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)
TestPillarboxRunHelper.runUntilStartOfMediaItem(player, 0)
TestPlayerRunHelper.playUntilStartOfMediaItem(player, 0)

player.setMediaItem(MediaItemUrn(URN_NOT_LIVE_VIDEO))
player.playWhenReady = true
Expand Down Expand Up @@ -177,7 +176,7 @@ class CommandersActTrackerIntegrationTest {
player.playWhenReady = true

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)
TestPillarboxRunHelper.runUntilStartOfMediaItem(player, 0)
TestPlayerRunHelper.playUntilStartOfMediaItem(player, 0)

verifyOrder {
commandersAct.enableRunningInBackground()
Expand Down Expand Up @@ -227,7 +226,7 @@ class CommandersActTrackerIntegrationTest {
player.playWhenReady = true

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)
TestPillarboxRunHelper.runUntilStartOfMediaItem(player, 0)
TestPlayerRunHelper.playUntilStartOfMediaItem(player, 0)

verifyOrder {
commandersAct.enableRunningInBackground()
Expand All @@ -252,7 +251,7 @@ class CommandersActTrackerIntegrationTest {
player.setPlaybackSpeed(2f)

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)
TestPillarboxRunHelper.runUntilStartOfMediaItem(player, 0)
TestPlayerRunHelper.playUntilStartOfMediaItem(player, 0)

verifyOrder {
commandersAct.enableRunningInBackground()
Expand All @@ -276,7 +275,7 @@ class CommandersActTrackerIntegrationTest {
player.playWhenReady = true

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)
TestPillarboxRunHelper.runUntilStartOfMediaItem(player, 0)
TestPlayerRunHelper.playUntilStartOfMediaItem(player, 0)

clock.advanceTime(5.minutes.inWholeMilliseconds)
player.setPlaybackSpeed(2f)
Expand Down Expand Up @@ -305,7 +304,7 @@ class CommandersActTrackerIntegrationTest {
player.playWhenReady = true

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)
TestPillarboxRunHelper.runUntilStartOfMediaItem(player, 0)
TestPlayerRunHelper.playUntilStartOfMediaItem(player, 0)

clock.advanceTime(2.minutes.inWholeMilliseconds)
player.playWhenReady = false
Expand Down Expand Up @@ -340,7 +339,7 @@ class CommandersActTrackerIntegrationTest {
player.playWhenReady = true

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)
TestPillarboxRunHelper.runUntilStartOfMediaItem(player, 0)
TestPlayerRunHelper.playUntilStartOfMediaItem(player, 0)

clock.advanceTime(2.minutes.inWholeMilliseconds)
player.playWhenReady = false
Expand Down Expand Up @@ -386,7 +385,7 @@ class CommandersActTrackerIntegrationTest {
player.playWhenReady = true

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)
TestPillarboxRunHelper.runUntilStartOfMediaItem(player, 0)
TestPlayerRunHelper.playUntilStartOfMediaItem(player, 0)

clock.advanceTime(2.minutes.inWholeMilliseconds)
player.stop()
Expand Down Expand Up @@ -420,7 +419,7 @@ class CommandersActTrackerIntegrationTest {
player.playWhenReady = true

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)
TestPillarboxRunHelper.runUntilStartOfMediaItem(player, 0)
TestPlayerRunHelper.playUntilStartOfMediaItem(player, 0)

clock.advanceTime(2.minutes.inWholeMilliseconds)
player.seekTo(30.seconds.inWholeMilliseconds)
Expand Down Expand Up @@ -489,7 +488,7 @@ class CommandersActTrackerIntegrationTest {
player.playWhenReady = true

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)
TestPillarboxRunHelper.runUntilStartOfMediaItem(player, 0)
TestPlayerRunHelper.playUntilStartOfMediaItem(player, 0)

clock.advanceTime(2.seconds.inWholeMilliseconds)
advanceTimeBy(2.seconds)
Expand Down Expand Up @@ -599,7 +598,7 @@ class CommandersActTrackerIntegrationTest {
player.playWhenReady = true

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)
TestPillarboxRunHelper.runUntilStartOfMediaItem(player, 0)
TestPlayerRunHelper.playUntilStartOfMediaItem(player, 0)

clock.advanceTime(playTime.inWholeMilliseconds)
advanceTimeBy(playTime)
Expand Down Expand Up @@ -712,7 +711,7 @@ class CommandersActTrackerIntegrationTest {
player.playWhenReady = true

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)
TestPillarboxRunHelper.runUntilStartOfMediaItem(player, 0)
TestPlayerRunHelper.playUntilStartOfMediaItem(player, 0)

clock.advanceTime(playTime.inWholeMilliseconds)
advanceTimeBy(playTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import androidx.media3.common.PlaybackParameters
import androidx.media3.common.Player
import androidx.media3.common.util.Assertions
import androidx.media3.common.util.Clock
import androidx.media3.common.util.ConditionVariable
import androidx.media3.common.util.Util
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.test.utils.robolectric.RobolectricUtil
import androidx.media3.test.utils.robolectric.TestPlayerRunHelper
import java.util.concurrent.TimeoutException
import java.util.concurrent.atomic.AtomicBoolean

Expand Down Expand Up @@ -85,50 +82,4 @@ object TestPillarboxRunHelper {
throw IllegalStateException(player.playerError)
}
}

/**
* Same as [TestPlayerRunHelper.playUntilStartOfMediaItem], but doesn't pause the player afterwards.
*
* @param player The [Player].
* @param mediaItemIndex The index of the media item.
*
* @throws TimeoutException If the [default timeout][RobolectricUtil.DEFAULT_TIMEOUT_MS] is exceeded.
*
* @see TestPlayerRunHelper.playUntilStartOfMediaItem
*/
@Throws(TimeoutException::class)
fun runUntilStartOfMediaItem(player: ExoPlayer, mediaItemIndex: Int) {
verifyMainTestThread(player)
verifyPlaybackThreadIsAlive(player)

val applicationLooper = Util.getCurrentOrMainLooper()
val messageHandled = AtomicBoolean(false)

player
.createMessage { _, _ ->
// Block playback thread until pause command has been sent from test thread.
val blockPlaybackThreadCondition = ConditionVariable()

player.clock
.createHandler(applicationLooper, null)
.post {
messageHandled.set(true)
blockPlaybackThreadCondition.open()
}

try {
player.clock.onThreadBlocked()
blockPlaybackThreadCondition.block()
} catch (e: InterruptedException) {
// Ignore.
}
}
.setPosition(mediaItemIndex, 0L)
.send()
player.play()
RobolectricUtil.runMainLooperUntil { messageHandled.get() || player.playerError != null }
if (player.playerError != null) {
throw IllegalStateException(player.playerError)
}
}
}

0 comments on commit 8a606fd

Please sign in to comment.