CallRecordingViewModelTest: enable testing LiveData and Rx without Looper

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey 2023-01-30 12:47:21 +01:00 committed by Marcel Hibbe
parent 4fee81c460
commit 4687341755
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
2 changed files with 23 additions and 2 deletions

View File

@ -290,6 +290,7 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:5.1.1'
testImplementation 'androidx.arch.core:core-testing:2.1.0'
androidTestImplementation "androidx.test:core:1.5.0"

View File

@ -1,12 +1,20 @@
package com.nextcloud.talk.viewmodels
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.nextcloud.talk.test.fakes.FakeCallRecordingRepository
import com.vividsolutions.jts.util.Assert
import io.reactivex.android.plugins.RxAndroidPlugins
import io.reactivex.schedulers.Schedulers
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Rule
import org.junit.Test
import org.mockito.MockitoAnnotations
internal class CallRecordingViewModelTest {
class CallRecordingViewModelTest {
@get:Rule
val instantExecutorRule = InstantTaskExecutorRule()
val repository = FakeCallRecordingRepository()
@ -19,10 +27,22 @@ internal class CallRecordingViewModelTest {
fun testCallRecordingViewModel_startRecord() {
val viewModel = CallRecordingViewModel(repository)
viewModel.setData("foo")
viewModel.clickRecordButton()
// implement extension function for liveData to await value?!
Assert.equals(CallRecordingViewModel.RecordingStartedState, viewModel.viewState)
Assert.equals(CallRecordingViewModel.RecordingStartLoadingState, viewModel.viewState.value)
}
companion object {
@JvmStatic
@BeforeClass
fun setUpClass() {
RxAndroidPlugins.setInitMainThreadSchedulerHandler {
Schedulers.trampoline()
}
}
}
}