From b55e94b9389e99ce3b3b24b4c7616ecb25673963 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 29 Sep 2021 13:20:11 +0100 Subject: [PATCH] extracting the rx instant setup to a reuseable test rule --- .../quads/SharedSecureStorageViewModelTest.kt | 13 +++----- .../java/im/vector/app/test/InstantRxRule.kt | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 vector/src/test/java/im/vector/app/test/InstantRxRule.kt diff --git a/vector/src/test/java/im/vector/app/features/crypto/quads/SharedSecureStorageViewModelTest.kt b/vector/src/test/java/im/vector/app/features/crypto/quads/SharedSecureStorageViewModelTest.kt index 630cf753bd..8f48f10868 100644 --- a/vector/src/test/java/im/vector/app/features/crypto/quads/SharedSecureStorageViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/crypto/quads/SharedSecureStorageViewModelTest.kt @@ -17,12 +17,11 @@ package im.vector.app.features.crypto.quads import com.airbnb.mvrx.Uninitialized +import im.vector.app.test.InstantRxRule import im.vector.app.test.fakes.FakeSession import im.vector.app.test.fakes.FakeStringProvider import im.vector.app.test.test -import io.reactivex.android.plugins.RxAndroidPlugins -import io.reactivex.plugins.RxJavaPlugins -import io.reactivex.schedulers.Schedulers +import org.junit.Rule import org.junit.Test import org.matrix.android.sdk.api.session.securestorage.IntegrityResult import org.matrix.android.sdk.api.session.securestorage.KeyInfo @@ -39,14 +38,12 @@ private val KEY_INFO_WITHOUT_PASSPHRASE = KeyInfo(id = "id", content = SecretSto class SharedSecureStorageViewModelTest { + @get:Rule + val instantRx = InstantRxRule() + private val stringProvider = FakeStringProvider() private val session = FakeSession() - init { - RxJavaPlugins.setInitNewThreadSchedulerHandler { Schedulers.trampoline() } - RxAndroidPlugins.setInitMainThreadSchedulerHandler { Schedulers.trampoline() } - } - @Test fun `given a key info with passphrase when initialising then step is EnterPassphrase`() { givenKey(KEY_INFO_WITH_PASSPHRASE) diff --git a/vector/src/test/java/im/vector/app/test/InstantRxRule.kt b/vector/src/test/java/im/vector/app/test/InstantRxRule.kt new file mode 100644 index 0000000000..1145cb7dd1 --- /dev/null +++ b/vector/src/test/java/im/vector/app/test/InstantRxRule.kt @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.test + +import io.reactivex.android.plugins.RxAndroidPlugins +import io.reactivex.plugins.RxJavaPlugins +import io.reactivex.schedulers.Schedulers +import org.junit.rules.TestRule +import org.junit.runner.Description +import org.junit.runners.model.Statement + +class InstantRxRule : TestRule { + override fun apply(base: Statement, description: Description?): Statement { + RxJavaPlugins.setInitNewThreadSchedulerHandler { Schedulers.trampoline() } + RxAndroidPlugins.setInitMainThreadSchedulerHandler { Schedulers.trampoline() } + return base + } +}