diff --git a/vector/src/androidTest/java/im/vector/app/ClearCurrentSessionRule.kt b/vector/src/androidTest/java/im/vector/app/ClearCurrentSessionRule.kt index 68db0a9509..735e96c1e0 100644 --- a/vector/src/androidTest/java/im/vector/app/ClearCurrentSessionRule.kt +++ b/vector/src/androidTest/java/im/vector/app/ClearCurrentSessionRule.kt @@ -28,6 +28,11 @@ import org.junit.runner.Description import org.junit.runners.model.Statement import kotlin.reflect.KClass +/** + * A TestRule to reset and clear the current Session. + * If a Session is active it will be signed out and cleared from the ActiveSessionHolder. + * The VectorPreferences and AnalyticsDatastore are also cleared in an attempt to recreate a fresh base. + */ class ClearCurrentSessionRule : TestWatcher() { override fun apply(base: Statement, description: Description): Statement { val context = InstrumentationRegistry.getInstrumentation().targetContext @@ -46,6 +51,10 @@ class ClearCurrentSessionRule : TestWatcher() { private fun KClass<*>.asTopLevel() = Class.forName("${qualifiedName}Kt") +/** + * Fetches the top level, private [Context.dataStore] extension property from [im.vector.app.features.analytics.store.AnalyticsStore] + * via reflection to avoid exposing property to all callers. + */ @Suppress("UNCHECKED_CAST") private fun reflectAnalyticDatastore(context: Context): DataStore { val klass = AnalyticsStore::class.asTopLevel() diff --git a/vector/src/main/java/im/vector/app/features/analytics/store/AnalyticsStore.kt b/vector/src/main/java/im/vector/app/features/analytics/store/AnalyticsStore.kt index 823d6285ed..fe1e8ad9ce 100644 --- a/vector/src/main/java/im/vector/app/features/analytics/store/AnalyticsStore.kt +++ b/vector/src/main/java/im/vector/app/features/analytics/store/AnalyticsStore.kt @@ -29,6 +29,9 @@ import kotlinx.coroutines.flow.map import org.matrix.android.sdk.api.extensions.orFalse import javax.inject.Inject +/** + * Also accessed via reflection by the instrumentation tests @see [im.vector.app.ClearCurrentSessionRule]. + */ private val Context.dataStore: DataStore by preferencesDataStore(name = "vector_analytics") /**