Fix voice recording tests
This commit is contained in:
parent
b4fcffbdf9
commit
273999ee88
|
@ -20,6 +20,8 @@ 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
|
||||
|
@ -27,7 +29,7 @@ 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() {
|
||||
|
@ -35,11 +37,19 @@ class VoiceRecorderProviderTests {
|
|||
}
|
||||
|
||||
@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)
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue