Skip to content

Commit 7628d48

Browse files
committed
Fix quality issues.
1 parent b7c6369 commit 7628d48

File tree

3 files changed

+79
-72
lines changed

3 files changed

+79
-72
lines changed

libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/fakes/FakeRustEventTimelineItem.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FakeRustEventTimelineItem(
3232
override fun isLocal(): Boolean = false
3333
override fun isOwn(): Boolean = false
3434
override fun isRemote(): Boolean = false
35-
override fun localSendState(): EventSendState? = null
35+
override fun localSendState(): EventSendState? = null
3636
override fun reactions(): List<Reaction> = emptyList()
3737
override fun readReceipts(): Map<String, Receipt> = emptyMap()
3838
override fun sender(): String = A_USER_ID.value

libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/fakes/FakeRustTimeline.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import org.matrix.rustcomponents.sdk.Timeline
1313
import org.matrix.rustcomponents.sdk.TimelineDiff
1414
import org.matrix.rustcomponents.sdk.TimelineListener
1515

16-
class FakeRustTimeline(
17-
) : Timeline(NoPointer) {
16+
class FakeRustTimeline : Timeline(NoPointer) {
1817
private var listener: TimelineListener? = null
1918
override suspend fun addListener(listener: TimelineListener): TaskHandle {
2019
this.listener = listener

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

Lines changed: 77 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -33,89 +33,97 @@ import uniffi.matrix_sdk_ui.EventItemOrigin
3333
@OptIn(ExperimentalCoroutinesApi::class)
3434
class TimelineItemsSubscriberTest {
3535
@Test
36-
fun `when timeline emits an empty list of items, the flow must emits an empty list`() = runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
37-
val timelineItems: MutableSharedFlow<List<MatrixTimelineItem>> =
38-
MutableSharedFlow(replay = 1, extraBufferCapacity = Int.MAX_VALUE)
39-
val timeline = FakeRustTimeline()
40-
val timelineItemsSubscriber = testScope.createTimelineItemsSubscriber(
41-
coroutineScope = cancellableScope,
42-
timeline = timeline,
43-
timelineItems = timelineItems,
44-
)
45-
timelineItems.test {
46-
timelineItemsSubscriber.subscribeIfNeeded()
47-
// Wait for the listener to be set.
48-
testScope.runCurrent()
49-
timeline.emitDiff(listOf(FakeRustTimelineDiff(item = null, change = TimelineChange.RESET)))
50-
val final = awaitItem()
51-
assertThat(final).isEmpty()
52-
timelineItemsSubscriber.unsubscribeIfNeeded()
36+
fun `when timeline emits an empty list of items, the flow must emits an empty list`() {
37+
runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
38+
val timelineItems: MutableSharedFlow<List<MatrixTimelineItem>> =
39+
MutableSharedFlow(replay = 1, extraBufferCapacity = Int.MAX_VALUE)
40+
val timeline = FakeRustTimeline()
41+
val timelineItemsSubscriber = testScope.createTimelineItemsSubscriber(
42+
coroutineScope = cancellableScope,
43+
timeline = timeline,
44+
timelineItems = timelineItems,
45+
)
46+
timelineItems.test {
47+
timelineItemsSubscriber.subscribeIfNeeded()
48+
// Wait for the listener to be set.
49+
testScope.runCurrent()
50+
timeline.emitDiff(listOf(FakeRustTimelineDiff(item = null, change = TimelineChange.RESET)))
51+
val final = awaitItem()
52+
assertThat(final).isEmpty()
53+
timelineItemsSubscriber.unsubscribeIfNeeded()
54+
}
5355
}
5456
}
5557

5658
@Test
57-
fun `when timeline emits a non empty list of items, the flow must emits a non empty list`() = runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
58-
val timelineItems: MutableSharedFlow<List<MatrixTimelineItem>> =
59-
MutableSharedFlow(replay = 1, extraBufferCapacity = Int.MAX_VALUE)
60-
val timeline = FakeRustTimeline()
61-
val timelineItemsSubscriber = testScope.createTimelineItemsSubscriber(
62-
coroutineScope = cancellableScope,
63-
timeline = timeline,
64-
timelineItems = timelineItems,
65-
)
66-
timelineItems.test {
67-
timelineItemsSubscriber.subscribeIfNeeded()
68-
// Wait for the listener to be set.
69-
testScope.runCurrent()
70-
timeline.emitDiff(listOf(FakeRustTimelineDiff(item = FakeRustTimelineItem(), change = TimelineChange.RESET)))
71-
val final = awaitItem()
72-
assertThat(final).isNotEmpty()
73-
timelineItemsSubscriber.unsubscribeIfNeeded()
59+
fun `when timeline emits a non empty list of items, the flow must emits a non empty list`() {
60+
runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
61+
val timelineItems: MutableSharedFlow<List<MatrixTimelineItem>> =
62+
MutableSharedFlow(replay = 1, extraBufferCapacity = Int.MAX_VALUE)
63+
val timeline = FakeRustTimeline()
64+
val timelineItemsSubscriber = testScope.createTimelineItemsSubscriber(
65+
coroutineScope = cancellableScope,
66+
timeline = timeline,
67+
timelineItems = timelineItems,
68+
)
69+
timelineItems.test {
70+
timelineItemsSubscriber.subscribeIfNeeded()
71+
// Wait for the listener to be set.
72+
testScope.runCurrent()
73+
timeline.emitDiff(listOf(FakeRustTimelineDiff(item = FakeRustTimelineItem(), change = TimelineChange.RESET)))
74+
val final = awaitItem()
75+
assertThat(final).isNotEmpty()
76+
timelineItemsSubscriber.unsubscribeIfNeeded()
77+
}
7478
}
7579
}
7680

7781
@Test
78-
fun `when timeline emits an item with SYNC origin, the callback onNewSyncedEvent is invoked`() = runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
79-
val timelineItems: MutableSharedFlow<List<MatrixTimelineItem>> =
80-
MutableSharedFlow(replay = 1, extraBufferCapacity = Int.MAX_VALUE)
81-
val timeline = FakeRustTimeline()
82-
val onNewSyncedEventRecorder = lambdaRecorder<Unit> { }
83-
val timelineItemsSubscriber = testScope.createTimelineItemsSubscriber(
84-
coroutineScope = cancellableScope,
85-
timeline = timeline,
86-
timelineItems = timelineItems,
87-
onNewSyncedEvent = onNewSyncedEventRecorder,
88-
)
89-
timelineItems.test {
90-
timelineItemsSubscriber.subscribeIfNeeded()
91-
// Wait for the listener to be set.
92-
testScope.runCurrent()
93-
timeline.emitDiff(
94-
listOf(
95-
FakeRustTimelineDiff(
96-
item = FakeRustTimelineItem(
97-
asEventResult = FakeRustEventTimelineItem(origin = EventItemOrigin.SYNC)
98-
),
99-
change = TimelineChange.RESET,
82+
fun `when timeline emits an item with SYNC origin, the callback onNewSyncedEvent is invoked`() {
83+
runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
84+
val timelineItems: MutableSharedFlow<List<MatrixTimelineItem>> =
85+
MutableSharedFlow(replay = 1, extraBufferCapacity = Int.MAX_VALUE)
86+
val timeline = FakeRustTimeline()
87+
val onNewSyncedEventRecorder = lambdaRecorder<Unit> { }
88+
val timelineItemsSubscriber = testScope.createTimelineItemsSubscriber(
89+
coroutineScope = cancellableScope,
90+
timeline = timeline,
91+
timelineItems = timelineItems,
92+
onNewSyncedEvent = onNewSyncedEventRecorder,
93+
)
94+
timelineItems.test {
95+
timelineItemsSubscriber.subscribeIfNeeded()
96+
// Wait for the listener to be set.
97+
testScope.runCurrent()
98+
timeline.emitDiff(
99+
listOf(
100+
FakeRustTimelineDiff(
101+
item = FakeRustTimelineItem(
102+
asEventResult = FakeRustEventTimelineItem(origin = EventItemOrigin.SYNC)
103+
),
104+
change = TimelineChange.RESET,
105+
)
100106
)
101107
)
102-
)
103-
val final = awaitItem()
104-
assertThat(final).isNotEmpty()
105-
timelineItemsSubscriber.unsubscribeIfNeeded()
108+
val final = awaitItem()
109+
assertThat(final).isNotEmpty()
110+
timelineItemsSubscriber.unsubscribeIfNeeded()
111+
}
112+
onNewSyncedEventRecorder.assertions().isCalledOnce()
106113
}
107-
onNewSyncedEventRecorder.assertions().isCalledOnce()
108114
}
109115

110116
@Test
111-
fun `multiple subscriptions does not have side effect`() = runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
112-
val timelineItemsSubscriber = testScope.createTimelineItemsSubscriber(
113-
coroutineScope = cancellableScope,
114-
)
115-
timelineItemsSubscriber.subscribeIfNeeded()
116-
timelineItemsSubscriber.subscribeIfNeeded()
117-
timelineItemsSubscriber.unsubscribeIfNeeded()
118-
timelineItemsSubscriber.unsubscribeIfNeeded()
117+
fun `multiple subscriptions does not have side effect`() {
118+
runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
119+
val timelineItemsSubscriber = testScope.createTimelineItemsSubscriber(
120+
coroutineScope = cancellableScope,
121+
)
122+
timelineItemsSubscriber.subscribeIfNeeded()
123+
timelineItemsSubscriber.subscribeIfNeeded()
124+
timelineItemsSubscriber.unsubscribeIfNeeded()
125+
timelineItemsSubscriber.unsubscribeIfNeeded()
126+
}
119127
}
120128

121129
private fun TestScope.createTimelineItemsSubscriber(

0 commit comments

Comments
 (0)