Skip to content

Commit 0b32dbe

Browse files
committed
tests : refactor some classes
1 parent 97d4e63 commit 0b32dbe

File tree

6 files changed

+16
-15
lines changed

6 files changed

+16
-15
lines changed

features/roomlist/impl/src/test/kotlin/io/element/android/features/roomlist/impl/RoomListPresenterTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ import io.element.android.tests.testutils.testCoroutineDispatchers
9595
import kotlinx.coroutines.CoroutineScope
9696
import kotlinx.coroutines.SupervisorJob
9797
import kotlinx.coroutines.cancel
98+
import kotlinx.coroutines.flow.MutableStateFlow
9899
import kotlinx.coroutines.test.TestScope
99100
import kotlinx.coroutines.test.runTest
100101
import org.junit.Rule
@@ -219,7 +220,7 @@ class RoomListPresenterTest {
219220
val encryptionService = FakeEncryptionService().apply {
220221
emitRecoveryState(RecoveryState.INCOMPLETE)
221222
}
222-
val syncService = FakeSyncService(initialState = SyncState.Running)
223+
val syncService = FakeSyncService(MutableStateFlow(SyncState.Running))
223224
val presenter = createRoomListPresenter(
224225
client = FakeMatrixClient(roomListService = roomListService, encryptionService = encryptionService, syncService = syncService),
225226
coroutineScope = scope,
@@ -250,7 +251,7 @@ class RoomListPresenterTest {
250251
sessionVerificationService = FakeSessionVerificationService().apply {
251252
givenNeedsSessionVerification(false)
252253
},
253-
syncService = FakeSyncService(initialState = SyncState.Running)
254+
syncService = FakeSyncService(MutableStateFlow(SyncState.Running))
254255
)
255256
val scope = CoroutineScope(context = coroutineContext + SupervisorJob())
256257
val presenter = createRoomListPresenter(

libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/room/FakeMatrixRoom.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class FakeMatrixRoom(
139139
private val saveComposerDraftLambda: (ComposerDraft) -> Result<Unit> = { _: ComposerDraft -> Result.success(Unit) },
140140
private val loadComposerDraftLambda: () -> Result<ComposerDraft?> = { Result.success<ComposerDraft?>(null) },
141141
private val clearComposerDraftLambda: () -> Result<Unit> = { Result.success(Unit) },
142+
private val subscribeToSyncLambda: () -> Unit = { lambdaError() },
142143
) : MatrixRoom {
143144
private val _roomInfoFlow: MutableSharedFlow<MatrixRoomInfo> = MutableSharedFlow(replay = 1)
144145
override val roomInfoFlow: Flow<MatrixRoomInfo> = _roomInfoFlow
@@ -181,7 +182,9 @@ class FakeMatrixRoom(
181182
timelineFocusedOnEventResult(eventId)
182183
}
183184

184-
override suspend fun subscribeToSync() = Unit
185+
override suspend fun subscribeToSync() {
186+
subscribeToSyncLambda()
187+
}
185188

186189
override suspend fun powerLevels(): Result<MatrixRoomPowerLevels> {
187190
return powerLevelsResult()

libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/sync/FakeSyncService.kt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,16 @@ import kotlinx.coroutines.flow.MutableStateFlow
2222
import kotlinx.coroutines.flow.StateFlow
2323

2424
class FakeSyncService(
25-
initialState: SyncState = SyncState.Idle
25+
syncStateFlow: MutableStateFlow<SyncState> = MutableStateFlow(SyncState.Idle)
2626
) : SyncService {
27-
private val syncStateFlow = MutableStateFlow(initialState)
28-
29-
fun simulateError() {
30-
syncStateFlow.value = SyncState.Error
31-
}
32-
27+
var startSyncLambda: () -> Result<Unit> = { Result.success(Unit) }
3328
override suspend fun startSync(): Result<Unit> {
34-
syncStateFlow.value = SyncState.Running
35-
return Result.success(Unit)
29+
return startSyncLambda()
3630
}
3731

32+
var stopSyncLambda: () -> Result<Unit> = { Result.success(Unit) }
3833
override suspend fun stopSync(): Result<Unit> {
39-
syncStateFlow.value = SyncState.Terminated
40-
return Result.success(Unit)
34+
return stopSyncLambda()
4135
}
4236

4337
override val syncState: StateFlow<SyncState> = syncStateFlow

libraries/push/impl/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,6 @@ dependencies {
8282
testImplementation(projects.services.appnavstate.test)
8383
testImplementation(projects.services.toolbox.impl)
8484
testImplementation(projects.services.toolbox.test)
85+
testImplementation(projects.libraries.featureflag.test)
86+
testImplementation(libs.kotlinx.collections.immutable)
8587
}

services/appnavstate/impl/src/test/kotlin/io/element/android/services/appnavstate/impl/DefaultNavigationStateServiceTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import io.element.android.services.appnavstate.test.A_ROOM_OWNER
3131
import io.element.android.services.appnavstate.test.A_SESSION_OWNER
3232
import io.element.android.services.appnavstate.test.A_SPACE_OWNER
3333
import io.element.android.services.appnavstate.test.A_THREAD_OWNER
34+
import io.element.android.services.appnavstate.test.FakeAppForegroundStateService
3435
import io.element.android.tests.testutils.runCancellableScopeTest
3536
import kotlinx.coroutines.CoroutineScope
3637
import kotlinx.coroutines.flow.first
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.element.android.services.appnavstate.impl
17+
package io.element.android.services.appnavstate.test
1818

1919
import io.element.android.services.appnavstate.api.AppForegroundStateService
2020
import kotlinx.coroutines.flow.MutableStateFlow

0 commit comments

Comments
 (0)