From bec8b5f71ecd6d8c2ab2771c6fc7926af82c5acb Mon Sep 17 00:00:00 2001 From: Valere Date: Thu, 24 Nov 2022 12:45:11 +0100 Subject: [PATCH] code review --- ... EditAggregatedSummaryEntityMapperTest.kt} | 52 ++++++++++++++++--- .../session/event/ValidDecryptedEventTest.kt | 2 +- 2 files changed, 45 insertions(+), 9 deletions(-) rename matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/mapper/{EditAggregationSummaryMapperTest.kt => EditAggregatedSummaryEntityMapperTest.kt} (57%) diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/mapper/EditAggregationSummaryMapperTest.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/mapper/EditAggregatedSummaryEntityMapperTest.kt similarity index 57% rename from matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/mapper/EditAggregationSummaryMapperTest.kt rename to matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/mapper/EditAggregatedSummaryEntityMapperTest.kt index 861f343179c..7ad5bb40e3f 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/mapper/EditAggregationSummaryMapperTest.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/mapper/EditAggregatedSummaryEntityMapperTest.kt @@ -19,17 +19,17 @@ package org.matrix.android.sdk.internal.database.mapper import io.mockk.every import io.mockk.mockk import io.realm.RealmList -import org.amshove.kluent.shouldBe +import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldNotBe import org.junit.Test import org.matrix.android.sdk.internal.database.model.EditAggregatedSummaryEntity import org.matrix.android.sdk.internal.database.model.EditionOfEvent import org.matrix.android.sdk.internal.database.model.EventEntity -class EditAggregationSummaryMapperTest { +class EditAggregatedSummaryEntityMapperTest { @Test - fun test() { + fun `test mapping summary entity to model`() { val edits = RealmList( EditionOfEvent( timestamp = 0L, @@ -56,12 +56,48 @@ class EditAggregationSummaryMapperTest { val mapped = EditAggregatedSummaryEntityMapper.map(fakeSummaryEntity) mapped shouldNotBe null - mapped!!.sourceEvents.size shouldBe 2 - mapped.localEchos.size shouldBe 1 - mapped.localEchos.first() shouldBe "e2" + mapped!!.sourceEvents.size shouldBeEqualTo 2 + mapped.localEchos.size shouldBeEqualTo 1 + mapped.localEchos.first() shouldBeEqualTo "e2" - mapped.lastEditTs shouldBe 30L - mapped.latestEdit?.eventId shouldBe "e2" + mapped.lastEditTs shouldBeEqualTo 30L + mapped.latestEdit?.eventId shouldBeEqualTo "e2" + } + + @Test + fun `event with lexicographically largest event_id is treated as more recent`() { + val lowerId = "\$Albatross" + val higherId = "\$Zebra" + + (higherId > lowerId) shouldBeEqualTo true + val timestamp = 1669288766745L + val edits = RealmList( + EditionOfEvent( + timestamp = timestamp, + eventId = lowerId, + isLocalEcho = false, + event = mockEvent(lowerId) + ), + EditionOfEvent( + timestamp = timestamp, + eventId = higherId, + isLocalEcho = false, + event = mockEvent(higherId) + ), + EditionOfEvent( + timestamp = 1L, + eventId = "e2", + isLocalEcho = true, + event = mockEvent("e2") + ) + ) + + val fakeSummaryEntity = mockk { + every { editions } returns edits + } + val mapped = EditAggregatedSummaryEntityMapper.map(fakeSummaryEntity) + mapped!!.lastEditTs shouldBeEqualTo timestamp + mapped.latestEdit?.eventId shouldBeEqualTo higherId } private fun mockEvent(eventId: String): EventEntity { diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/event/ValidDecryptedEventTest.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/event/ValidDecryptedEventTest.kt index 1d1933df84f..5fda242b90f 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/event/ValidDecryptedEventTest.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/event/ValidDecryptedEventTest.kt @@ -31,7 +31,7 @@ import org.matrix.android.sdk.api.session.room.model.message.MessageTextContent class ValidDecryptedEventTest { - val fakeEvent = Event( + private val fakeEvent = Event( type = EventType.ENCRYPTED, eventId = "\$eventId", roomId = "!fakeRoom",