Skip to content

Commit

Permalink
Merge branch 'develop' into multiple-classrooms-accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
adhiamboperes authored Aug 8, 2024
2 parents 3f4b504 + bfa471e commit 6974db4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,15 @@ class AudioPlayerController @Inject constructor(
*/
fun releaseMediaPlayer() {
audioLock.withLock {
check(mediaPlayerActive) { "Media player has not been previously initialized" }
mediaPlayerActive = false
isReleased = true
prepared = false
mediaPlayer.release()
stopUpdatingSeekBar()
playProgress = null
if (!isReleased) {
check(mediaPlayerActive) { "Media player has not been previously initialized" }
mediaPlayerActive = false
isReleased = true
prepared = false
mediaPlayer.release()
stopUpdatingSeekBar()
playProgress = null
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import dagger.BindsInstance
import dagger.Component
import dagger.Module
import dagger.Provides
import org.junit.Assert.fail
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -443,6 +444,17 @@ class AudioPlayerControllerTest {
.contains("Media player has not been previously initialized")
}

@Test
fun testController_releasePlayerMultipleTimes_doesNoThrowException() {
setUpMediaReadyApplication()
audioPlayerController.initializeMediaPlayer()

assertNoExceptionIsThrown {
audioPlayerController.releaseMediaPlayer()
audioPlayerController.releaseMediaPlayer()
}
}

@Test
fun testError_notPrepared_invokePlay_fails() {
setUpMediaReadyApplication()
Expand Down Expand Up @@ -872,6 +884,14 @@ class AudioPlayerControllerTest {
ApplicationProvider.getApplicationContext<TestApplication>().inject(this)
}

private fun assertNoExceptionIsThrown(block: () -> Unit) {
try {
block()
} catch (e: Exception) {
fail("Expected no exception, but got: $e")
}
}

// TODO(#89): Move this to a common test application component.
@Module
class TestModule {
Expand Down

0 comments on commit 6974db4

Please sign in to comment.