From 32f7767aa592021909e1c98ed130830b1c78c587 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Mon, 5 Sep 2022 17:40:02 +0200 Subject: [PATCH] RefreshDevicesUseCase unit tests --- .../devices/v2/RefreshDevicesUseCase.kt | 1 - .../devices/v2/RefreshDevicesUseCaseTest.kt | 48 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 vector/src/test/java/im/vector/app/features/settings/devices/v2/RefreshDevicesUseCaseTest.kt diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/RefreshDevicesUseCase.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/RefreshDevicesUseCase.kt index e8f3aa7455..a53ab1d2b3 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/RefreshDevicesUseCase.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/RefreshDevicesUseCase.kt @@ -20,7 +20,6 @@ import im.vector.app.core.di.ActiveSessionHolder import org.matrix.android.sdk.api.NoOpMatrixCallback import javax.inject.Inject -// TODO add unit tests class RefreshDevicesUseCase @Inject constructor( private val activeSessionHolder: ActiveSessionHolder, ) { diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/RefreshDevicesUseCaseTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/RefreshDevicesUseCaseTest.kt new file mode 100644 index 0000000000..4cd7afaf08 --- /dev/null +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/RefreshDevicesUseCaseTest.kt @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 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.features.settings.devices.v2 + +import im.vector.app.test.fakes.FakeActiveSessionHolder +import io.mockk.every +import io.mockk.just +import io.mockk.runs +import io.mockk.verifyAll +import org.junit.Test +import org.matrix.android.sdk.api.NoOpMatrixCallback + +class RefreshDevicesUseCaseTest { + + private val fakeActiveSessionHolder = FakeActiveSessionHolder() + + private val refreshDevicesUseCase = RefreshDevicesUseCase( + activeSessionHolder = fakeActiveSessionHolder.instance + ) + + @Test + fun `given current session when refreshing then devices list and keys are fetched`() { + val session = fakeActiveSessionHolder.fakeSession + every { session.cryptoService().fetchDevicesList(any()) } just runs + every { session.cryptoService().downloadKeys(any(), any(), any()) } just runs + + refreshDevicesUseCase.execute() + + verifyAll { + session.cryptoService().fetchDevicesList(match { it is NoOpMatrixCallback }) + session.cryptoService().downloadKeys(listOf(session.myUserId), true, match { it is NoOpMatrixCallback }) + } + } +}