diff --git a/dependencies.gradle b/dependencies.gradle index fdc2c5d941..604174fe57 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -29,7 +29,7 @@ def jjwt = "0.11.5" def vanniktechEmoji = "0.15.0" // Testing -def mockk = "1.12.3" +def mockk = "1.12.3" // We need to use 1.12.3 to have mocking in androidTest until a new version is released: https://github.com/mockk/mockk/issues/819 def espresso = "3.4.0" def androidxTest = "1.4.0" def androidxOrchestrator = "1.4.1" diff --git a/vector/build.gradle b/vector/build.gradle index 256ffd5b1f..46659f66a8 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -337,7 +337,6 @@ android { } dependencies { - implementation fileTree(dir: "libs", include: ["*.aar", "*.jar"]) implementation project(':library:opusencoder') implementation project(":vector-config") diff --git a/vector/src/androidTest/java/im/vector/app/features/voice/VoiceRecorderLTests.kt b/vector/src/androidTest/java/im/vector/app/features/voice/VoiceRecorderLTests.kt index a7cc252fb7..c02c2cac80 100644 --- a/vector/src/androidTest/java/im/vector/app/features/voice/VoiceRecorderLTests.kt +++ b/vector/src/androidTest/java/im/vector/app/features/voice/VoiceRecorderLTests.kt @@ -20,7 +20,6 @@ import android.Manifest import androidx.test.platform.app.InstrumentationRegistry import androidx.test.rule.GrantPermissionRule import io.mockk.spyk -import io.mockk.verify import kotlinx.coroutines.Dispatchers import org.amshove.kluent.shouldBeNull import org.amshove.kluent.shouldExist @@ -60,14 +59,13 @@ class VoiceRecorderLTests { } @Test - fun cancelRecordRemovesFileAfterStopping() = with(recorder) { + fun cancelRecordRemovesFile() = with(recorder) { startRecord("some_room_id") val file = recorder.getVoiceMessageFile() file.shouldNotBeNullAndExist() cancelRecord() - verify { stopRecord() } getVoiceMessageFile().shouldBeNull() file!!.shouldNotExist() } diff --git a/vector/src/androidTest/java/im/vector/app/features/voice/VoiceRecorderQTests.kt b/vector/src/androidTest/java/im/vector/app/features/voice/VoiceRecorderQTests.kt index 395c1f21d9..446d9e5b21 100644 --- a/vector/src/androidTest/java/im/vector/app/features/voice/VoiceRecorderQTests.kt +++ b/vector/src/androidTest/java/im/vector/app/features/voice/VoiceRecorderQTests.kt @@ -17,10 +17,14 @@ package im.vector.app.features.voice import android.Manifest +import android.os.Build +import androidx.test.filters.SdkSuppress import androidx.test.platform.app.InstrumentationRegistry import androidx.test.rule.GrantPermissionRule import io.mockk.spyk import io.mockk.verify +import kotlinx.coroutines.delay +import kotlinx.coroutines.runBlocking import org.amshove.kluent.shouldBeNull import org.amshove.kluent.shouldExist import org.amshove.kluent.shouldNotBeNull @@ -29,6 +33,7 @@ import org.junit.Rule import org.junit.Test import java.io.File +@SdkSuppress(minSdkVersion = Build.VERSION_CODES.Q) class VoiceRecorderQTests { @get:Rule @@ -38,38 +43,50 @@ class VoiceRecorderQTests { private val recorder = spyk(VoiceRecorderQ(context)) @Test - fun startRecordCreatesOggFile() = with(recorder) { - getVoiceMessageFile().shouldBeNull() + fun startRecordCreatesOggFile() = runBlocking { + with(recorder) { + getVoiceMessageFile().shouldBeNull() - startRecord("some_room_id") + startRecord("some_room_id") + waitForRecording() - getVoiceMessageFile().shouldNotBeNullAndExist() + getVoiceMessageFile().shouldNotBeNullAndExist() - stopRecord() + stopRecord() + } } @Test - fun stopRecordKeepsFile() = with(recorder) { - getVoiceMessageFile().shouldBeNull() + fun stopRecordKeepsFile() = runBlocking { + with(recorder) { + getVoiceMessageFile().shouldBeNull() - startRecord("some_room_id") - stopRecord() + startRecord("some_room_id") + waitForRecording() + stopRecord() - getVoiceMessageFile().shouldNotBeNullAndExist() + getVoiceMessageFile().shouldNotBeNullAndExist() + } } @Test - fun cancelRecordRemovesFileAfterStopping() = with(recorder) { - startRecord("some_room_id") - val file = recorder.getVoiceMessageFile() - file.shouldNotBeNullAndExist() + fun cancelRecordRemovesFileAfterStopping() = runBlocking { + with(recorder) { + startRecord("some_room_id") + val file = recorder.getVoiceMessageFile() + file.shouldNotBeNullAndExist() - cancelRecord() + waitForRecording() + cancelRecord() - verify { stopRecord() } - getVoiceMessageFile().shouldBeNull() - file!!.shouldNotExist() + verify { stopRecord() } + getVoiceMessageFile().shouldBeNull() + file!!.shouldNotExist() + } } + + // Give MediaRecorder some time to actually start recording + private suspend fun waitForRecording() = delay(10) } private fun File?.shouldNotBeNullAndExist() {