Skip to content

Commit fc405fe

Browse files
committed
Simplify code
1 parent 35ed89d commit fc405fe

File tree

2 files changed

+2
-34
lines changed

2 files changed

+2
-34
lines changed

pillarbox-player-testutils/src/main/java/ch/srgssr/pillarbox/player/test/utils/TestPillarboxRunHelper.kt

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -105,36 +105,4 @@ object TestPillarboxRunHelper {
105105
player.currentPosition >= position.inWholeMilliseconds
106106
}
107107
}
108-
109-
/**
110-
* Run and wait until [Player.isPlaying] is [isPlaying].
111-
112-
* If a playback error occurs, it will be thrown wrapped in an [IllegalStateException].
113-
*
114-
* @param player The [Player].
115-
* @param isPlaying The expected value of [Player.isPlaying].
116-
117-
* @throws TimeoutException If the [RobolectricUtil.DEFAULT_TIMEOUT_MS] is exceeded.
118-
*/
119-
@Throws(TimeoutException::class)
120-
fun runUntilIsPlaying(player: Player, isPlaying: Boolean) {
121-
verifyMainTestThread(player)
122-
if (player is ExoPlayer) {
123-
verifyPlaybackThreadIsAlive(player)
124-
}
125-
val receivedCallback = AtomicBoolean(false)
126-
val listener = object : Player.Listener {
127-
override fun onIsPlayingChanged(actual: Boolean) {
128-
if (actual == isPlaying) {
129-
receivedCallback.set(true)
130-
}
131-
}
132-
}
133-
player.addListener(listener)
134-
RobolectricUtil.runMainLooperUntil { receivedCallback.get() || player.playerError != null }
135-
player.removeListener(listener)
136-
if (player.playerError != null) {
137-
throw IllegalStateException(player.playerError)
138-
}
139-
}
140108
}

pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/IsPlayingAllTypeOfContentTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import android.os.Looper
99
import androidx.media3.common.MediaItem
1010
import androidx.media3.common.Player
1111
import androidx.media3.test.utils.FakeClock
12+
import androidx.media3.test.utils.robolectric.TestPlayerRunHelper
1213
import androidx.test.core.app.ApplicationProvider
13-
import ch.srgssr.pillarbox.player.test.utils.TestPillarboxRunHelper
1414
import org.junit.runner.RunWith
1515
import org.robolectric.ParameterizedRobolectricTestRunner
1616
import org.robolectric.ParameterizedRobolectricTestRunner.Parameters
@@ -54,7 +54,7 @@ class IsPlayingAllTypeOfContentTest(
5454
player.prepare()
5555
player.play()
5656

57-
TestPillarboxRunHelper.runUntilIsPlaying(player, isPlaying = true)
57+
TestPlayerRunHelper.play(player).untilBackgroundThreadCondition { player.isPlaying }
5858

5959
assertEquals(Player.STATE_READY, player.playbackState)
6060
assertTrue(player.isPlaying)

0 commit comments

Comments
 (0)