diff options
| author | David Göransson <david.goransson@mullvad.net> | 2024-06-14 15:00:23 +0200 |
|---|---|---|
| committer | Albin <albin@mullvad.net> | 2024-06-19 09:28:48 +0200 |
| commit | d09b5053b7b6cb2a65d047d0b90d195192f6ecf3 (patch) | |
| tree | c29e89ae8f3e0c2d90915af6829ef7199e8b6a7e /android/app/src/test | |
| parent | 9be52437a1a9065ca7fa2f831f0833cf959e2e36 (diff) | |
| download | mullvadvpn-d09b5053b7b6cb2a65d047d0b90d195192f6ecf3.tar.xz mullvadvpn-d09b5053b7b6cb2a65d047d0b90d195192f6ecf3.zip | |
Align UseCases
Diffstat (limited to 'android/app/src/test')
7 files changed, 26 insertions, 27 deletions
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) |
