Skip to content

Commit

Permalink
Use PillarboxExoPlayer constructor from test
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 committed Dec 16, 2024
1 parent ec8e843 commit bb3f5ea
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
*/
package ch.srgssr.pillarbox.player

import android.content.Context
import android.os.Looper
import androidx.media3.common.C
import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.common.Timeline.Window
import androidx.media3.test.utils.FakeClock
import androidx.media3.test.utils.robolectric.TestPlayerRunHelper
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.srgssr.pillarbox.player.extension.getPlaybackSpeed
import ch.srgssr.pillarbox.player.test.utils.TestPillarboxRunHelper
Expand All @@ -22,19 +19,14 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Shadows.shadowOf
import kotlin.coroutines.EmptyCoroutineContext

@RunWith(AndroidJUnit4::class)
class TestPillarboxExoPlayerPlaybackSpeed {
private lateinit var player: PillarboxExoPlayer

@Before
fun createPlayer() {
val context = ApplicationProvider.getApplicationContext<Context>()
player = PillarboxExoPlayer(context) {
clock(FakeClock(true))
coroutineContext(EmptyCoroutineContext)
}
player = PillarboxExoPlayer()
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
*/
package ch.srgssr.pillarbox.player.analytics

import android.content.Context
import android.os.Looper
import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.test.utils.FakeClock
import androidx.media3.test.utils.robolectric.TestPlayerRunHelper
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.srgssr.pillarbox.player.PillarboxExoPlayer
import io.mockk.clearAllMocks
import io.mockk.clearMocks
import io.mockk.confirmVerified
Expand All @@ -32,23 +30,15 @@ import kotlin.test.assertTrue

@RunWith(AndroidJUnit4::class)
class PlaybackSessionManagerTest {
private lateinit var clock: FakeClock
private lateinit var player: ExoPlayer
private lateinit var sessionManager: PlaybackSessionManager
private lateinit var sessionManagerListener: PlaybackSessionManager.Listener

@BeforeTest
fun setUp() {
val context = ApplicationProvider.getApplicationContext<Context>()

clock = FakeClock(true)
sessionManagerListener = mockk(relaxed = true)
player = ExoPlayer.Builder(context)
.setClock(clock)
.build()
.apply {
prepare()
}
player = PillarboxExoPlayer()
player.prepare()

sessionManager = PlaybackSessionManager().apply {
setPlayer(player)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
*/
package ch.srgssr.pillarbox.player.utils

import android.content.Context
import android.os.Looper
import androidx.media3.exoplayer.ExoPlayer
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.srgssr.pillarbox.player.PillarboxExoPlayer
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestDispatcher
import kotlinx.coroutines.test.UnconfinedTestDispatcher
Expand Down Expand Up @@ -308,8 +306,7 @@ class HeartbeatTest {

@Test
fun `verify player is accessible from the task`() {
val context = ApplicationProvider.getApplicationContext<Context>()
val player = ExoPlayer.Builder(context).build()
val player = PillarboxExoPlayer()
runTest(testDispatcher) {
var taskCalled = false

Expand Down

0 comments on commit bb3f5ea

Please sign in to comment.