Use runCatching instead of try/catch in PlayerExtensionsTest

PiperOrigin-RevId: 661992546
This commit is contained in:
ibaker 2024-08-12 01:41:44 -07:00 committed by Copybara-Service
parent a76ff16179
commit ef6cb5d913

View File

@ -113,15 +113,14 @@ class PlayerExtensionsTest {
fun playerListen_onEventsThrowsException_bubblesOutAndUnregistersListener() = runTest { fun playerListen_onEventsThrowsException_bubblesOutAndUnregistersListener() = runTest {
val player = PlayerWithListeners(TestExoPlayerBuilder(context).build()) val player = PlayerWithListeners(TestExoPlayerBuilder(context).build())
val exceptionFromListen = async { val exceptionFromListen = async {
try { runCatching {
player.listen { events -> player.listen { events ->
if (Player.EVENT_VOLUME_CHANGED in events) { if (Player.EVENT_VOLUME_CHANGED in events) {
throw IllegalStateException("Volume event!") throw IllegalStateException("Volume event!")
}
} }
} }
} catch (expected: IllegalStateException) { .exceptionOrNull()
expected
}
} }
// Wait for the Player.Listener to be registered inside player.listen // Wait for the Player.Listener to be registered inside player.listen
testScheduler.runCurrent() testScheduler.runCurrent()