Skip to content

Commit 00ca73f

Browse files
authored
Refactor: Move InMemorySessionStore to test module (#5252)
* Refactor: Move InMemorySessionStore to test module - Delete `libraries/session-storage/impl-memory` module - Move `InMemorySessionStore.kt` to `libraries/session-storage/test` * Cleanup tests. * Fix error.
2 parents 66eb876 + 5869678 commit 00ca73f

File tree

20 files changed

+144
-188
lines changed

20 files changed

+144
-188
lines changed

features/migration/impl/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ dependencies {
3636
testImplementation(libs.test.truth)
3737
testImplementation(libs.test.turbine)
3838
testImplementation(projects.libraries.matrix.test)
39-
testImplementation(projects.libraries.sessionStorage.implMemory)
4039
testImplementation(projects.libraries.sessionStorage.test)
4140
testImplementation(projects.libraries.preferences.test)
4241
testImplementation(projects.tests.testutils)

features/migration/impl/src/test/kotlin/io/element/android/features/migration/impl/migrations/AppMigration02Test.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package io.element.android.features.migration.impl.migrations
1010
import com.google.common.truth.Truth.assertThat
1111
import io.element.android.libraries.preferences.test.FakeSessionPreferencesStoreFactory
1212
import io.element.android.libraries.preferences.test.InMemorySessionPreferencesStore
13-
import io.element.android.libraries.sessionstorage.impl.memory.InMemorySessionStore
13+
import io.element.android.libraries.sessionstorage.test.InMemorySessionStore
1414
import io.element.android.libraries.sessionstorage.test.aSessionData
1515
import io.element.android.tests.testutils.lambda.lambdaRecorder
1616
import kotlinx.coroutines.flow.first
@@ -20,12 +20,12 @@ import org.junit.Test
2020
class AppMigration02Test {
2121
@Test
2222
fun `test migration`() = runTest {
23-
val sessionStore = InMemorySessionStore().apply {
24-
updateData(aSessionData())
25-
}
23+
val sessionStore = InMemorySessionStore(
24+
initialList = listOf(aSessionData()),
25+
)
2626
val sessionPreferencesStore = InMemorySessionPreferencesStore(isSessionVerificationSkipped = false)
2727
val sessionPreferencesStoreFactory = FakeSessionPreferencesStoreFactory(
28-
getLambda = lambdaRecorder { _, _, -> sessionPreferencesStore },
28+
getLambda = lambdaRecorder { _, _ -> sessionPreferencesStore },
2929
removeLambda = lambdaRecorder { _ -> }
3030
)
3131
val migration = AppMigration02(sessionStore = sessionStore, sessionPreferenceStoreFactory = sessionPreferencesStoreFactory)

features/migration/impl/src/test/kotlin/io/element/android/features/migration/impl/migrations/AppMigration05Test.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package io.element.android.features.migration.impl.migrations
99

1010
import com.google.common.truth.Truth.assertThat
1111
import io.element.android.libraries.matrix.test.A_SESSION_ID
12-
import io.element.android.libraries.sessionstorage.impl.memory.InMemorySessionStore
12+
import io.element.android.libraries.sessionstorage.test.InMemorySessionStore
1313
import io.element.android.libraries.sessionstorage.test.aSessionData
1414
import kotlinx.coroutines.test.runTest
1515
import org.junit.Test
@@ -18,14 +18,14 @@ import java.io.File
1818
class AppMigration05Test {
1919
@Test
2020
fun `empty session path should be set to an expected path`() = runTest {
21-
val sessionStore = InMemorySessionStore().apply {
22-
updateData(
21+
val sessionStore = InMemorySessionStore(
22+
initialList = listOf(
2323
aSessionData(
2424
sessionId = A_SESSION_ID.value,
2525
sessionPath = "",
2626
)
2727
)
28-
}
28+
)
2929
val migration = AppMigration05(sessionStore = sessionStore, baseDirectory = File("/a/path"))
3030
migration.migrate()
3131
val storedData = sessionStore.getSession(A_SESSION_ID.value)!!
@@ -34,14 +34,14 @@ class AppMigration05Test {
3434

3535
@Test
3636
fun `non empty session path should not be impacted by the migration`() = runTest {
37-
val sessionStore = InMemorySessionStore().apply {
38-
updateData(
37+
val sessionStore = InMemorySessionStore(
38+
initialList = listOf(
3939
aSessionData(
4040
sessionId = A_SESSION_ID.value,
4141
sessionPath = "/a/path/existing",
4242
)
4343
)
44-
}
44+
)
4545
val migration = AppMigration05(sessionStore = sessionStore, baseDirectory = File("/a/path"))
4646
migration.migrate()
4747
val storedData = sessionStore.getSession(A_SESSION_ID.value)!!

features/migration/impl/src/test/kotlin/io/element/android/features/migration/impl/migrations/AppMigration06Test.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package io.element.android.features.migration.impl.migrations
99

1010
import com.google.common.truth.Truth.assertThat
1111
import io.element.android.libraries.matrix.test.A_SESSION_ID
12-
import io.element.android.libraries.sessionstorage.impl.memory.InMemorySessionStore
12+
import io.element.android.libraries.sessionstorage.test.InMemorySessionStore
1313
import io.element.android.libraries.sessionstorage.test.aSessionData
1414
import kotlinx.coroutines.test.runTest
1515
import org.junit.Test
@@ -18,15 +18,15 @@ import java.io.File
1818
class AppMigration06Test {
1919
@Test
2020
fun `empty cache path should be set to an expected path`() = runTest {
21-
val sessionStore = InMemorySessionStore().apply {
22-
updateData(
21+
val sessionStore = InMemorySessionStore(
22+
initialList = listOf(
2323
aSessionData(
2424
sessionId = A_SESSION_ID.value,
2525
sessionPath = "/a/path/to/a/session/AN_ID",
2626
cachePath = "",
2727
)
2828
)
29-
}
29+
)
3030
val migration = AppMigration06(sessionStore = sessionStore, cacheDirectory = File("/a/path/cache"))
3131
migration.migrate()
3232
val storedData = sessionStore.getSession(A_SESSION_ID.value)!!
@@ -35,14 +35,14 @@ class AppMigration06Test {
3535

3636
@Test
3737
fun `non empty cache path should not be impacted by the migration`() = runTest {
38-
val sessionStore = InMemorySessionStore().apply {
39-
updateData(
38+
val sessionStore = InMemorySessionStore(
39+
initialList = listOf(
4040
aSessionData(
4141
sessionId = A_SESSION_ID.value,
4242
cachePath = "/a/path/existing",
4343
)
4444
)
45-
}
45+
)
4646
val migration = AppMigration05(sessionStore = sessionStore, baseDirectory = File("/a/path/cache"))
4747
migration.migrate()
4848
val storedData = sessionStore.getSession(A_SESSION_ID.value)!!

features/rageshake/impl/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ dependencies {
5454
testImplementation(libs.test.mockk)
5555
testImplementation(projects.features.enterprise.test)
5656
testImplementation(projects.libraries.matrix.test)
57-
testImplementation(projects.libraries.sessionStorage.implMemory)
5857
testImplementation(projects.libraries.sessionStorage.test)
5958
testImplementation(projects.features.rageshake.test)
6059
testImplementation(projects.libraries.preferences.test)

features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporterTest.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import io.element.android.libraries.matrix.test.encryption.FakeEncryptionService
2727
import io.element.android.libraries.matrix.test.tracing.FakeTracingService
2828
import io.element.android.libraries.network.useragent.DefaultUserAgentProvider
2929
import io.element.android.libraries.sessionstorage.api.SessionStore
30-
import io.element.android.libraries.sessionstorage.impl.memory.InMemorySessionStore
30+
import io.element.android.libraries.sessionstorage.test.InMemorySessionStore
3131
import io.element.android.libraries.sessionstorage.test.aSessionData
3232
import io.element.android.tests.testutils.lambda.lambdaRecorder
3333
import io.element.android.tests.testutils.testCoroutineDispatchers
@@ -104,9 +104,9 @@ class DefaultBugReporterTest {
104104
)
105105
server.start()
106106

107-
val mockSessionStore = InMemorySessionStore().apply {
108-
storeData(aSessionData(sessionId = "@foo:example.com", deviceId = "ABCDEFGH"))
109-
}
107+
val mockSessionStore = InMemorySessionStore(
108+
initialList = listOf(aSessionData(sessionId = "@foo:example.com", deviceId = "ABCDEFGH"))
109+
)
110110

111111
val fakeEncryptionService = FakeEncryptionService()
112112
val matrixClient = FakeMatrixClient(encryptionService = fakeEncryptionService)
@@ -165,9 +165,9 @@ class DefaultBugReporterTest {
165165
)
166166
server.start()
167167

168-
val mockSessionStore = InMemorySessionStore().apply {
169-
storeData(aSessionData("@foo:example.com", "ABCDEFGH"))
170-
}
168+
val mockSessionStore = InMemorySessionStore(
169+
initialList = listOf(aSessionData("@foo:example.com", "ABCDEFGH"))
170+
)
171171

172172
val fakeEncryptionService = FakeEncryptionService()
173173
val matrixClient = FakeMatrixClient(encryptionService = fakeEncryptionService)
@@ -308,19 +308,19 @@ class DefaultBugReporterTest {
308308
fun `the log directory is initialized using the last session store data`() = runTest {
309309
val sut = createDefaultBugReporter(
310310
buildMeta = aBuildMeta(isEnterpriseBuild = true),
311-
sessionStore = InMemorySessionStore().apply {
312-
storeData(aSessionData(sessionId = "@alice:domain.com"))
313-
}
311+
sessionStore = InMemorySessionStore(
312+
initialList = listOf(aSessionData(sessionId = "@alice:domain.com"))
313+
)
314314
)
315315
assertThat(sut.logDirectory().absolutePath).endsWith("/cache/logs/domain.com")
316316
}
317317

318318
@Test
319319
fun `foss build - the log directory is initialized to the root log directory`() = runTest {
320320
val sut = createDefaultBugReporter(
321-
sessionStore = InMemorySessionStore().apply {
322-
storeData(aSessionData(sessionId = "@alice:domain.com"))
323-
}
321+
sessionStore = InMemorySessionStore(
322+
initialList = listOf(aSessionData(sessionId = "@alice:domain.com"))
323+
)
324324
)
325325
assertThat(sut.logDirectory().absolutePath).endsWith("/cache/logs")
326326
}

features/signedout/impl/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ dependencies {
3333
testImplementation(libs.test.truth)
3434
testImplementation(libs.test.turbine)
3535
testImplementation(projects.libraries.matrix.test)
36-
testImplementation(projects.libraries.sessionStorage.implMemory)
3736
testImplementation(projects.libraries.sessionStorage.test)
3837
testImplementation(projects.tests.testutils)
3938
}

features/signedout/impl/src/test/kotlin/io/element/android/features/signedout/impl/SignedOutPresenterTest.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import io.element.android.libraries.matrix.api.core.SessionId
1515
import io.element.android.libraries.matrix.test.A_SESSION_ID
1616
import io.element.android.libraries.matrix.test.core.aBuildMeta
1717
import io.element.android.libraries.sessionstorage.api.SessionStore
18-
import io.element.android.libraries.sessionstorage.impl.memory.InMemorySessionStore
18+
import io.element.android.libraries.sessionstorage.test.InMemorySessionStore
1919
import io.element.android.libraries.sessionstorage.test.aSessionData
2020
import io.element.android.tests.testutils.WarmUpRule
2121
import kotlinx.coroutines.test.runTest
@@ -31,9 +31,9 @@ class SignedOutPresenterTest {
3131
@Test
3232
fun `present - initial state`() = runTest {
3333
val aSessionData = aSessionData()
34-
val sessionStore = InMemorySessionStore().apply {
35-
storeData(aSessionData)
36-
}
34+
val sessionStore = InMemorySessionStore(
35+
initialList = listOf(aSessionData)
36+
)
3737
val presenter = createSignedOutPresenter(sessionStore = sessionStore)
3838
moleculeFlow(RecompositionMode.Immediate) {
3939
presenter.present()
@@ -48,9 +48,9 @@ class SignedOutPresenterTest {
4848
@Test
4949
fun `present - sign in again`() = runTest {
5050
val aSessionData = aSessionData()
51-
val sessionStore = InMemorySessionStore().apply {
52-
storeData(aSessionData)
53-
}
51+
val sessionStore = InMemorySessionStore(
52+
initialList = listOf(aSessionData)
53+
)
5454
val presenter = createSignedOutPresenter(sessionStore = sessionStore)
5555
moleculeFlow(RecompositionMode.Immediate) {
5656
presenter.present()

libraries/matrix/impl/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ dependencies {
4848
testImplementation(projects.libraries.featureflag.test)
4949
testImplementation(projects.libraries.matrix.test)
5050
testImplementation(projects.libraries.preferences.test)
51-
testImplementation(projects.libraries.sessionStorage.implMemory)
5251
testImplementation(projects.libraries.sessionStorage.test)
5352
testImplementation(projects.services.analytics.test)
5453
testImplementation(projects.services.toolbox.test)

libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/RustClientSessionDelegateTest.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package io.element.android.libraries.matrix.impl
1010
import com.google.common.truth.Truth.assertThat
1111
import io.element.android.libraries.matrix.impl.fixtures.factories.aRustSession
1212
import io.element.android.libraries.sessionstorage.api.SessionStore
13-
import io.element.android.libraries.sessionstorage.impl.memory.InMemorySessionStore
13+
import io.element.android.libraries.sessionstorage.test.InMemorySessionStore
1414
import io.element.android.libraries.sessionstorage.test.aSessionData
1515
import io.element.android.tests.testutils.testCoroutineDispatchers
1616
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -23,11 +23,12 @@ import org.junit.Test
2323
class RustClientSessionDelegateTest {
2424
@Test
2525
fun `saveSessionInKeychain should update the store`() = runTest {
26-
val sessionStore = InMemorySessionStore()
27-
sessionStore.storeData(
28-
aSessionData(
29-
accessToken = "anAccessToken",
30-
refreshToken = "aRefreshToken",
26+
val sessionStore = InMemorySessionStore(
27+
initialList = listOf(
28+
aSessionData(
29+
accessToken = "anAccessToken",
30+
refreshToken = "aRefreshToken",
31+
)
3132
)
3233
)
3334
val sut = aRustClientSessionDelegate(sessionStore)

0 commit comments

Comments
 (0)