Skip to content

Commit 0251318

Browse files
committed
Cleanup tests.
1 parent 75a640b commit 0251318

File tree

9 files changed

+64
-58
lines changed

9 files changed

+64
-58
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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/src/test/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporterTest.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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/src/test/kotlin/io/element/android/features/signedout/impl/SignedOutPresenterTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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/src/test/kotlin/io/element/android/libraries/matrix/impl/RustClientSessionDelegateTest.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ class SessionPathsProviderTest {
2424

2525
@Test
2626
fun `if session is found, provides returns the data`() = runTest {
27-
val store = InMemorySessionStore()
28-
val sut = SessionPathsProvider(store)
29-
store.storeData(
30-
aSessionData(
31-
sessionPath = "/a/path/to/a/session",
32-
cachePath = "/a/path/to/a/cache",
27+
val store = InMemorySessionStore(
28+
initialList = listOf(
29+
aSessionData(
30+
sessionPath = "/a/path/to/a/session",
31+
cachePath = "/a/path/to/a/cache",
32+
)
3333
)
3434
)
35+
val sut = SessionPathsProvider(store)
3536
val result = sut.provides(A_SESSION_ID)!!
3637
assertThat(result.fileDirectory.absolutePath).isEqualTo("/a/path/to/a/session")
3738
assertThat(result.cacheDirectory.absolutePath).isEqualTo("/a/path/to/a/cache")

libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/DefaultFirebaseNewTokenHandlerTest.kt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ class DefaultFirebaseNewTokenHandlerTest {
4949
val registerPusherResult = lambdaRecorder<MatrixClient, String, String, Result<Unit>> { _, _, _ -> Result.success(Unit) }
5050
val pusherSubscriber = FakePusherSubscriber(registerPusherResult = registerPusherResult)
5151
val firebaseNewTokenHandler = createDefaultFirebaseNewTokenHandler(
52-
sessionStore = InMemorySessionStore().apply {
53-
storeData(aSessionData(A_USER_ID.value))
54-
storeData(aSessionData(A_USER_ID_2.value))
55-
storeData(aSessionData(A_USER_ID_3.value))
56-
},
52+
sessionStore = InMemorySessionStore(
53+
initialList = listOf(
54+
aSessionData(A_USER_ID.value),
55+
aSessionData(A_USER_ID_2.value),
56+
aSessionData(A_USER_ID_3.value),
57+
)
58+
),
5759
matrixClientProvider = FakeMatrixClientProvider { sessionId ->
5860
when (sessionId) {
5961
A_USER_ID -> Result.success(aMatrixClient1)
@@ -88,9 +90,9 @@ class DefaultFirebaseNewTokenHandlerTest {
8890
val registerPusherResult = lambdaRecorder<MatrixClient, String, String, Result<Unit>> { _, _, _ -> Result.success(Unit) }
8991
val pusherSubscriber = FakePusherSubscriber(registerPusherResult = registerPusherResult)
9092
val firebaseNewTokenHandler = createDefaultFirebaseNewTokenHandler(
91-
sessionStore = InMemorySessionStore().apply {
92-
storeData(aSessionData(A_USER_ID.value))
93-
},
93+
sessionStore = InMemorySessionStore(
94+
initialList = listOf(aSessionData(A_USER_ID.value))
95+
),
9496
matrixClientProvider = FakeMatrixClientProvider {
9597
Result.failure(IllegalStateException())
9698
},
@@ -112,9 +114,9 @@ class DefaultFirebaseNewTokenHandlerTest {
112114
val registerPusherResult = lambdaRecorder<MatrixClient, String, String, Result<Unit>> { _, _, _ -> Result.failure(AN_EXCEPTION) }
113115
val pusherSubscriber = FakePusherSubscriber(registerPusherResult = registerPusherResult)
114116
val firebaseNewTokenHandler = createDefaultFirebaseNewTokenHandler(
115-
sessionStore = InMemorySessionStore().apply {
116-
storeData(aSessionData(A_USER_ID.value))
117-
},
117+
sessionStore = InMemorySessionStore(
118+
initialList = listOf(aSessionData(A_USER_ID.value))
119+
),
118120
matrixClientProvider = FakeMatrixClientProvider {
119121
Result.success(aMatrixClient1)
120122
},

libraries/session-storage/test/src/main/kotlin/io/element/android/libraries/sessionstorage/test/InMemorySessionStore.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import kotlinx.coroutines.flow.MutableStateFlow
1515
import kotlinx.coroutines.flow.asStateFlow
1616
import kotlinx.coroutines.flow.map
1717

18-
class InMemorySessionStore : SessionStore {
19-
private val sessionDataListFlow = MutableStateFlow<List<SessionData>>(emptyList())
18+
class InMemorySessionStore(
19+
initialList: List<SessionData> = emptyList(),
20+
) : SessionStore {
21+
private val sessionDataListFlow = MutableStateFlow(initialList)
2022

2123
override fun isLoggedIn(): Flow<LoggedInState> {
2224
return sessionDataListFlow.map {

0 commit comments

Comments
 (0)