Skip to content

Commit

Permalink
Fix voice recording tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinesp committed Sep 6, 2022
1 parent b4fcffb commit 273999e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,36 @@ import android.os.Build
import androidx.test.platform.app.InstrumentationRegistry
import im.vector.app.AndroidVersionTestOverrider
import im.vector.app.features.DefaultVectorFeatures
import io.mockk.every
import io.mockk.spyk
import org.amshove.kluent.shouldBeInstanceOf
import org.junit.After
import org.junit.Test

class VoiceRecorderProviderTests {

private val context = InstrumentationRegistry.getInstrumentation().targetContext
private val provider = VoiceRecorderProvider(context, DefaultVectorFeatures())
private val provider = spyk(VoiceRecorderProvider(context, DefaultVectorFeatures()))

@After
fun tearDown() {
AndroidVersionTestOverrider.restore()
}

@Test
fun provideVoiceRecorderOnAndroidQReturnsQRecorder() {
fun provideVoiceRecorderOnAndroidQAndCodecReturnsQRecorder() {
AndroidVersionTestOverrider.override(Build.VERSION_CODES.Q)
every { provider.hasOpusEncoder() } returns true
provider.provideVoiceRecorder().shouldBeInstanceOf(VoiceRecorderQ::class)
}

@Test
fun provideVoiceRecorderOnAndroidQButNoCodecReturnsLRecorder() {
AndroidVersionTestOverrider.override(Build.VERSION_CODES.Q)
every { provider.hasOpusEncoder() } returns false
provider.provideVoiceRecorder().shouldBeInstanceOf(VoiceRecorderL::class)
}

@Test
fun provideVoiceRecorderOnOlderAndroidVersionReturnsLRecorder() {
AndroidVersionTestOverrider.override(Build.VERSION_CODES.LOLLIPOP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.content.Context
import android.media.MediaCodecList
import android.media.MediaFormat
import android.os.Build
import androidx.annotation.VisibleForTesting
import im.vector.app.features.VectorFeatures
import kotlinx.coroutines.Dispatchers
import javax.inject.Inject
Expand All @@ -40,7 +41,8 @@ class VoiceRecorderProvider @Inject constructor(
return Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || !hasOpusEncoder() || vectorFeatures.forceUsageOfOpusEncoder()
}

private fun hasOpusEncoder(): Boolean {
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal fun hasOpusEncoder(): Boolean {
val codecList = MediaCodecList(MediaCodecList.ALL_CODECS)
val format = MediaFormat.createAudioFormat(MediaFormat.MIMETYPE_AUDIO_OPUS, 48000, 1)
return codecList.findEncoderForFormat(format) != null
Expand Down

0 comments on commit 273999e

Please sign in to comment.