From 8d030b02ae988efff7db70236b7f69bc80736348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaquim=20Sta=CC=88hli?= Date: Thu, 10 Oct 2024 15:24:41 +0200 Subject: [PATCH] Fix tests --- .../player/PillarboxPreloadManagerTest.kt | 24 +----- .../srgssr/pillarbox/player/PlayerPoolTest.kt | 80 ------------------- 2 files changed, 1 insertion(+), 103 deletions(-) delete mode 100644 pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/PlayerPoolTest.kt diff --git a/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/PillarboxPreloadManagerTest.kt b/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/PillarboxPreloadManagerTest.kt index 6d6acd412..5e4bc9f67 100644 --- a/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/PillarboxPreloadManagerTest.kt +++ b/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/PillarboxPreloadManagerTest.kt @@ -20,25 +20,12 @@ import kotlin.test.assertTrue @RunWith(AndroidJUnit4::class) class PillarboxPreloadManagerTest { - private var createdPlayersCount = 0 private lateinit var preloadManager: PillarboxPreloadManager @BeforeTest fun setUp() { val context = ApplicationProvider.getApplicationContext() - - createdPlayersCount = 0 - preloadManager = PillarboxPreloadManager( - context = context, - playerFactory = { playbackLooper -> - createdPlayersCount++ - - PillarboxExoPlayer( - context = context, - playbackLooper = playbackLooper, - ) - }, - ) + preloadManager = PillarboxPreloadManager(context = context) } @AfterTest @@ -51,9 +38,6 @@ class PillarboxPreloadManagerTest { assertEquals(C.INDEX_UNSET, preloadManager.currentPlayingIndex) assertEquals(0, preloadManager.sourceCount) assertNull(preloadManager.getMediaSource(VOD1)) - assertNotNull(preloadManager.getPlayer(0)) - assertNull(preloadManager.getCurrentlyPlayingPlayer()) - assertEquals(1, createdPlayersCount) } @Test @@ -72,8 +56,6 @@ class PillarboxPreloadManagerTest { assertNotNull(preloadManager.getMediaSource(VOD3)) assertNotNull(preloadManager.getMediaSource(VOD4)) assertNull(preloadManager.getMediaSource(VOD5)) - assertEquals(preloadManager.getPlayer(2), preloadManager.getCurrentlyPlayingPlayer()) - assertEquals(1, createdPlayersCount) assertTrue(preloadManager.remove(VOD2)) assertTrue(preloadManager.remove(VOD3)) @@ -86,8 +68,6 @@ class PillarboxPreloadManagerTest { assertNull(preloadManager.getMediaSource(VOD3)) assertNotNull(preloadManager.getMediaSource(VOD4)) assertNull(preloadManager.getMediaSource(VOD5)) - assertEquals(preloadManager.getPlayer(2), preloadManager.getCurrentlyPlayingPlayer()) - assertEquals(1, createdPlayersCount) preloadManager.reset() preloadManager.invalidate() @@ -99,8 +79,6 @@ class PillarboxPreloadManagerTest { assertNull(preloadManager.getMediaSource(VOD3)) assertNull(preloadManager.getMediaSource(VOD4)) assertNull(preloadManager.getMediaSource(VOD5)) - assertEquals(preloadManager.getPlayer(2), preloadManager.getCurrentlyPlayingPlayer()) - assertEquals(1, createdPlayersCount) } private companion object { diff --git a/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/PlayerPoolTest.kt b/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/PlayerPoolTest.kt deleted file mode 100644 index 4fa73a948..000000000 --- a/pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/PlayerPoolTest.kt +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) SRG SSR. All rights reserved. - * License information is available from the LICENSE file. - */ -package ch.srgssr.pillarbox.player - -import androidx.test.core.app.ApplicationProvider -import androidx.test.ext.junit.runners.AndroidJUnit4 -import org.junit.runner.RunWith -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertFalse -import kotlin.test.assertNotNull -import kotlin.test.assertNull -import kotlin.test.assertTrue - -@RunWith(AndroidJUnit4::class) -class PlayerPoolTest { - @Test(expected = IllegalArgumentException::class) - fun `playerCount can not be negative`() { - PlayerPool( - playersCount = -1, - playerFactory = { PillarboxExoPlayer(ApplicationProvider.getApplicationContext()) }, - ) - } - - @Test(expected = IllegalArgumentException::class) - fun `playerCount can not be 0`() { - PlayerPool( - playersCount = 0, - playerFactory = { PillarboxExoPlayer(ApplicationProvider.getApplicationContext()) }, - ) - } - - @Test - fun `get player at position`() { - val playersCount = 5 - var createdPlayers = 0 - val pool = PlayerPool( - playersCount = playersCount, - playerFactory = { - createdPlayers++ - - PillarboxExoPlayer(ApplicationProvider.getApplicationContext()) - }, - ) - - // Invalid position - assertNull(pool.getPlayerAtPosition(-1)) - assertEquals(0, createdPlayers) - - // Position < playersCount - assertNotNull(pool.getPlayerAtPosition(2)) - assertEquals(1, createdPlayers) - - // Position > playersCount - val requestedPlayerOffset = 3 - assertNotNull(pool.getPlayerAtPosition(playersCount + requestedPlayerOffset)) - assertEquals(2, createdPlayers) - - // Reuse player instance - assertEquals(pool.getPlayerAtPosition(requestedPlayerOffset), pool.getPlayerAtPosition(playersCount + requestedPlayerOffset)) - assertEquals(2, createdPlayers) - } - - @Test - fun release() { - val pool = PlayerPool( - playersCount = 3, - playerFactory = { PillarboxExoPlayer(ApplicationProvider.getApplicationContext()) }, - ) - val player = pool.getPlayerAtPosition(1) - - assertNotNull(player) - assertFalse(player.isReleased) - - pool.release() - assertTrue(player.isReleased) - } -}