From 0a50c9f9cfeff74a3d9f294f0c5c4ccaea461ce4 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 18 Jun 2025 14:38:33 +0200 Subject: [PATCH] Add missing test on RustNotificationService --- .../fixtures/fakes/FakeFfiNotificationClient.kt | 3 +++ .../notification/RustNotificationServiceTest.kt | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/fakes/FakeFfiNotificationClient.kt b/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/fakes/FakeFfiNotificationClient.kt index ec244ede74..180da9cc89 100644 --- a/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/fakes/FakeFfiNotificationClient.kt +++ b/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/fakes/FakeFfiNotificationClient.kt @@ -14,8 +14,11 @@ import org.matrix.rustcomponents.sdk.NotificationItemsRequest class FakeFfiNotificationClient( var notificationItemResult: Map = emptyMap(), + val closeResult: () -> Unit = { } ) : NotificationClient(NoPointer) { override suspend fun getNotifications(requests: List): Map { return notificationItemResult } + + override fun close() = closeResult() } diff --git a/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/notification/RustNotificationServiceTest.kt b/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/notification/RustNotificationServiceTest.kt index 0349523d11..3166acc891 100644 --- a/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/notification/RustNotificationServiceTest.kt +++ b/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/notification/RustNotificationServiceTest.kt @@ -19,6 +19,7 @@ import io.element.android.libraries.matrix.test.A_SESSION_ID import io.element.android.libraries.matrix.test.A_USER_ID_2 import io.element.android.services.toolbox.api.systemclock.SystemClock import io.element.android.services.toolbox.test.systemclock.FakeSystemClock +import io.element.android.tests.testutils.lambda.lambdaRecorder import io.element.android.tests.testutils.testCoroutineDispatchers import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runTest @@ -61,6 +62,19 @@ class RustNotificationServiceTest { ) } + @Test + fun `close should invoke the close method of the service`() = runTest { + val closeResult = lambdaRecorder { } + val notificationClient = FakeFfiNotificationClient( + closeResult = closeResult, + ) + val sut = createRustNotificationService( + notificationClient = notificationClient, + ) + sut.close() + closeResult.assertions().isCalledOnce() + } + private fun TestScope.createRustNotificationService( notificationClient: NotificationClient = FakeFfiNotificationClient(), clock: SystemClock = FakeSystemClock(),