summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModelTest.kt4
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModelTest.kt6
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SettingsViewModelTest.kt5
-rw-r--r--android/lib/common-test/src/main/java/net/mullvad/mullvadvpn/lib/common/test/TestCoroutineRule.kt14
4 files changed, 19 insertions, 10 deletions
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModelTest.kt
index 32cce31136..fa46aff444 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModelTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModelTest.kt
@@ -13,7 +13,7 @@ import io.mockk.verify
import io.mockk.verifyOrder
import junit.framework.Assert.assertEquals
import kotlinx.coroutines.flow.MutableStateFlow
-import kotlinx.coroutines.test.TestCoroutineDispatcher
+import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runBlockingTest
import net.mullvad.mullvadvpn.compose.state.DeviceRevokedUiState
import net.mullvad.mullvadvpn.model.TunnelState
@@ -48,7 +48,7 @@ class DeviceRevokedViewModelTest {
DeviceRevokedViewModel(
mockedServiceConnectionManager,
mockedAccountRepository,
- TestCoroutineDispatcher()
+ UnconfinedTestDispatcher()
)
}
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModelTest.kt
index 6938c4092c..4ba80511c6 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModelTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModelTest.kt
@@ -11,7 +11,7 @@ import junit.framework.Assert.assertEquals
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
-import kotlinx.coroutines.test.TestCoroutineDispatcher
+import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.test.setMain
import net.mullvad.mullvadvpn.lib.ipc.Event
@@ -45,7 +45,7 @@ class LoginViewModelTest {
@Before
fun setup() {
- Dispatchers.setMain(TestCoroutineDispatcher())
+ Dispatchers.setMain(UnconfinedTestDispatcher())
MockKAnnotations.init(this, relaxUnitFun = true)
every { mockedAccountRepository.accountCreationEvents } returns accountCreationTestEvents
@@ -59,7 +59,7 @@ class LoginViewModelTest {
LoginViewModel(
mockedAccountRepository,
mockedDeviceRepository,
- TestCoroutineDispatcher()
+ UnconfinedTestDispatcher()
)
}
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SettingsViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SettingsViewModelTest.kt
index 0d87ed9311..a858913b31 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SettingsViewModelTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SettingsViewModelTest.kt
@@ -89,9 +89,14 @@ class SettingsViewModelTest {
isOutdated = false,
isSupported = true
)
+ every { mockAppVersionInfoCache.version } returns "1.0"
+ every { mockAppVersionInfoCache.isSupported } returns true
+ every { mockAppVersionInfoCache.isOutdated } returns false
// Act, Assert
viewModel.uiState.test {
+ awaitItem() // Wait for initial value
+
serviceConnectionState.value =
ServiceConnectionState.ConnectedReady(mockServiceConnectionContainer)
versionInfo.value = versionInfoTestItem
diff --git a/android/lib/common-test/src/main/java/net/mullvad/mullvadvpn/lib/common/test/TestCoroutineRule.kt b/android/lib/common-test/src/main/java/net/mullvad/mullvadvpn/lib/common/test/TestCoroutineRule.kt
index 2488aab66e..d04983be26 100644
--- a/android/lib/common-test/src/main/java/net/mullvad/mullvadvpn/lib/common/test/TestCoroutineRule.kt
+++ b/android/lib/common-test/src/main/java/net/mullvad/mullvadvpn/lib/common/test/TestCoroutineRule.kt
@@ -1,23 +1,27 @@
package net.mullvad.mullvadvpn.lib.common.test
import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.test.TestCoroutineDispatcher
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.TestDispatcher
+import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.junit.rules.TestWatcher
import org.junit.runner.Description
-class TestCoroutineRule(val testDispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher()) :
+@OptIn(ExperimentalCoroutinesApi::class)
+class TestCoroutineRule(val testDispatcher: TestDispatcher = UnconfinedTestDispatcher()) :
TestWatcher() {
- override fun starting(description: Description?) {
+ override fun starting(description: Description) {
super.starting(description)
Dispatchers.setMain(testDispatcher)
}
- override fun finished(description: Description?) {
+ override fun finished(description: Description) {
super.finished(description)
Dispatchers.resetMain()
- testDispatcher.cleanupTestCoroutines()
+ // Replacement for cleanupTestCoroutines()
+ testDispatcher.scheduler.runCurrent()
}
}