Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Jun 19, 2024
1 parent ff265b3 commit 8de5b38
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package net.mullvad.mullvadvpn.viewmodel

import app.cash.turbine.test
import arrow.core.Either
import arrow.core.left
import arrow.core.right
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
import java.time.Duration
import kotlin.test.assertIs
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -20,6 +22,7 @@ import net.mullvad.mullvadvpn.lib.model.ApiAccessMethodSetting
import net.mullvad.mullvadvpn.lib.model.TestApiAccessMethodError
import net.mullvad.mullvadvpn.lib.model.UnknownApiAccessMethodError
import net.mullvad.mullvadvpn.repository.ApiAccessRepository
import net.mullvad.mullvadvpn.util.delayAtLeast
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand All @@ -38,6 +41,7 @@ class ApiAccessMethodDetailsViewModelTest {

@BeforeEach
fun setUp() {
mockkStatic(DELAY_UTIL)
every { mockApiAccessRepository.apiAccessMethodSettingById(apiAccessMethodId) } returns
accessMethodFlow
every { mockApiAccessRepository.enabledApiAccessMethods() } returns enabledMethodsFlow
Expand All @@ -58,6 +62,8 @@ class ApiAccessMethodDetailsViewModelTest {
Unit.right()
coEvery { mockApiAccessRepository.setCurrentApiAccessMethod(any()) } returns
Unit.right()
coEvery { delayAtLeast<Either<TestApiAccessMethodError, Unit>>(any(), any()) } returns
Unit.right()

// Act
apiAccessMethodDetailsViewModel.setCurrentMethod()
Expand Down Expand Up @@ -177,4 +183,8 @@ class ApiAccessMethodDetailsViewModelTest {
)
}
}

companion object {
private const val DELAY_UTIL = "net.mullvad.mullvadvpn.util.DelayKt"
}
}

0 comments on commit 8de5b38

Please sign in to comment.