summaryrefslogtreecommitdiffhomepage
path: root/android/app/src
diff options
context:
space:
mode:
authorDavid Göransson <david.goransson@mullvad.net>2024-06-14 15:00:23 +0200
committerAlbin <albin@mullvad.net>2024-06-19 09:28:48 +0200
commitd09b5053b7b6cb2a65d047d0b90d195192f6ecf3 (patch)
treec29e89ae8f3e0c2d90915af6829ef7199e8b6a7e /android/app/src
parent9be52437a1a9065ca7fa2f831f0833cf959e2e36 (diff)
downloadmullvadvpn-d09b5053b7b6cb2a65d047d0b90d195192f6ecf3.tar.xz
mullvadvpn-d09b5053b7b6cb2a65d047d0b90d195192f6ecf3.zip
Align UseCases
Diffstat (limited to 'android/app/src')
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt12
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/InAppNotificationController.kt8
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/NewDeviceRepository.kt18
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryNotificationUseCase.kt2
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AvailableProvidersUseCase.kt2
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilteredRelayListUseCase.kt2
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/InternetAvailableUseCase.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/ConnectivityUseCase.kt)4
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceNotificationUseCase.kt21
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/PaymentUseCase.kt8
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SelectedLocationTitleUseCase.kt2
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SystemVpnSettingsAvailableUseCase.kt (renamed from android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SystemVpnSettingsUseCase.kt)4
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/TunnelStateNotificationUseCase.kt2
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/VersionNotificationUseCase.kt2
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt18
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListRelayItemsUseCase.kt4
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListsRelayItemUseCase.kt2
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt8
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CreateCustomListDialogViewModel.kt3
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt9
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListsViewModel.kt2
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeleteCustomListConfirmationViewModel.kt3
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListNameDialogViewModel.kt3
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/FilterViewModel.kt6
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModel.kt12
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt14
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt7
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryNotificationUseCaseTest.kt8
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt12
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceUseNotificationCaseTest.kt6
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/TunnelStateNotificationUseCaseTest.kt6
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/VersionNotificationUseCaseTest.kt6
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModelTest.kt10
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelTest.kt5
33 files changed, 119 insertions, 112 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt
index 70153de619..d752460ddb 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt
@@ -19,6 +19,7 @@ import net.mullvad.mullvadvpn.repository.ApiAccessRepository
import net.mullvad.mullvadvpn.repository.ChangelogRepository
import net.mullvad.mullvadvpn.repository.CustomListsRepository
import net.mullvad.mullvadvpn.repository.InAppNotificationController
+import net.mullvad.mullvadvpn.repository.NewDeviceRepository
import net.mullvad.mullvadvpn.repository.PrivacyDisclaimerRepository
import net.mullvad.mullvadvpn.repository.ProblemReportRepository
import net.mullvad.mullvadvpn.repository.RelayListFilterRepository
@@ -30,16 +31,16 @@ import net.mullvad.mullvadvpn.ui.serviceconnection.AppVersionInfoRepository
import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionManager
import net.mullvad.mullvadvpn.usecase.AccountExpiryNotificationUseCase
import net.mullvad.mullvadvpn.usecase.AvailableProvidersUseCase
-import net.mullvad.mullvadvpn.usecase.ConnectivityUseCase
import net.mullvad.mullvadvpn.usecase.EmptyPaymentUseCase
import net.mullvad.mullvadvpn.usecase.FilteredRelayListUseCase
+import net.mullvad.mullvadvpn.usecase.InternetAvailableUseCase
import net.mullvad.mullvadvpn.usecase.LastKnownLocationUseCase
import net.mullvad.mullvadvpn.usecase.NewDeviceNotificationUseCase
import net.mullvad.mullvadvpn.usecase.OutOfTimeUseCase
import net.mullvad.mullvadvpn.usecase.PaymentUseCase
import net.mullvad.mullvadvpn.usecase.PlayPaymentUseCase
import net.mullvad.mullvadvpn.usecase.SelectedLocationTitleUseCase
-import net.mullvad.mullvadvpn.usecase.SystemVpnSettingsUseCase
+import net.mullvad.mullvadvpn.usecase.SystemVpnSettingsAvailableUseCase
import net.mullvad.mullvadvpn.usecase.TunnelStateNotificationUseCase
import net.mullvad.mullvadvpn.usecase.VersionNotificationUseCase
import net.mullvad.mullvadvpn.usecase.customlists.CustomListActionUseCase
@@ -122,14 +123,15 @@ val uiModule = module {
single { VoucherRepository(get(), get()) }
single { SplitTunnelingRepository(get()) }
single { ApiAccessRepository(get()) }
+ single { NewDeviceRepository() }
single { AccountExpiryNotificationUseCase(get()) }
single { TunnelStateNotificationUseCase(get()) }
single { VersionNotificationUseCase(get(), BuildConfig.ENABLE_IN_APP_VERSION_NOTIFICATIONS) }
- single { NewDeviceNotificationUseCase(get()) }
+ single { NewDeviceNotificationUseCase(get(), get()) }
single { OutOfTimeUseCase(get(), get(), MainScope()) }
- single { ConnectivityUseCase(get()) }
- single { SystemVpnSettingsUseCase(androidContext()) }
+ single { InternetAvailableUseCase(get()) }
+ single { SystemVpnSettingsAvailableUseCase(androidContext()) }
single { CustomListActionUseCase(get(), get()) }
single { SelectedLocationTitleUseCase(get(), get()) }
single { AvailableProvidersUseCase(get()) }
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/InAppNotificationController.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/InAppNotificationController.kt
index decff575f8..79db20d390 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/InAppNotificationController.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/InAppNotificationController.kt
@@ -64,10 +64,10 @@ class InAppNotificationController(
val notifications =
combine(
- tunnelStateNotificationUseCase.notifications(),
- versionNotificationUseCase.notifications(),
- accountExpiryNotificationUseCase.notifications(),
- newDeviceNotificationUseCase.notifications(),
+ tunnelStateNotificationUseCase(),
+ versionNotificationUseCase(),
+ accountExpiryNotificationUseCase(),
+ newDeviceNotificationUseCase(),
) { a, b, c, d ->
a + b + c + d
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/NewDeviceRepository.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/NewDeviceRepository.kt
new file mode 100644
index 0000000000..37448ed0b9
--- /dev/null
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/NewDeviceRepository.kt
@@ -0,0 +1,18 @@
+package net.mullvad.mullvadvpn.repository
+
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.StateFlow
+
+class NewDeviceRepository {
+ private val _mutableShowNewDeviceNotification = MutableStateFlow(false)
+
+ val isNewDevice: StateFlow<Boolean> = _mutableShowNewDeviceNotification
+
+ fun newDeviceCreated() {
+ _mutableShowNewDeviceNotification.value = true
+ }
+
+ fun clearNewDeviceCreatedNotification() {
+ _mutableShowNewDeviceNotification.value = false
+ }
+}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryNotificationUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryNotificationUseCase.kt
index 65822788cb..4a7f1092a7 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryNotificationUseCase.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryNotificationUseCase.kt
@@ -12,7 +12,7 @@ import org.joda.time.DateTime
class AccountExpiryNotificationUseCase(
private val accountRepository: AccountRepository,
) {
- fun notifications(): Flow<List<InAppNotification>> =
+ operator fun invoke(): Flow<List<InAppNotification>> =
accountRepository.accountData
.map(::accountExpiryNotification)
.map(::listOfNotNull)
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AvailableProvidersUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AvailableProvidersUseCase.kt
index f79c0421f6..14aa3824cf 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AvailableProvidersUseCase.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AvailableProvidersUseCase.kt
@@ -8,7 +8,7 @@ import net.mullvad.mullvadvpn.repository.RelayListRepository
class AvailableProvidersUseCase(private val relayListRepository: RelayListRepository) {
- fun availableProviders(): Flow<List<Provider>> =
+ operator fun invoke(): Flow<List<Provider>> =
relayListRepository.relayList.map { relayList ->
relayList
.flatMap(RelayItem.Location.Country::cities)
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilteredRelayListUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilteredRelayListUseCase.kt
index 265c127227..c4e05ccc92 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilteredRelayListUseCase.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilteredRelayListUseCase.kt
@@ -13,7 +13,7 @@ class FilteredRelayListUseCase(
private val relayListRepository: RelayListRepository,
private val relayListFilterRepository: RelayListFilterRepository
) {
- fun filteredRelayList() =
+ operator fun invoke() =
combine(
relayListRepository.relayList,
relayListFilterRepository.selectedOwnership,
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/ConnectivityUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/InternetAvailableUseCase.kt
index 35983a86c0..a9a49e0cd6 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/ConnectivityUseCase.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/InternetAvailableUseCase.kt
@@ -4,8 +4,8 @@ import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
-class ConnectivityUseCase(val context: Context) {
- fun isInternetAvailable(): Boolean {
+class InternetAvailableUseCase(val context: Context) {
+ operator fun invoke(): Boolean {
val connectivityManager =
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceNotificationUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceNotificationUseCase.kt
index 06d26a76e8..12ce356155 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceNotificationUseCase.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceNotificationUseCase.kt
@@ -1,19 +1,20 @@
package net.mullvad.mullvadvpn.usecase
-import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import net.mullvad.mullvadvpn.lib.shared.DeviceRepository
import net.mullvad.mullvadvpn.repository.InAppNotification
+import net.mullvad.mullvadvpn.repository.NewDeviceRepository
-class NewDeviceNotificationUseCase(private val deviceRepository: DeviceRepository) {
- private val _mutableShowNewDeviceNotification = MutableStateFlow(false)
-
- fun notifications() =
+class NewDeviceNotificationUseCase(
+ private val newDeviceRepository: NewDeviceRepository,
+ private val deviceRepository: DeviceRepository
+) {
+ operator fun invoke() =
combine(
deviceRepository.deviceState.map { it?.displayName() },
- _mutableShowNewDeviceNotification
+ newDeviceRepository.isNewDevice
) { deviceName, newDeviceCreated ->
if (newDeviceCreated && deviceName != null) {
InAppNotification.NewDevice(deviceName)
@@ -21,12 +22,4 @@ class NewDeviceNotificationUseCase(private val deviceRepository: DeviceRepositor
}
.map(::listOfNotNull)
.distinctUntilChanged()
-
- fun newDeviceCreated() {
- _mutableShowNewDeviceNotification.value = true
- }
-
- fun clearNewDeviceCreatedNotification() {
- _mutableShowNewDeviceNotification.value = false
- }
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/PaymentUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/PaymentUseCase.kt
index 82efd5d722..fbd662f95e 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/PaymentUseCase.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/PaymentUseCase.kt
@@ -36,6 +36,7 @@ class PlayPaymentUseCase(private val paymentRepository: PaymentRepository) : Pay
override val paymentAvailability = _paymentAvailability.asStateFlow()
override val purchaseResult = _purchaseResult.asStateFlow()
+ @Suppress("ensure every public functions method is named 'invoke' with operator modifier")
override suspend fun purchaseProduct(productId: ProductId, activityProvider: () -> Activity) {
paymentRepository
.purchaseProduct(productId, activityProvider)
@@ -48,14 +49,17 @@ class PlayPaymentUseCase(private val paymentRepository: PaymentRepository) : Pay
.collect(_purchaseResult)
}
+ @Suppress("ensure every public functions method is named 'invoke' with operator modifier")
override suspend fun queryPaymentAvailability() {
paymentRepository.queryPaymentAvailability().collect(_paymentAvailability)
}
+ @Suppress("ensure every public functions method is named 'invoke' with operator modifier")
override suspend fun resetPurchaseResult() {
_purchaseResult.emit(null)
}
+ @Suppress("ensure every public functions method is named 'invoke' with operator modifier")
override suspend fun verifyPurchases(onSuccessfulVerification: () -> Unit) {
paymentRepository
.verifyPurchases()
@@ -87,18 +91,22 @@ class EmptyPaymentUseCase : PaymentUseCase {
override val paymentAvailability = MutableStateFlow(PaymentAvailability.ProductsUnavailable)
override val purchaseResult = MutableStateFlow<PurchaseResult?>(null)
+ @Suppress("ensure every public functions method is named 'invoke' with operator modifier")
override suspend fun purchaseProduct(productId: ProductId, activityProvider: () -> Activity) {
// No op
}
+ @Suppress("ensure every public functions method is named 'invoke' with operator modifier")
override suspend fun queryPaymentAvailability() {
// No op
}
+ @Suppress("ensure every public functions method is named 'invoke' with operator modifier")
override suspend fun resetPurchaseResult() {
// No op
}
+ @Suppress("ensure every public functions method is named 'invoke' with operator modifier")
override suspend fun verifyPurchases(onSuccessfulVerification: () -> Unit) {
// No op
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SelectedLocationTitleUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SelectedLocationTitleUseCase.kt
index a37e33492d..a45da5ae76 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SelectedLocationTitleUseCase.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SelectedLocationTitleUseCase.kt
@@ -16,7 +16,7 @@ class SelectedLocationTitleUseCase(
private val customListsRepository: CustomListsRepository,
private val relayListRepository: RelayListRepository,
) {
- fun selectedLocationTitle() =
+ operator fun invoke() =
combine(
customListsRepository.customLists,
relayListRepository.relayList,
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SystemVpnSettingsUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SystemVpnSettingsAvailableUseCase.kt
index a2ca2cdc64..11ef538ace 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SystemVpnSettingsUseCase.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SystemVpnSettingsAvailableUseCase.kt
@@ -3,7 +3,7 @@ package net.mullvad.mullvadvpn.usecase
import android.content.Context
import android.content.Intent
-class SystemVpnSettingsUseCase(val context: Context) {
- fun systemVpnSettingsAvailable(): Boolean =
+class SystemVpnSettingsAvailableUseCase(val context: Context) {
+ operator fun invoke(): Boolean =
Intent("android.net.vpn.SETTINGS").resolveActivity(context.packageManager) != null
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/TunnelStateNotificationUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/TunnelStateNotificationUseCase.kt
index ce0878c517..888f9f67bf 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/TunnelStateNotificationUseCase.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/TunnelStateNotificationUseCase.kt
@@ -9,7 +9,7 @@ import net.mullvad.mullvadvpn.lib.shared.ConnectionProxy
import net.mullvad.mullvadvpn.repository.InAppNotification
class TunnelStateNotificationUseCase(private val connectionProxy: ConnectionProxy) {
- fun notifications(): Flow<List<InAppNotification>> =
+ operator fun invoke(): Flow<List<InAppNotification>> =
connectionProxy.tunnelState
.distinctUntilChanged()
.map(::tunnelStateNotification)
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/VersionNotificationUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/VersionNotificationUseCase.kt
index b7dc50a241..43f1fdac77 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/VersionNotificationUseCase.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/VersionNotificationUseCase.kt
@@ -11,7 +11,7 @@ class VersionNotificationUseCase(
private val isVersionInfoNotificationEnabled: Boolean,
) {
- fun notifications() =
+ operator fun invoke() =
appVersionInfoRepository
.versionInfo()
.map { versionInfo ->
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt
index 180381f771..354316793c 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt
@@ -22,32 +22,32 @@ class CustomListActionUseCase(
private val customListsRepository: CustomListsRepository,
private val relayListRepository: RelayListRepository
) {
- suspend fun performAction(
+ suspend operator fun invoke(
action: CustomListAction
): Either<CustomListActionError, CustomListSuccess> {
return when (action) {
is CustomListAction.Create -> {
- performAction(action)
+ invoke(action)
}
is CustomListAction.Rename -> {
- performAction(action)
+ invoke(action)
}
is CustomListAction.Delete -> {
- performAction(action)
+ invoke(action)
}
is CustomListAction.UpdateLocations -> {
- performAction(action)
+ invoke(action)
}
}
}
- suspend fun performAction(action: CustomListAction.Rename): Either<RenameError, Renamed> =
+ suspend operator fun invoke(action: CustomListAction.Rename): Either<RenameError, Renamed> =
customListsRepository
.updateCustomListName(action.id, action.newName)
.map { Renamed(undo = action.not()) }
.mapLeft(::RenameError)
- suspend fun performAction(
+ suspend operator fun invoke(
action: CustomListAction.Create
): Either<CreateWithLocationsError, Created> = either {
val customListId =
@@ -79,7 +79,7 @@ class CustomListActionUseCase(
)
}
- suspend fun performAction(
+ suspend operator fun invoke(
action: CustomListAction.Delete
): Either<DeleteWithUndoError, Deleted> = either {
val customList =
@@ -94,7 +94,7 @@ class CustomListActionUseCase(
Deleted(undo = action.not(locations = customList.locations, name = customList.name))
}
- suspend fun performAction(
+ suspend operator fun invoke(
action: CustomListAction.UpdateLocations
): Either<UpdateLocationsError, LocationsChanged> = either {
val customList =
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListRelayItemsUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListRelayItemsUseCase.kt
index d28bfe1d55..3390b8f9a1 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListRelayItemsUseCase.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListRelayItemsUseCase.kt
@@ -14,9 +14,7 @@ class CustomListRelayItemsUseCase(
private val customListsRepository: CustomListsRepository,
private val relayListRepository: RelayListRepository
) {
- fun getRelayItemLocationsForCustomList(
- customListId: CustomListId
- ): Flow<List<RelayItem.Location>> =
+ operator fun invoke(customListId: CustomListId): Flow<List<RelayItem.Location>> =
combine(
customListsRepository.customLists.mapNotNull { it?.getById(customListId) },
relayListRepository.relayList
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListsRelayItemUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListsRelayItemUseCase.kt
index 015aa8ab4f..93eb914bd0 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListsRelayItemUseCase.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListsRelayItemUseCase.kt
@@ -10,7 +10,7 @@ class CustomListsRelayItemUseCase(
private val relayListRepository: RelayListRepository,
) {
- fun relayItemCustomLists() =
+ operator fun invoke() =
combine(customListsRepository.customLists, relayListRepository.relayList) {
customLists,
relayList ->
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt
index a27ed9adbd..b41a175dad 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt
@@ -25,8 +25,8 @@ import net.mullvad.mullvadvpn.lib.shared.ConnectionProxy
import net.mullvad.mullvadvpn.lib.shared.DeviceRepository
import net.mullvad.mullvadvpn.lib.shared.VpnPermissionRepository
import net.mullvad.mullvadvpn.repository.InAppNotificationController
+import net.mullvad.mullvadvpn.repository.NewDeviceRepository
import net.mullvad.mullvadvpn.usecase.LastKnownLocationUseCase
-import net.mullvad.mullvadvpn.usecase.NewDeviceNotificationUseCase
import net.mullvad.mullvadvpn.usecase.OutOfTimeUseCase
import net.mullvad.mullvadvpn.usecase.PaymentUseCase
import net.mullvad.mullvadvpn.usecase.SelectedLocationTitleUseCase
@@ -40,7 +40,7 @@ class ConnectViewModel(
private val accountRepository: AccountRepository,
private val deviceRepository: DeviceRepository,
inAppNotificationController: InAppNotificationController,
- private val newDeviceNotificationUseCase: NewDeviceNotificationUseCase,
+ private val newDeviceRepository: NewDeviceRepository,
selectedLocationTitleUseCase: SelectedLocationTitleUseCase,
private val outOfTimeUseCase: OutOfTimeUseCase,
private val paymentUseCase: PaymentUseCase,
@@ -57,7 +57,7 @@ class ConnectViewModel(
@OptIn(FlowPreview::class)
val uiState: StateFlow<ConnectUiState> =
combine(
- selectedLocationTitleUseCase.selectedLocationTitle(),
+ selectedLocationTitleUseCase(),
inAppNotificationController.notifications,
connectionProxy.tunnelState,
lastKnownLocationUseCase.lastKnownDisconnectedLocation,
@@ -167,7 +167,7 @@ class ConnectViewModel(
}
fun dismissNewDeviceNotification() {
- newDeviceNotificationUseCase.clearNewDeviceCreatedNotification()
+ newDeviceRepository.clearNewDeviceCreatedNotification()
}
private fun outOfTimeEffect() =
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CreateCustomListDialogViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CreateCustomListDialogViewModel.kt
index 043f989598..ef45302975 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CreateCustomListDialogViewModel.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CreateCustomListDialogViewModel.kt
@@ -37,8 +37,7 @@ class CreateCustomListDialogViewModel(
fun createCustomList(name: String) {
viewModelScope.launch {
- customListActionUseCase
- .performAction(
+ customListActionUseCase(
CustomListAction.Create(
CustomListName.fromString(name),
listOfNotNull(locationCode)
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt
index 581c11c397..f25384c120 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt
@@ -79,8 +79,7 @@ class CustomListLocationsViewModel(
fun save() {
viewModelScope.launch {
_selectedLocations.value?.let { selectedLocations ->
- customListActionUseCase
- .performAction(
+ customListActionUseCase(
CustomListAction.UpdateLocations(
customListId,
selectedLocations.calculateLocationsToSave().map { it.id }
@@ -191,11 +190,7 @@ class CustomListLocationsViewModel(
private suspend fun fetchInitialSelectedLocations() {
val selectedLocations =
- customListRelayItemsUseCase
- .getRelayItemLocationsForCustomList(customListId)
- .first()
- .withDescendants()
- .toSet()
+ customListRelayItemsUseCase(customListId).first().withDescendants().toSet()
_initialLocations.value = selectedLocations
_selectedLocations.value = selectedLocations
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListsViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListsViewModel.kt
index 3689ad7fc8..03d3548ebc 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListsViewModel.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListsViewModel.kt
@@ -28,6 +28,6 @@ class CustomListsViewModel(
)
fun undoDeleteCustomList(action: CustomListAction.Create) {
- viewModelScope.launch { customListActionUseCase.performAction(action) }
+ viewModelScope.launch { customListActionUseCase(action) }
}
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeleteCustomListConfirmationViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeleteCustomListConfirmationViewModel.kt
index 79c2a133c2..8bea330f83 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeleteCustomListConfirmationViewModel.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeleteCustomListConfirmationViewModel.kt
@@ -37,8 +37,7 @@ class DeleteCustomListConfirmationViewModel(
fun deleteCustomList() {
viewModelScope.launch {
_error.emit(null)
- customListActionUseCase
- .performAction(CustomListAction.Delete(customListId))
+ customListActionUseCase(CustomListAction.Delete(customListId))
.fold(
{ _error.tryEmit(it) },
{
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListNameDialogViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListNameDialogViewModel.kt
index 7c45bed0d7..2536f8edd7 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListNameDialogViewModel.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListNameDialogViewModel.kt
@@ -41,8 +41,7 @@ class EditCustomListNameDialogViewModel(
fun updateCustomListName(name: String) {
viewModelScope.launch {
- customListActionUseCase
- .performAction(
+ customListActionUseCase(
CustomListAction.Rename(
id = customListId,
name = initialName,
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/FilterViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/FilterViewModel.kt
index 6e139f4d7f..728142b3ff 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/FilterViewModel.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/FilterViewModel.kt
@@ -35,7 +35,7 @@ class FilterViewModel(
viewModelScope.launch {
selectedProviders.value =
combine(
- availableProvidersUseCase.availableProviders(),
+ availableProvidersUseCase(),
relayListFilterRepository.selectedProviders,
) { allProviders, selectedConstraintProviders ->
selectedConstraintProviders.toSelectedProviders(allProviders)
@@ -50,7 +50,7 @@ class FilterViewModel(
val uiState: StateFlow<RelayFilterState> =
combine(
selectedOwnership,
- availableProvidersUseCase.availableProviders(),
+ availableProvidersUseCase(),
selectedProviders,
) { selectedOwnership, allProviders, selectedProviders ->
RelayFilterState(
@@ -86,7 +86,7 @@ class FilterViewModel(
viewModelScope.launch {
selectedProviders.value =
if (isChecked) {
- availableProvidersUseCase.availableProviders().first()
+ availableProvidersUseCase().first()
} else {
emptyList()
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModel.kt
index fc2f5e86f9..e35baa571e 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModel.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModel.kt
@@ -27,8 +27,8 @@ import net.mullvad.mullvadvpn.compose.state.LoginUiState
import net.mullvad.mullvadvpn.lib.model.AccountNumber
import net.mullvad.mullvadvpn.lib.model.LoginAccountError
import net.mullvad.mullvadvpn.lib.shared.AccountRepository
-import net.mullvad.mullvadvpn.usecase.ConnectivityUseCase
-import net.mullvad.mullvadvpn.usecase.NewDeviceNotificationUseCase
+import net.mullvad.mullvadvpn.repository.NewDeviceRepository
+import net.mullvad.mullvadvpn.usecase.InternetAvailableUseCase
import net.mullvad.mullvadvpn.util.getOrDefault
private const val MINIMUM_LOADING_SPINNER_TIME_MILLIS = 500L
@@ -45,8 +45,8 @@ sealed interface LoginUiSideEffect {
class LoginViewModel(
private val accountRepository: AccountRepository,
- private val newDeviceNotificationUseCase: NewDeviceNotificationUseCase,
- private val connectivityUseCase: ConnectivityUseCase,
+ private val newDeviceRepository: NewDeviceRepository,
+ private val internetAvailableUseCase: InternetAvailableUseCase,
private val dispatcher: CoroutineDispatcher = Dispatchers.IO
) : ViewModel() {
private val _loginState = MutableStateFlow(LoginUiState.INITIAL.loginState)
@@ -123,7 +123,7 @@ class LoginViewModel(
}
private suspend fun onSuccessfulLogin() {
- newDeviceNotificationUseCase.newDeviceCreated()
+ newDeviceRepository.newDeviceCreated()
viewModelScope.launch(dispatcher) {
// Find if user is out of time
@@ -161,7 +161,7 @@ class LoginViewModel(
}
private fun isInternetAvailable(): Boolean {
- return connectivityUseCase.isInternetAvailable()
+ return internetAvailableUseCase()
}
companion object {
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt
index 2ab757bd78..2509fdc876 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt
@@ -42,12 +42,12 @@ class SelectLocationViewModel(
@Suppress("DestructuringDeclarationWithTooManyEntries")
val uiState =
combine(
- filteredRelayListUseCase.filteredRelayList(),
- customListsRelayItemUseCase.relayItemCustomLists(),
+ filteredRelayListUseCase(),
+ customListsRelayItemUseCase(),
relayListRepository.selectedLocation,
_searchTerm,
relayListFilterRepository.selectedOwnership,
- availableProvidersUseCase.availableProviders(),
+ availableProvidersUseCase(),
relayListFilterRepository.selectedProviders,
) {
relayCountries,
@@ -135,8 +135,7 @@ class SelectLocationViewModel(
viewModelScope.launch {
val newLocations =
(customList.locations + item).filter { it !in item.descendants() }.map { it.id }
- customListActionUseCase
- .performAction(CustomListAction.UpdateLocations(customList.id, newLocations))
+ customListActionUseCase(CustomListAction.UpdateLocations(customList.id, newLocations))
.fold(
{ _uiSideEffect.send(SelectLocationSideEffect.GenericError) },
{ _uiSideEffect.send(SelectLocationSideEffect.LocationAddedToCustomList(it)) },
@@ -145,14 +144,13 @@ class SelectLocationViewModel(
}
fun performAction(action: CustomListAction) {
- viewModelScope.launch { customListActionUseCase.performAction(action) }
+ viewModelScope.launch { customListActionUseCase(action) }
}
fun removeLocationFromList(item: RelayItem.Location, customList: RelayItem.CustomList) {
viewModelScope.launch {
val newLocations = (customList.locations - item).map { it.id }
- customListActionUseCase
- .performAction(CustomListAction.UpdateLocations(customList.id, newLocations))
+ customListActionUseCase(CustomListAction.UpdateLocations(customList.id, newLocations))
.fold(
{ _uiSideEffect.send(SelectLocationSideEffect.GenericError) },
{
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt
index a0a38ef6f8..3c24cba6d6 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt
@@ -29,7 +29,7 @@ import net.mullvad.mullvadvpn.lib.model.Settings
import net.mullvad.mullvadvpn.lib.model.WireguardConstraints
import net.mullvad.mullvadvpn.repository.RelayListRepository
import net.mullvad.mullvadvpn.repository.SettingsRepository
-import net.mullvad.mullvadvpn.usecase.SystemVpnSettingsUseCase
+import net.mullvad.mullvadvpn.usecase.SystemVpnSettingsAvailableUseCase
import net.mullvad.mullvadvpn.util.isCustom
sealed interface VpnSettingsSideEffect {
@@ -45,7 +45,7 @@ sealed interface VpnSettingsSideEffect {
class VpnSettingsViewModel(
private val repository: SettingsRepository,
private val relayListRepository: RelayListRepository,
- private val systemVpnSettingsUseCase: SystemVpnSettingsUseCase,
+ private val systemVpnSettingsUseCase: SystemVpnSettingsAvailableUseCase,
private val dispatcher: CoroutineDispatcher = Dispatchers.IO
) : ViewModel() {
@@ -76,8 +76,7 @@ class VpnSettingsViewModel(
selectedWireguardPort = settings?.getWireguardPort() ?: Constraint.Any,
customWireguardPort = customWgPort,
availablePortRanges = portRanges,
- systemVpnSettingsAvailable =
- systemVpnSettingsUseCase.systemVpnSettingsAvailable()
+ systemVpnSettingsAvailable = systemVpnSettingsUseCase()
)
}
.stateIn(
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryNotificationUseCaseTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryNotificationUseCaseTest.kt
index 11d574b663..897ab65e15 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryNotificationUseCaseTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryNotificationUseCaseTest.kt
@@ -43,15 +43,13 @@ class AccountExpiryNotificationUseCaseTest {
@Test
fun `initial state should be empty`() = runTest {
// Arrange, Act, Assert
- accountExpiryNotificationUseCase.notifications().test {
- assertTrue { awaitItem().isEmpty() }
- }
+ accountExpiryNotificationUseCase().test { assertTrue { awaitItem().isEmpty() } }
}
@Test
fun `account that expires within 3 days should emit a notification`() = runTest {
// Arrange, Act, Assert
- accountExpiryNotificationUseCase.notifications().test {
+ accountExpiryNotificationUseCase().test {
assertTrue { awaitItem().isEmpty() }
val closeToExpiry = AccountData(mockk(relaxed = true), DateTime.now().plusDays(2))
accountExpiry.value = closeToExpiry
@@ -66,7 +64,7 @@ class AccountExpiryNotificationUseCaseTest {
@Test
fun `account that expires in 4 days should not emit a notification`() = runTest {
// Arrange, Act, Assert
- accountExpiryNotificationUseCase.notifications().test {
+ accountExpiryNotificationUseCase().test {
assertTrue { awaitItem().isEmpty() }
accountExpiry.value = AccountData(mockk(relaxed = true), DateTime.now().plusDays(4))
expectNoEvents()
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt
index bb19d42d13..d98292ccd9 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt
@@ -77,7 +77,7 @@ class CustomListActionUseCaseTest {
)
// Act
- val result = customListActionUseCase.performAction(action)
+ val result = customListActionUseCase(action)
// Assert
assertEquals(expectedResult, result)
@@ -94,7 +94,7 @@ class CustomListActionUseCaseTest {
CustomListAlreadyExists.left()
// Act
- val result = customListActionUseCase.performAction(action)
+ val result = customListActionUseCase(action)
// Assert
assertEquals(expectedError, result)
@@ -113,7 +113,7 @@ class CustomListActionUseCaseTest {
} returns Unit.right()
// Act
- val result = customListActionUseCase.performAction(action)
+ val result = customListActionUseCase(action)
// Assert
assertEquals(expectedResult, result)
@@ -133,7 +133,7 @@ class CustomListActionUseCaseTest {
val expectedError = RenameError(NameAlreadyExists(newName.value)).left()
// Act
- val result = customListActionUseCase.performAction(action)
+ val result = customListActionUseCase(action)
// Assert
assertEquals(expectedError, result)
@@ -158,7 +158,7 @@ class CustomListActionUseCaseTest {
mockCustomList.right()
// Act
- val result = customListActionUseCase.performAction(action)
+ val result = customListActionUseCase(action)
// Assert
assertEquals(expectedResult, result)
@@ -184,7 +184,7 @@ class CustomListActionUseCaseTest {
} returns Unit.right()
// Act
- val result = customListActionUseCase.performAction(action)
+ val result = customListActionUseCase(action)
// Assert
assertEquals(expectedResult, result)
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceUseNotificationCaseTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceUseNotificationCaseTest.kt
index 95df8dc359..ec487815e1 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceUseNotificationCaseTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceUseNotificationCaseTest.kt
@@ -58,13 +58,13 @@ class NewDeviceUseNotificationCaseTest {
@Test
fun `initial state should be empty`() = runTest {
// Arrange, Act, Assert
- newDeviceNotificationUseCase.notifications().test { assertTrue { awaitItem().isEmpty() } }
+ newDeviceNotificationUseCase().test { assertTrue { awaitItem().isEmpty() } }
}
@Test
fun `when newDeviceCreated is called notifications should emit NewDevice notification containing device name`() =
runTest {
- newDeviceNotificationUseCase.notifications().test {
+ newDeviceNotificationUseCase().test {
// Arrange, Act
awaitItem()
newDeviceNotificationUseCase.newDeviceCreated()
@@ -76,7 +76,7 @@ class NewDeviceUseNotificationCaseTest {
@Test
fun `clearNewDeviceCreatedNotification should clear notifications`() = runTest {
- newDeviceNotificationUseCase.notifications().test {
+ newDeviceNotificationUseCase().test {
// Arrange, Act
awaitItem()
newDeviceNotificationUseCase.newDeviceCreated()
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/TunnelStateNotificationUseCaseTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/TunnelStateNotificationUseCaseTest.kt
index a2e8db36fd..20a6a1bef0 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/TunnelStateNotificationUseCaseTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/TunnelStateNotificationUseCaseTest.kt
@@ -46,12 +46,12 @@ class TunnelStateNotificationUseCaseTest {
@Test
fun `initial state should be empty`() = runTest {
// Arrange, Act, Assert
- tunnelStateNotificationUseCase.notifications().test { assertTrue { awaitItem().isEmpty() } }
+ tunnelStateNotificationUseCase().test { assertTrue { awaitItem().isEmpty() } }
}
@Test
fun `when TunnelState is error use case should emit TunnelStateError notification`() = runTest {
- tunnelStateNotificationUseCase.notifications().test {
+ tunnelStateNotificationUseCase().test {
// Arrange, Act
assertEquals(emptyList(), awaitItem())
val errorState: ErrorState = mockk()
@@ -65,7 +65,7 @@ class TunnelStateNotificationUseCaseTest {
@Test
fun `when TunnelState is Disconnecting with blocking use case should emit TunnelStateBlocked notification`() =
runTest {
- tunnelStateNotificationUseCase.notifications().test {
+ tunnelStateNotificationUseCase().test {
// Arrange, Act
assertEquals(emptyList(), awaitItem())
tunnelState.emit(TunnelState.Disconnecting(ActionAfterDisconnect.Block))
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/VersionNotificationUseCaseTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/VersionNotificationUseCaseTest.kt
index 1630ed757f..9d40f9715c 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/VersionNotificationUseCaseTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/VersionNotificationUseCaseTest.kt
@@ -49,13 +49,13 @@ class VersionNotificationUseCaseTest {
@Test
fun `initial state should be empty`() = runTest {
// Arrange, Act, Assert
- versionNotificationUseCase.notifications().test { assertTrue { awaitItem().isEmpty() } }
+ versionNotificationUseCase().test { assertTrue { awaitItem().isEmpty() } }
}
@Test
fun `when a new version is available use case should emit UpdateAvailable with new version`() =
runTest {
- versionNotificationUseCase.notifications().test {
+ versionNotificationUseCase().test {
// Arrange, Act
val upgradeVersionInfo =
VersionInfo(
@@ -77,7 +77,7 @@ class VersionNotificationUseCaseTest {
@Test
fun `when an unsupported version use case should emit UnsupportedVersion notification`() =
runTest {
- versionNotificationUseCase.notifications().test {
+ versionNotificationUseCase().test {
// Arrange, Act
val upgradeVersionInfo =
VersionInfo(
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 1717ae6cc4..f95720de14 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
@@ -27,7 +27,7 @@ import net.mullvad.mullvadvpn.lib.model.AccountData
import net.mullvad.mullvadvpn.lib.model.AccountNumber
import net.mullvad.mullvadvpn.lib.model.LoginAccountError
import net.mullvad.mullvadvpn.lib.shared.AccountRepository
-import net.mullvad.mullvadvpn.usecase.ConnectivityUseCase
+import net.mullvad.mullvadvpn.usecase.InternetAvailableUseCase
import net.mullvad.mullvadvpn.usecase.NewDeviceNotificationUseCase
import org.joda.time.DateTime
import org.junit.jupiter.api.Assertions.assertEquals
@@ -38,7 +38,7 @@ import org.junit.jupiter.api.extension.ExtendWith
@ExtendWith(TestCoroutineRule::class)
class LoginViewModelTest {
- @MockK private lateinit var connectivityUseCase: ConnectivityUseCase
+ @MockK private lateinit var connectivityUseCase: InternetAvailableUseCase
@MockK private lateinit var mockedAccountRepository: AccountRepository
@MockK private lateinit var mockedNewDeviceNotificationUseCase: NewDeviceNotificationUseCase
@@ -48,7 +48,7 @@ class LoginViewModelTest {
fun setup() {
Dispatchers.setMain(UnconfinedTestDispatcher())
MockKAnnotations.init(this, relaxUnitFun = true)
- every { connectivityUseCase.isInternetAvailable() } returns true
+ every { connectivityUseCase() } returns true
every { mockedNewDeviceNotificationUseCase.newDeviceCreated() } returns Unit
coEvery { mockedAccountRepository.fetchAccountHistory() } returns null
@@ -56,7 +56,7 @@ class LoginViewModelTest {
LoginViewModel(
accountRepository = mockedAccountRepository,
newDeviceNotificationUseCase = mockedNewDeviceNotificationUseCase,
- connectivityUseCase = connectivityUseCase,
+ internetAvailableUseCase = connectivityUseCase,
UnconfinedTestDispatcher()
)
}
@@ -65,7 +65,7 @@ class LoginViewModelTest {
fun `given no internet when logging in then show no internet error`() = runTest {
turbineScope {
// Arrange
- every { connectivityUseCase.isInternetAvailable() } returns false
+ every { connectivityUseCase() } returns false
val uiStates = loginViewModel.uiState.testIn(backgroundScope)
// Act
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelTest.kt
index c917bf18d2..ac84d86ea8 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelTest.kt
@@ -28,7 +28,7 @@ import net.mullvad.mullvadvpn.lib.model.WireguardConstraints
import net.mullvad.mullvadvpn.lib.model.WireguardTunnelOptions
import net.mullvad.mullvadvpn.repository.RelayListRepository
import net.mullvad.mullvadvpn.repository.SettingsRepository
-import net.mullvad.mullvadvpn.usecase.SystemVpnSettingsUseCase
+import net.mullvad.mullvadvpn.usecase.SystemVpnSettingsAvailableUseCase
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@@ -38,7 +38,8 @@ import org.junit.jupiter.api.extension.ExtendWith
class VpnSettingsViewModelTest {
private val mockSettingsRepository: SettingsRepository = mockk()
- private val mockSystemVpnSettingsUseCase: SystemVpnSettingsUseCase = mockk(relaxed = true)
+ private val mockSystemVpnSettingsUseCase: SystemVpnSettingsAvailableUseCase =
+ mockk(relaxed = true)
private val mockRelayListRepository: RelayListRepository = mockk()
private val mockSettingsUpdate = MutableStateFlow<Settings?>(null)