Skip to content

Commit 24bceea

Browse files
committed
Uniformize the way we are creating class under test.
1 parent b0d4eb8 commit 24bceea

File tree

13 files changed

+185
-272
lines changed

13 files changed

+185
-272
lines changed

appnav/src/test/kotlin/io/element/android/appnav/JoinBaseRoomLoadedFlowNodeTest.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import io.element.android.libraries.matrix.test.FakeMatrixClient
2828
import io.element.android.libraries.matrix.test.room.FakeBaseRoom
2929
import io.element.android.libraries.matrix.test.room.FakeJoinedRoom
3030
import io.element.android.services.appnavstate.test.FakeAppNavigationStateService
31-
import kotlinx.coroutines.CoroutineScope
31+
import kotlinx.coroutines.test.TestScope
3232
import kotlinx.coroutines.test.runTest
3333
import org.junit.Rule
3434
import org.junit.Test
@@ -96,18 +96,17 @@ class JoinBaseRoomLoadedFlowNodeTest {
9696
}
9797
}
9898

99-
private fun createJoinedRoomLoadedFlowNode(
99+
private fun TestScope.createJoinedRoomLoadedFlowNode(
100100
plugins: List<Plugin>,
101101
messagesEntryPoint: MessagesEntryPoint = FakeMessagesEntryPoint(),
102102
roomDetailsEntryPoint: RoomDetailsEntryPoint = FakeRoomDetailsEntryPoint(),
103-
coroutineScope: CoroutineScope,
104103
) = JoinedRoomLoadedFlowNode(
105104
buildContext = BuildContext.root(savedStateMap = null),
106105
plugins = plugins,
107106
messagesEntryPoint = messagesEntryPoint,
108107
roomDetailsEntryPoint = roomDetailsEntryPoint,
109108
appNavigationStateService = FakeAppNavigationStateService(),
110-
appCoroutineScope = coroutineScope,
109+
appCoroutineScope = this,
111110
roomComponentFactory = FakeRoomComponentFactory(),
112111
matrixClient = FakeMatrixClient(),
113112
)
@@ -121,7 +120,6 @@ class JoinBaseRoomLoadedFlowNodeTest {
121120
val roomFlowNode = createJoinedRoomLoadedFlowNode(
122121
plugins = listOf(inputs),
123122
messagesEntryPoint = fakeMessagesEntryPoint,
124-
coroutineScope = this
125123
)
126124
// WHEN
127125
val roomFlowNodeTestHelper = roomFlowNode.parentNodeTestHelper()
@@ -144,7 +142,6 @@ class JoinBaseRoomLoadedFlowNodeTest {
144142
plugins = listOf(inputs),
145143
messagesEntryPoint = fakeMessagesEntryPoint,
146144
roomDetailsEntryPoint = fakeRoomDetailsEntryPoint,
147-
coroutineScope = this
148145
)
149146
val roomFlowNodeTestHelper = roomFlowNode.parentNodeTestHelper()
150147
// WHEN

features/call/impl/src/test/kotlin/io/element/android/features/call/utils/DefaultActiveCallManagerTest.kt

Lines changed: 118 additions & 152 deletions
Large diffs are not rendered by default.

features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/settings/LockScreenSettingsPresenterTest.kt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ import io.element.android.features.lockscreen.impl.storage.LockScreenStore
2020
import io.element.android.tests.testutils.awaitLastSequentialItem
2121
import io.element.android.tests.testutils.consumeItemsUntilPredicate
2222
import io.element.android.tests.testutils.test
23-
import kotlinx.coroutines.CoroutineScope
23+
import kotlinx.coroutines.test.TestScope
2424
import kotlinx.coroutines.test.runTest
2525
import org.junit.Test
2626

2727
class LockScreenSettingsPresenterTest {
2828
@Test
2929
fun `present - remove pin option is hidden when mandatory`() = runTest {
30-
val presenter = createLockScreenSettingsPresenter(this, lockScreenConfig = aLockScreenConfig(isPinMandatory = true))
30+
val presenter = createLockScreenSettingsPresenter(lockScreenConfig = aLockScreenConfig(isPinMandatory = true))
3131
presenter.test {
3232
awaitItem().also { state ->
3333
assertThat(state.showRemovePinOption).isFalse()
@@ -37,7 +37,7 @@ class LockScreenSettingsPresenterTest {
3737

3838
@Test
3939
fun `present - remove pin flow`() = runTest {
40-
val presenter = createLockScreenSettingsPresenter(this)
40+
val presenter = createLockScreenSettingsPresenter()
4141
presenter.test {
4242
consumeItemsUntilPredicate { state ->
4343
state.showRemovePinOption
@@ -71,7 +71,6 @@ class LockScreenSettingsPresenterTest {
7171
isDeviceSecured = true,
7272
)
7373
val presenter = createLockScreenSettingsPresenter(
74-
coroutineScope = this,
7574
biometricAuthenticatorManager = fakeBiometricAuthenticatorManager
7675
)
7776
presenter.test {
@@ -88,7 +87,6 @@ class LockScreenSettingsPresenterTest {
8887
}
8988
)
9089
val presenter = createLockScreenSettingsPresenter(
91-
coroutineScope = this,
9290
biometricAuthenticatorManager = fakeBiometricAuthenticatorManager
9391
)
9492
presenter.test {
@@ -110,7 +108,6 @@ class LockScreenSettingsPresenterTest {
110108
}
111109
)
112110
val presenter = createLockScreenSettingsPresenter(
113-
coroutineScope = this,
114111
biometricAuthenticatorManager = fakeBiometricAuthenticatorManager
115112
)
116113
presenter.test {
@@ -130,7 +127,6 @@ class LockScreenSettingsPresenterTest {
130127
)
131128
val lockScreenStore = InMemoryLockScreenStore()
132129
val presenter = createLockScreenSettingsPresenter(
133-
coroutineScope = this,
134130
lockScreenStore = lockScreenStore,
135131
biometricAuthenticatorManager = fakeBiometricAuthenticatorManager
136132
)
@@ -148,8 +144,7 @@ class LockScreenSettingsPresenterTest {
148144
}
149145
}
150146

151-
private suspend fun createLockScreenSettingsPresenter(
152-
coroutineScope: CoroutineScope,
147+
private suspend fun TestScope.createLockScreenSettingsPresenter(
153148
lockScreenConfig: LockScreenConfig = aLockScreenConfig(),
154149
biometricAuthenticatorManager: BiometricAuthenticatorManager = FakeBiometricAuthenticatorManager(),
155150
lockScreenStore: LockScreenStore = InMemoryLockScreenStore(),
@@ -160,7 +155,7 @@ class LockScreenSettingsPresenterTest {
160155
return LockScreenSettingsPresenter(
161156
lockScreenStore = lockScreenStore,
162157
pinCodeManager = pinCodeManager,
163-
coroutineScope = coroutineScope,
158+
coroutineScope = this,
164159
lockScreenConfig = lockScreenConfig,
165160
biometricAuthenticatorManager = biometricAuthenticatorManager,
166161
)

features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/unlock/PinUnlockPresenterTest.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import io.element.android.libraries.architecture.AsyncAction
2424
import io.element.android.libraries.architecture.AsyncData
2525
import io.element.android.tests.testutils.lambda.assert
2626
import io.element.android.tests.testutils.lambda.lambdaRecorder
27-
import kotlinx.coroutines.CoroutineScope
27+
import kotlinx.coroutines.test.TestScope
2828
import kotlinx.coroutines.test.runTest
2929
import org.junit.Test
3030

@@ -34,7 +34,7 @@ class PinUnlockPresenterTest {
3434

3535
@Test
3636
fun `present - success verify flow`() = runTest {
37-
val presenter = createPinUnlockPresenter(this)
37+
val presenter = createPinUnlockPresenter()
3838
moleculeFlow(RecompositionMode.Immediate) {
3939
presenter.present()
4040
}.test {
@@ -71,7 +71,7 @@ class PinUnlockPresenterTest {
7171

7272
@Test
7373
fun `present - failure verify flow`() = runTest {
74-
val presenter = createPinUnlockPresenter(this)
74+
val presenter = createPinUnlockPresenter()
7575
moleculeFlow(RecompositionMode.Immediate) {
7676
presenter.present()
7777
}.test {
@@ -100,7 +100,7 @@ class PinUnlockPresenterTest {
100100
fun `present - forgot pin flow`() = runTest {
101101
val signOutLambda = lambdaRecorder<Boolean, Unit> {}
102102
val signOut = FakeLogoutUseCase(signOutLambda)
103-
val presenter = createPinUnlockPresenter(this, logoutUseCase = signOut)
103+
val presenter = createPinUnlockPresenter(logoutUseCase = signOut)
104104
moleculeFlow(RecompositionMode.Immediate) {
105105
presenter.present()
106106
}.test {
@@ -135,8 +135,7 @@ class PinUnlockPresenterTest {
135135
dataOrNull()?.assertText(text)
136136
}
137137

138-
private suspend fun createPinUnlockPresenter(
139-
scope: CoroutineScope,
138+
private suspend fun TestScope.createPinUnlockPresenter(
140139
biometricAuthenticatorManager: BiometricAuthenticatorManager = FakeBiometricAuthenticatorManager(),
141140
callback: PinCodeManager.Callback = DefaultPinCodeManagerCallback(),
142141
logoutUseCase: FakeLogoutUseCase = FakeLogoutUseCase(logoutLambda = { "" }),
@@ -149,7 +148,7 @@ class PinUnlockPresenterTest {
149148
pinCodeManager = pinCodeManager,
150149
biometricAuthenticatorManager = biometricAuthenticatorManager,
151150
logoutUseCase = logoutUseCase,
152-
coroutineScope = scope,
151+
coroutineScope = this,
153152
pinUnlockHelper = PinUnlockHelper(biometricAuthenticatorManager, pinCodeManager),
154153
)
155154
}

features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/forward/ForwardMessagesPresenterTest.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import io.element.android.libraries.matrix.test.timeline.FakeTimeline
2121
import io.element.android.libraries.matrix.test.timeline.LiveTimelineProvider
2222
import io.element.android.tests.testutils.WarmUpRule
2323
import io.element.android.tests.testutils.lambda.lambdaRecorder
24-
import kotlinx.coroutines.CoroutineScope
24+
import kotlinx.coroutines.test.TestScope
2525
import kotlinx.coroutines.test.runTest
2626
import org.junit.Rule
2727
import org.junit.Test
@@ -91,13 +91,12 @@ class ForwardMessagesPresenterTest {
9191
}
9292
}
9393

94-
private fun CoroutineScope.aForwardMessagesPresenter(
94+
private fun TestScope.aForwardMessagesPresenter(
9595
eventId: EventId = AN_EVENT_ID,
9696
fakeRoom: FakeJoinedRoom = FakeJoinedRoom(),
97-
coroutineScope: CoroutineScope = this,
9897
) = ForwardMessagesPresenter(
9998
eventId = eventId.value,
10099
timelineProvider = LiveTimelineProvider(fakeRoom),
101-
appCoroutineScope = coroutineScope,
100+
appCoroutineScope = this,
102101
)
103102
}

0 commit comments

Comments
 (0)