From 67500edafa1fbe12e9b632be0beb60969517c0ce Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 20 Aug 2026 15:17:18 +0200 Subject: [PATCH] Move FakeCacheService to the preferences test module The fake was declared in RootFlowNodeTest, so other tests could not use it. Move it next to the API it fakes, and let the cleared cache event flow be provided by the caller, so that a test can emit events. Co-Authored-By: Claude Opus 5 (1M context) --- appnav/build.gradle.kts | 1 + .../element/android/appnav/RootFlowNodeTest.kt | 8 +------- features/preferences/test/build.gradle.kts | 2 ++ .../preferences/test/FakeCacheService.kt | 17 +++++++++++++++++ 4 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 features/preferences/test/src/main/kotlin/io/element/android/features/preferences/test/FakeCacheService.kt diff --git a/appnav/build.gradle.kts b/appnav/build.gradle.kts index 8e21f247ee..12b95d9a09 100644 --- a/appnav/build.gradle.kts +++ b/appnav/build.gradle.kts @@ -75,6 +75,7 @@ dependencies { testImplementation(projects.features.forward.test) testImplementation(projects.features.messages.test) testImplementation(projects.features.networkmonitor.test) + testImplementation(projects.features.preferences.test) testImplementation(projects.features.rageshake.test) testImplementation(projects.features.signedout.test) testImplementation(projects.services.apperror.test) diff --git a/appnav/src/test/kotlin/io/element/android/appnav/RootFlowNodeTest.kt b/appnav/src/test/kotlin/io/element/android/appnav/RootFlowNodeTest.kt index 1661782871..9cba1d7934 100644 --- a/appnav/src/test/kotlin/io/element/android/appnav/RootFlowNodeTest.kt +++ b/appnav/src/test/kotlin/io/element/android/appnav/RootFlowNodeTest.kt @@ -35,7 +35,7 @@ import io.element.android.features.login.api.LoginParams import io.element.android.features.login.api.accesscontrol.AccountProviderAccessControl import io.element.android.features.login.test.FakeLoginEntryPoint import io.element.android.features.login.test.FakeLoginIntentResolver -import io.element.android.features.preferences.api.CacheService +import io.element.android.features.preferences.test.FakeCacheService import io.element.android.features.rageshake.test.FakeBugReportEntryPoint import io.element.android.features.rageshake.test.logs.FakeAnnouncementService import io.element.android.features.share.test.FakeShareIntentHandler @@ -47,7 +47,6 @@ import io.element.android.libraries.architecture.Presenter import io.element.android.libraries.di.DependencyInjectionGraphOwner import io.element.android.libraries.featureflag.test.FakeFeatureFlagService import io.element.android.libraries.matrix.api.MatrixClient -import io.element.android.libraries.matrix.api.core.SessionId import io.element.android.libraries.matrix.test.FakeSdkMetadata import io.element.android.libraries.matrix.test.auth.FakeMatrixAuthenticationService import io.element.android.libraries.matrix.test.permalink.FakePermalinkParser @@ -65,7 +64,6 @@ import io.element.android.tests.testutils.robolectric.RobolectricTest import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.FlowCollector -import kotlinx.coroutines.flow.emptyFlow import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest @@ -208,10 +206,6 @@ private class NotUsedPresenter : Presenter { override fun present(): T = error("Not used") } -private class FakeCacheService : CacheService { - override val clearedCacheEventFlow = emptyFlow() -} - private class FakeSyncOrchestratorFactory : SyncOrchestrator.Factory { override fun create(matrixClient: MatrixClient, sessionCoroutineScope: CoroutineScope): SyncOrchestrator = error("Not used") } diff --git a/features/preferences/test/build.gradle.kts b/features/preferences/test/build.gradle.kts index a066fe4707..5b8969796a 100644 --- a/features/preferences/test/build.gradle.kts +++ b/features/preferences/test/build.gradle.kts @@ -16,5 +16,7 @@ android { dependencies { implementation(projects.libraries.architecture) implementation(projects.features.preferences.api) + implementation(projects.libraries.matrix.api) + implementation(libs.coroutines.core) implementation(projects.tests.testutils) } diff --git a/features/preferences/test/src/main/kotlin/io/element/android/features/preferences/test/FakeCacheService.kt b/features/preferences/test/src/main/kotlin/io/element/android/features/preferences/test/FakeCacheService.kt new file mode 100644 index 0000000000..9696a2050b --- /dev/null +++ b/features/preferences/test/src/main/kotlin/io/element/android/features/preferences/test/FakeCacheService.kt @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2026 Element Creations Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. + * Please see LICENSE files in the repository root for full details. + */ + +package io.element.android.features.preferences.test + +import io.element.android.features.preferences.api.CacheService +import io.element.android.libraries.matrix.api.core.SessionId +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.emptyFlow + +class FakeCacheService( + override val clearedCacheEventFlow: Flow = emptyFlow(), +) : CacheService