Benoit Marty 2022-03-22 16:33:31 +01:00
parent f791ddb7bb
commit 86829008c3
8 changed files with 120 additions and 132 deletions

View file

@ -17,7 +17,7 @@
package org.matrix.android.sdk.internal.session.space
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.test.runTest
import okhttp3.ResponseBody.Companion.toResponseBody
import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test
@ -35,7 +35,7 @@ internal class DefaultResolveSpaceInfoTaskTest {
private val resolveSpaceInfoTask = DefaultResolveSpaceInfoTask(spaceApi.instance, globalErrorReceiver)
@Test
fun `given stable endpoint works, when execute, then return stable api data`() = runBlockingTest {
fun `given stable endpoint works, when execute, then return stable api data`() = runTest {
spaceApi.givenStableEndpointReturns(response)
val result = resolveSpaceInfoTask.execute(spaceApi.params)
@ -44,7 +44,7 @@ internal class DefaultResolveSpaceInfoTaskTest {
}
@Test
fun `given stable endpoint fails, when execute, then fallback to unstable endpoint`() = runBlockingTest {
fun `given stable endpoint fails, when execute, then fallback to unstable endpoint`() = runTest {
spaceApi.givenStableEndpointThrows(httpException)
spaceApi.givenUnstableEndpointReturns(response)

View file

@ -30,7 +30,7 @@ import im.vector.app.test.fixtures.aVectorAnalyticsScreen
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
@ -60,35 +60,35 @@ class DefaultVectorAnalyticsTest {
}
@Test
fun `when setting user consent then updates analytics store`() = runBlockingTest {
fun `when setting user consent then updates analytics store`() = runTest {
defaultVectorAnalytics.setUserConsent(true)
fakeAnalyticsStore.verifyConsentUpdated(updatedValue = true)
}
@Test
fun `when consenting to analytics then updates posthog opt out to false`() = runBlockingTest {
fun `when consenting to analytics then updates posthog opt out to false`() = runTest {
fakeAnalyticsStore.givenUserContent(consent = true)
fakePostHog.verifyOptOutStatus(optedOut = false)
}
@Test
fun `when revoking consent to analytics then updates posthog opt out to true`() = runBlockingTest {
fun `when revoking consent to analytics then updates posthog opt out to true`() = runTest {
fakeAnalyticsStore.givenUserContent(consent = false)
fakePostHog.verifyOptOutStatus(optedOut = true)
}
@Test
fun `when setting the analytics id then updates analytics store`() = runBlockingTest {
fun `when setting the analytics id then updates analytics store`() = runTest {
defaultVectorAnalytics.setAnalyticsId(AN_ANALYTICS_ID)
fakeAnalyticsStore.verifyAnalyticsIdUpdated(updatedValue = AN_ANALYTICS_ID)
}
@Test
fun `given lateinit user properties when valid analytics id updates then identify with lateinit properties`() = runBlockingTest {
fun `given lateinit user properties when valid analytics id updates then identify with lateinit properties`() = runTest {
fakeLateInitUserPropertiesFactory.givenCreatesProperties(A_LATE_INIT_USER_PROPERTIES)
fakeAnalyticsStore.givenAnalyticsId(AN_ANALYTICS_ID)
@ -97,7 +97,7 @@ class DefaultVectorAnalyticsTest {
}
@Test
fun `when signing out then resets posthog`() = runBlockingTest {
fun `when signing out then resets posthog`() = runTest {
fakeAnalyticsStore.allowSettingAnalyticsIdToCallBackingFlow()
defaultVectorAnalytics.onSignOut()
@ -106,7 +106,7 @@ class DefaultVectorAnalyticsTest {
}
@Test
fun `given user consent when tracking screen events then submits to posthog`() = runBlockingTest {
fun `given user consent when tracking screen events then submits to posthog`() = runTest {
fakeAnalyticsStore.givenUserContent(consent = true)
defaultVectorAnalytics.screen(A_SCREEN_EVENT)
@ -115,7 +115,7 @@ class DefaultVectorAnalyticsTest {
}
@Test
fun `given user has not consented when tracking screen events then does not track`() = runBlockingTest {
fun `given user has not consented when tracking screen events then does not track`() = runTest {
fakeAnalyticsStore.givenUserContent(consent = false)
defaultVectorAnalytics.screen(A_SCREEN_EVENT)
@ -124,7 +124,7 @@ class DefaultVectorAnalyticsTest {
}
@Test
fun `given user consent when tracking events then submits to posthog`() = runBlockingTest {
fun `given user consent when tracking events then submits to posthog`() = runTest {
fakeAnalyticsStore.givenUserContent(consent = true)
defaultVectorAnalytics.capture(AN_EVENT)
@ -133,7 +133,7 @@ class DefaultVectorAnalyticsTest {
}
@Test
fun `given user has not consented when tracking events then does not track`() = runBlockingTest {
fun `given user has not consented when tracking events then does not track`() = runTest {
fakeAnalyticsStore.givenUserContent(consent = false)
defaultVectorAnalytics.capture(AN_EVENT)

View file

@ -23,7 +23,7 @@ import im.vector.app.test.fakes.FakeContext
import im.vector.app.test.fakes.FakeSession
import im.vector.app.test.fakes.FakeVectorStore
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.test.runTest
import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test
@ -43,14 +43,14 @@ class LateInitUserPropertiesFactoryTest {
)
@Test
fun `given no active session when creating properties then returns null`() = runBlockingTest {
fun `given no active session when creating properties then returns null`() = runTest {
val result = lateInitUserProperties.createUserProperties()
result shouldBeEqualTo null
}
@Test
fun `given no use case set on an active session when creating properties then returns null`() = runBlockingTest {
fun `given no use case set on an active session when creating properties then returns null`() = runTest {
fakeVectorStore.givenUseCase(null)
fakeSession.givenVectorStore(fakeVectorStore.instance)
fakeActiveSessionDataSource.setActiveSession(fakeSession)
@ -61,7 +61,7 @@ class LateInitUserPropertiesFactoryTest {
}
@Test
fun `given use case set on an active session when creating properties then includes the use case`() = runBlockingTest {
fun `given use case set on an active session when creating properties then includes the use case`() = runTest {
fakeVectorStore.givenUseCase(FtueUseCase.TEAMS)
fakeActiveSessionDataSource.setActiveSession(fakeSession)
val result = lateInitUserProperties.createUserProperties()

View file

@ -21,7 +21,7 @@ import com.airbnb.mvrx.test.MvRxTestRule
import im.vector.app.test.fakes.FakeSession
import im.vector.app.test.fakes.FakeStringProvider
import im.vector.app.test.test
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
import org.matrix.android.sdk.api.session.securestorage.IntegrityResult
@ -47,117 +47,105 @@ class SharedSecureStorageViewModelTest {
val args = SharedSecureStorageActivity.Args(keyId = null, emptyList(), "alias")
@Test
fun `given a key info with passphrase when initialising then step is EnterPassphrase`() {
runBlockingTest {
givenKey(KEY_INFO_WITH_PASSPHRASE)
val viewModel = createViewModel()
viewModel
.test(this)
.assertState(aViewState(
hasPassphrase = true,
step = SharedSecureStorageViewState.Step.EnterPassphrase
))
.finish()
}
fun `given a key info with passphrase when initialising then step is EnterPassphrase`() = runTest {
givenKey(KEY_INFO_WITH_PASSPHRASE)
val viewModel = createViewModel()
viewModel
.test(this)
.assertState(aViewState(
hasPassphrase = true,
step = SharedSecureStorageViewState.Step.EnterPassphrase
))
.finish()
}
@Test
fun `given a key info without passphrase when initialising then step is EnterKey`() {
runBlockingTest {
givenKey(KEY_INFO_WITHOUT_PASSPHRASE)
fun `given a key info without passphrase when initialising then step is EnterKey`() = runTest {
givenKey(KEY_INFO_WITHOUT_PASSPHRASE)
val viewModel = createViewModel()
val viewModel = createViewModel()
viewModel
.test(this)
.assertState(aViewState(
hasPassphrase = false,
step = SharedSecureStorageViewState.Step.EnterKey
))
.finish()
}
viewModel
.test(this)
.assertState(aViewState(
hasPassphrase = false,
step = SharedSecureStorageViewState.Step.EnterKey
))
.finish()
}
@Test
fun `given on EnterKey step when going back then dismisses`() {
runBlockingTest {
givenKey(KEY_INFO_WITHOUT_PASSPHRASE)
fun `given on EnterKey step when going back then dismisses`() = runTest {
givenKey(KEY_INFO_WITHOUT_PASSPHRASE)
val viewModel = createViewModel()
val test = viewModel.test(this)
viewModel.handle(SharedSecureStorageAction.Back)
test
.assertEvents(SharedSecureStorageViewEvent.Dismiss)
.finish()
}
val viewModel = createViewModel()
val test = viewModel.test(this)
viewModel.handle(SharedSecureStorageAction.Back)
test
.assertEvents(SharedSecureStorageViewEvent.Dismiss)
.finish()
}
@Test
fun `given on passphrase step when using key then step is EnterKey`() {
runBlockingTest {
givenKey(KEY_INFO_WITH_PASSPHRASE)
val viewModel = createViewModel()
val test = viewModel.test(this)
fun `given on passphrase step when using key then step is EnterKey`() = runTest {
givenKey(KEY_INFO_WITH_PASSPHRASE)
val viewModel = createViewModel()
val test = viewModel.test(this)
viewModel.handle(SharedSecureStorageAction.UseKey)
viewModel.handle(SharedSecureStorageAction.UseKey)
test
.assertStates(
aViewState(
hasPassphrase = true,
step = SharedSecureStorageViewState.Step.EnterPassphrase
),
aViewState(
hasPassphrase = true,
step = SharedSecureStorageViewState.Step.EnterKey
)
)
.finish()
}
test
.assertStates(
aViewState(
hasPassphrase = true,
step = SharedSecureStorageViewState.Step.EnterPassphrase
),
aViewState(
hasPassphrase = true,
step = SharedSecureStorageViewState.Step.EnterKey
)
)
.finish()
}
@Test
fun `given a key info with passphrase and on EnterKey step when going back then step is EnterPassphrase`() {
runBlockingTest {
givenKey(KEY_INFO_WITH_PASSPHRASE)
val viewModel = createViewModel()
val test = viewModel.test(this)
fun `given a key info with passphrase and on EnterKey step when going back then step is EnterPassphrase`() = runTest {
givenKey(KEY_INFO_WITH_PASSPHRASE)
val viewModel = createViewModel()
val test = viewModel.test(this)
viewModel.handle(SharedSecureStorageAction.UseKey)
viewModel.handle(SharedSecureStorageAction.Back)
viewModel.handle(SharedSecureStorageAction.UseKey)
viewModel.handle(SharedSecureStorageAction.Back)
test
.assertStates(
aViewState(
hasPassphrase = true,
step = SharedSecureStorageViewState.Step.EnterPassphrase
),
aViewState(
hasPassphrase = true,
step = SharedSecureStorageViewState.Step.EnterKey
),
aViewState(
hasPassphrase = true,
step = SharedSecureStorageViewState.Step.EnterPassphrase
)
)
.finish()
}
test
.assertStates(
aViewState(
hasPassphrase = true,
step = SharedSecureStorageViewState.Step.EnterPassphrase
),
aViewState(
hasPassphrase = true,
step = SharedSecureStorageViewState.Step.EnterKey
),
aViewState(
hasPassphrase = true,
step = SharedSecureStorageViewState.Step.EnterPassphrase
)
)
.finish()
}
@Test
fun `given on passphrase step when going back then dismisses`() {
runBlockingTest {
givenKey(KEY_INFO_WITH_PASSPHRASE)
val viewModel = createViewModel()
val test = viewModel.test(this)
fun `given on passphrase step when going back then dismisses`() = runTest {
givenKey(KEY_INFO_WITH_PASSPHRASE)
val viewModel = createViewModel()
val test = viewModel.test(this)
viewModel.handle(SharedSecureStorageAction.Back)
viewModel.handle(SharedSecureStorageAction.Back)
test
.assertEvents(SharedSecureStorageViewEvent.Dismiss)
.finish()
}
test
.assertEvents(SharedSecureStorageViewEvent.Dismiss)
.finish()
}
private fun createViewModel(): SharedSecureStorageViewModel {

View file

@ -21,7 +21,7 @@ import im.vector.app.features.location.LocationData
import im.vector.app.test.fakes.FakeSession
import io.mockk.MockKAnnotations
import io.mockk.impl.annotations.OverrideMockKs
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -42,7 +42,7 @@ class CompareLocationsUseCaseTest {
}
@Test
fun `given 2 very near locations when calling execute then these locations are considered as equal`() = runBlockingTest {
fun `given 2 very near locations when calling execute then these locations are considered as equal`() = runTest {
// Given
val location1 = LocationData(
latitude = 48.858269,
@ -62,7 +62,7 @@ class CompareLocationsUseCaseTest {
}
@Test
fun `given 2 far away locations when calling execute then these locations are considered as not equal`() = runBlockingTest {
fun `given 2 far away locations when calling execute then these locations are considered as not equal`() = runTest {
// Given
val location1 = LocationData(
latitude = 48.858269,

View file

@ -38,7 +38,7 @@ import io.mockk.runs
import io.mockk.unmockkStatic
import io.mockk.verify
import io.mockk.verifyAll
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Before
import org.junit.Rule
@ -77,7 +77,7 @@ class DownloadMediaUseCaseTest {
}
@Test
fun `given a file when calling execute then save the file in local with success`() = runBlockingTest {
fun `given a file when calling execute then save the file in local with success`() = runTest {
// Given
val uri = mockk<Uri>()
val mimeType = "mimeType"
@ -105,7 +105,7 @@ class DownloadMediaUseCaseTest {
}
@Test
fun `given a file when calling execute then save the file in local with error`() = runBlockingTest {
fun `given a file when calling execute then save the file in local with error`() = runTest {
// Given
val uri = mockk<Uri>()
val mimeType = "mimeType"

View file

@ -40,7 +40,7 @@ import im.vector.app.test.fakes.FakeVectorFeatures
import im.vector.app.test.fakes.FakeVectorOverrides
import im.vector.app.test.fixtures.aHomeServerCapabilities
import im.vector.app.test.test
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -82,7 +82,7 @@ class OnboardingViewModelTest {
}
@Test
fun `when handling PostViewEvent, then emits contents as view event`() = runBlockingTest {
fun `when handling PostViewEvent, then emits contents as view event`() = runTest {
val test = viewModel.test(this)
viewModel.handle(OnboardingAction.PostViewEvent(OnboardingViewEvents.OnTakeMeHome))
@ -93,7 +93,7 @@ class OnboardingViewModelTest {
}
@Test
fun `given supports changing display name, when handling PersonalizeProfile, then emits contents choose display name`() = runBlockingTest {
fun `given supports changing display name, when handling PersonalizeProfile, then emits contents choose display name`() = runTest {
val initialState = initialState.copy(personalizationState = PersonalizationState(supportsChangingDisplayName = true, supportsChangingProfilePicture = false))
viewModel = createViewModel(initialState)
val test = viewModel.test(this)
@ -106,7 +106,7 @@ class OnboardingViewModelTest {
}
@Test
fun `given only supports changing profile picture, when handling PersonalizeProfile, then emits contents choose profile picture`() = runBlockingTest {
fun `given only supports changing profile picture, when handling PersonalizeProfile, then emits contents choose profile picture`() = runTest {
val initialState = initialState.copy(personalizationState = PersonalizationState(supportsChangingDisplayName = false, supportsChangingProfilePicture = true))
viewModel = createViewModel(initialState)
val test = viewModel.test(this)
@ -119,7 +119,7 @@ class OnboardingViewModelTest {
}
@Test
fun `when handling SignUp then sets sign mode to sign up and starts registration`() = runBlockingTest {
fun `when handling SignUp then sets sign mode to sign up and starts registration`() = runTest {
givenRegistrationResultFor(RegisterAction.StartRegistration, ANY_CONTINUING_REGISTRATION_RESULT)
val test = viewModel.test(this)
@ -137,7 +137,7 @@ class OnboardingViewModelTest {
}
@Test
fun `given register action requires more steps, when handling action, then posts next steps`() = runBlockingTest {
fun `given register action requires more steps, when handling action, then posts next steps`() = runTest {
val test = viewModel.test(this)
givenRegistrationResultFor(A_LOADABLE_REGISTER_ACTION, ANY_CONTINUING_REGISTRATION_RESULT)
@ -154,7 +154,7 @@ class OnboardingViewModelTest {
}
@Test
fun `given register action is non loadable, when handling action, then posts next steps without loading`() = runBlockingTest {
fun `given register action is non loadable, when handling action, then posts next steps without loading`() = runTest {
val test = viewModel.test(this)
givenRegistrationResultFor(A_NON_LOADABLE_REGISTER_ACTION, ANY_CONTINUING_REGISTRATION_RESULT)
@ -167,7 +167,7 @@ class OnboardingViewModelTest {
}
@Test
fun `given register action ignores result, when handling action, then does nothing on success`() = runBlockingTest {
fun `given register action ignores result, when handling action, then does nothing on success`() = runTest {
val test = viewModel.test(this)
givenRegistrationResultFor(A_RESULT_IGNORED_REGISTER_ACTION, RegistrationResult.FlowResponse(AN_IGNORED_FLOW_RESULT))
@ -184,7 +184,7 @@ class OnboardingViewModelTest {
}
@Test
fun `when registering account, then updates state and emits account created event`() = runBlockingTest {
fun `when registering account, then updates state and emits account created event`() = runTest {
givenRegistrationResultFor(A_LOADABLE_REGISTER_ACTION, RegistrationResult.Success(fakeSession))
givenSuccessfullyCreatesAccount(A_HOMESERVER_CAPABILITIES)
val test = viewModel.test(this)
@ -203,7 +203,7 @@ class OnboardingViewModelTest {
}
@Test
fun `given registration has started and has dummy step to do, when handling action, then ignores other steps and executes dummy`() = runBlockingTest {
fun `given registration has started and has dummy step to do, when handling action, then ignores other steps and executes dummy`() = runTest {
givenSuccessfulRegistrationForStartAndDummySteps(missingStages = listOf(Stage.Dummy(mandatory = true)))
val test = viewModel.test(this)
@ -221,7 +221,7 @@ class OnboardingViewModelTest {
}
@Test
fun `given changing profile picture is supported, when updating display name, then updates upstream user display name and moves to choose profile picture`() = runBlockingTest {
fun `given changing profile picture is supported, when updating display name, then updates upstream user display name and moves to choose profile picture`() = runTest {
val personalisedInitialState = initialState.copy(personalizationState = PersonalizationState(supportsChangingProfilePicture = true))
viewModel = createViewModel(personalisedInitialState)
val test = viewModel.test(this)
@ -236,7 +236,7 @@ class OnboardingViewModelTest {
}
@Test
fun `given changing profile picture is not supported, when updating display name, then updates upstream user display name and completes personalization`() = runBlockingTest {
fun `given changing profile picture is not supported, when updating display name, then updates upstream user display name and completes personalization`() = runTest {
val personalisedInitialState = initialState.copy(personalizationState = PersonalizationState(supportsChangingProfilePicture = false))
viewModel = createViewModel(personalisedInitialState)
val test = viewModel.test(this)
@ -251,7 +251,7 @@ class OnboardingViewModelTest {
}
@Test
fun `given upstream failure, when handling display name update, then emits failure event`() = runBlockingTest {
fun `given upstream failure, when handling display name update, then emits failure event`() = runTest {
val test = viewModel.test(this)
fakeSession.fakeProfileService.givenSetDisplayNameErrors(AN_ERROR)
@ -268,7 +268,7 @@ class OnboardingViewModelTest {
}
@Test
fun `when handling profile picture selected, then updates selected picture state`() = runBlockingTest {
fun `when handling profile picture selected, then updates selected picture state`() = runTest {
val test = viewModel.test(this)
viewModel.handle(OnboardingAction.ProfilePictureSelected(fakeUri.instance))
@ -283,7 +283,7 @@ class OnboardingViewModelTest {
}
@Test
fun `given a selected picture, when handling save selected profile picture, then updates upstream avatar and completes personalization`() = runBlockingTest {
fun `given a selected picture, when handling save selected profile picture, then updates upstream avatar and completes personalization`() = runTest {
val initialStateWithPicture = givenPictureSelected(fakeUri.instance, A_PICTURE_FILENAME)
viewModel = createViewModel(initialStateWithPicture)
val test = viewModel.test(this)
@ -298,7 +298,7 @@ class OnboardingViewModelTest {
}
@Test
fun `given upstream update avatar fails, when saving selected profile picture, then emits failure event`() = runBlockingTest {
fun `given upstream update avatar fails, when saving selected profile picture, then emits failure event`() = runTest {
fakeSession.fakeProfileService.givenUpdateAvatarErrors(AN_ERROR)
val initialStateWithPicture = givenPictureSelected(fakeUri.instance, A_PICTURE_FILENAME)
viewModel = createViewModel(initialStateWithPicture)
@ -313,7 +313,7 @@ class OnboardingViewModelTest {
}
@Test
fun `given no selected picture, when saving selected profile picture, then emits failure event`() = runBlockingTest {
fun `given no selected picture, when saving selected profile picture, then emits failure event`() = runTest {
val test = viewModel.test(this)
viewModel.handle(OnboardingAction.SaveSelectedProfilePicture)
@ -325,7 +325,7 @@ class OnboardingViewModelTest {
}
@Test
fun `when handling profile skipped, then completes personalization`() = runBlockingTest {
fun `when handling profile skipped, then completes personalization`() = runTest {
val test = viewModel.test(this)
viewModel.handle(OnboardingAction.UpdateProfilePictureSkipped)

View file

@ -19,7 +19,7 @@ package im.vector.app.features.onboarding
import im.vector.app.test.fakes.FakeRegistrationWizard
import im.vector.app.test.fakes.FakeSession
import io.mockk.coVerifyAll
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.test.runTest
import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test
import org.matrix.android.sdk.api.auth.registration.RegisterThreePid
@ -39,7 +39,7 @@ private val A_PID_TO_REGISTER = RegisterThreePid.Email("an email")
class RegistrationActionHandlerTest {
@Test
fun `when handling register action then delegates to wizard`() = runBlockingTest {
fun `when handling register action then delegates to wizard`() = runTest {
val cases = listOf(
case(RegisterAction.StartRegistration) { getRegistrationFlow() },
case(RegisterAction.CaptchaDone(A_CAPTCHA_RESPONSE)) { performReCaptcha(A_CAPTCHA_RESPONSE) },