Add missing test on RustNotificationService

This commit is contained in:
Benoit Marty 2025-06-18 14:38:33 +02:00 committed by Benoit Marty
parent 488932c4e3
commit 2953704d34
2 changed files with 17 additions and 0 deletions

View file

@ -14,8 +14,11 @@ import org.matrix.rustcomponents.sdk.NotificationItemsRequest
class FakeFfiNotificationClient(
var notificationItemResult: Map<String, NotificationItem> = emptyMap(),
val closeResult: () -> Unit = { }
) : NotificationClient(NoPointer) {
override suspend fun getNotifications(requests: List<NotificationItemsRequest>): Map<String, NotificationItem> {
return notificationItemResult
}
override fun close() = closeResult()
}

View file

@ -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<Unit> { }
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(),