Skip to content

Commit

Permalink
Migrate remaining jUnit tests to Kotlin Test
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 committed Dec 19, 2024
1 parent b1ba2ce commit 775e034
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 30 deletions.
1 change: 1 addition & 0 deletions pillarbox-demo-shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ dependencies {
debugImplementation(libs.androidx.compose.ui.tooling)

testImplementation(libs.junit)
testImplementation(libs.kotlin.test)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import ch.srg.dataProvider.integrationlayer.data.remote.Media
import ch.srg.dataProvider.integrationlayer.data.remote.MediaType
import ch.srg.dataProvider.integrationlayer.data.remote.Type
import ch.srg.dataProvider.integrationlayer.data.remote.Vendor
import org.junit.Assert.assertEquals
import org.junit.Test
import java.util.Date
import java.util.Locale
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds
Expand Down
1 change: 1 addition & 0 deletions pillarbox-player/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ dependencies {
androidTestImplementation(libs.androidx.test.monitor)
androidTestRuntimeOnly(libs.androidx.test.runner)
androidTestImplementation(libs.junit)
androidTestImplementation(libs.kotlin.test)
androidTestRuntimeOnly(libs.kotlinx.coroutines.android)
androidTestImplementation(libs.mockk)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import androidx.media3.common.Player
import androidx.media3.common.util.ConditionVariable
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import ch.srgssr.pillarbox.player.utils.ContentUrls
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import java.util.concurrent.atomic.AtomicReference
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue

/**
* Instrumented test, which will execute on an Android device.
Expand Down Expand Up @@ -50,10 +52,10 @@ class IsPlayingAllTypeOfContentTest {
if (player.playerError != null) {
throw Exception(player.playerError)
}
Assert.assertEquals(Player.STATE_READY, player.playbackState)
Assert.assertTrue(player.isPlaying)
Assert.assertNotNull(player.currentMediaItem)
Assert.assertEquals(player.currentMediaItem?.localConfiguration?.uri, Uri.parse(urlToTest))
assertEquals(Player.STATE_READY, player.playbackState)
assertTrue(player.isPlaying)
assertNotNull(player.currentMediaItem)
assertEquals(player.currentMediaItem?.localConfiguration?.uri, Uri.parse(urlToTest))
player.release()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import ch.srgssr.pillarbox.player.test.utils.TestTimeline
import io.mockk.clearAllMocks
import io.mockk.every
import io.mockk.mockk
import org.junit.After
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import kotlin.test.AfterTest
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds

class TestIsPlaybackSpeedPossibleAtPosition {

@After
@AfterTest
fun tearDown() {
clearAllMocks()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ import androidx.media3.test.utils.robolectric.TestPlayerRunHelper
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.srgssr.pillarbox.player.extension.getPlaybackSpeed
import ch.srgssr.pillarbox.player.test.utils.TestPillarboxRunHelper
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Shadows.shadowOf
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals

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

@Before
@BeforeTest
fun createPlayer() {
player = PillarboxExoPlayer()
}

@After
@AfterTest
fun releasePlayer() {
player.release()
shadowOf(Looper.getMainLooper()).idle()
Expand All @@ -43,15 +44,15 @@ class TestPillarboxExoPlayerPlaybackSpeed {
play()
}
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)
Assert.assertEquals(Player.STATE_READY, player.playbackState)
assertEquals(Player.STATE_READY, player.playbackState)

player.setPlaybackSpeed(2f)
Assert.assertEquals(1f, player.getPlaybackSpeed())
assertEquals(1f, player.getPlaybackSpeed())

player.seekTo(0)
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)
player.setPlaybackSpeed(2f)
Assert.assertEquals(1f, player.getPlaybackSpeed())
assertEquals(1f, player.getPlaybackSpeed())
}

@Test
Expand All @@ -63,15 +64,15 @@ class TestPillarboxExoPlayerPlaybackSpeed {

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)
player.setPlaybackSpeed(2f)
Assert.assertEquals(1f, player.getPlaybackSpeed())
assertEquals(1f, player.getPlaybackSpeed())

player.seekTo(0)
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)

player.setPlaybackSpeed(2f)
Assert.assertEquals(2f, player.getPlaybackSpeed())
assertEquals(2f, player.getPlaybackSpeed())
TestPillarboxRunHelper.runUntilEvents(player, Player.EVENT_IS_LOADING_CHANGED)
Assert.assertEquals(2f, player.getPlaybackSpeed())
assertEquals(2f, player.getPlaybackSpeed())
}

@Test
Expand All @@ -82,16 +83,16 @@ class TestPillarboxExoPlayerPlaybackSpeed {
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)

val liveEdgePosition = player.currentTimeline.getWindow(0, Window()).defaultPositionMs
Assert.assertNotEquals(C.TIME_UNSET, liveEdgePosition)
assertNotEquals(C.TIME_UNSET, liveEdgePosition)
player.seekTo(liveEdgePosition - 5_000)
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)

val speed = 2f
player.setPlaybackSpeed(speed)
Assert.assertEquals(speed, player.getPlaybackSpeed())
assertEquals(speed, player.getPlaybackSpeed())

TestPillarboxRunHelper.runUntilPlaybackParametersChanged(player)
Assert.assertEquals(1f, player.getPlaybackSpeed())
assertEquals(1f, player.getPlaybackSpeed())
}

@Test
Expand All @@ -104,11 +105,11 @@ class TestPillarboxExoPlayerPlaybackSpeed {
val speed = 2f
player.setPlaybackSpeed(speed)
TestPillarboxRunHelper.runUntilEvents(player)
Assert.assertEquals(speed, player.getPlaybackSpeed())
assertEquals(speed, player.getPlaybackSpeed())

player.setPlaybackSpeed(1f)
TestPillarboxRunHelper.runUntilEvents(player)
Assert.assertEquals(1f, player.getPlaybackSpeed())
assertEquals(1f, player.getPlaybackSpeed())
}

private companion object {
Expand Down

0 comments on commit 775e034

Please sign in to comment.