diff --git a/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushrulesConditionTest.kt b/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushrulesConditionTest.kt index 7651b32d20..7cb3917195 100644 --- a/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushrulesConditionTest.kt +++ b/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushrulesConditionTest.kt @@ -16,23 +16,21 @@ package im.vector.matrix.android.api.pushrules -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData -import im.vector.matrix.android.api.MatrixCallback -import im.vector.matrix.android.api.session.content.ContentAttachmentData import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.toContent import im.vector.matrix.android.api.session.room.Room import im.vector.matrix.android.api.session.room.RoomService -import im.vector.matrix.android.api.session.room.model.* -import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams +import im.vector.matrix.android.api.session.room.model.Membership +import im.vector.matrix.android.api.session.room.model.RoomMember import im.vector.matrix.android.api.session.room.model.message.MessageTextContent -import im.vector.matrix.android.api.session.room.send.UserDraft -import im.vector.matrix.android.api.session.room.timeline.Timeline -import im.vector.matrix.android.api.session.room.timeline.TimelineEvent -import im.vector.matrix.android.api.session.room.timeline.TimelineSettings -import im.vector.matrix.android.api.util.Cancelable -import im.vector.matrix.android.api.util.Optional +import io.mockk.every +import io.mockk.mockk +import org.amshove.kluent.When +import org.amshove.kluent.any +import org.amshove.kluent.calling +import org.amshove.kluent.itAnswers +import org.amshove.kluent.itReturns +import org.amshove.kluent.mock import org.junit.Assert import org.junit.Test @@ -133,17 +131,20 @@ class PushrulesConditionTest { val conditionEqual3Bis = RoomMemberCountCondition("==3") val conditionLessThan3 = RoomMemberCountCondition("<3") - val session = MockRoomService() + val room2JoinedId = "2joined" + val room3JoinedId = "3joined" - Event( - type = "m.room.message", - eventId = "mx0", - content = MessageTextContent("m.text", "A").toContent(), - originServerTs = 0, - roomId = "2joined").also { - Assert.assertFalse("This room does not have 3 members", conditionEqual3.isSatisfied(it, session)) - Assert.assertFalse("This room does not have 3 members", conditionEqual3Bis.isSatisfied(it, session)) - Assert.assertTrue("This room has less than 3 members", conditionLessThan3.isSatisfied(it, session)) + val roomStub2Joined = mockk { + every { getNumberOfJoinedMembers() } returns 2 + } + + val roomStub3Joined = mockk { + every { getNumberOfJoinedMembers() } returns 3 + } + + val sessionStub = mockk { + every { getRoom(room2JoinedId) } returns roomStub2Joined + every { getRoom(room3JoinedId) } returns roomStub3Joined } Event( @@ -151,10 +152,21 @@ class PushrulesConditionTest { eventId = "mx0", content = MessageTextContent("m.text", "A").toContent(), originServerTs = 0, - roomId = "3joined").also { - Assert.assertTrue("This room has 3 members", conditionEqual3.isSatisfied(it, session)) - Assert.assertTrue("This room has 3 members", conditionEqual3Bis.isSatisfied(it, session)) - Assert.assertFalse("This room has more than 3 members", conditionLessThan3.isSatisfied(it, session)) + roomId = room2JoinedId).also { + Assert.assertFalse("This room does not have 3 members", conditionEqual3.isSatisfied(it, sessionStub)) + Assert.assertFalse("This room does not have 3 members", conditionEqual3Bis.isSatisfied(it, sessionStub)) + Assert.assertTrue("This room has less than 3 members", conditionLessThan3.isSatisfied(it, sessionStub)) + } + + Event( + type = "m.room.message", + eventId = "mx0", + content = MessageTextContent("m.text", "A").toContent(), + originServerTs = 0, + roomId = room3JoinedId).also { + Assert.assertTrue("This room has 3 members", conditionEqual3.isSatisfied(it, sessionStub)) + Assert.assertTrue("This room has 3 members", conditionEqual3Bis.isSatisfied(it, sessionStub)) + Assert.assertFalse("This room has more than 3 members", conditionLessThan3.isSatisfied(it, sessionStub)) } } @@ -172,211 +184,4 @@ class PushrulesConditionTest { } } - class MockRoomService() : RoomService { - override fun createRoom(createRoomParams: CreateRoomParams, callback: MatrixCallback): Cancelable { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun joinRoom(roomId: String, viaServers: List, callback: MatrixCallback): Cancelable { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun getRoom(roomId: String): Room? { - return when (roomId) { - "2joined" -> MockRoom(roomId, 2) - "3joined" -> MockRoom(roomId, 3) - else -> null - } - } - - override fun liveRoomSummaries(): LiveData> { - return MutableLiveData() - } - - override fun markAllAsRead(roomIds: List, callback: MatrixCallback): Cancelable { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - } - - class MockRoom(override val roomId: String, val _numberOfJoinedMembers: Int) : Room { - override fun reportContent(eventId: String, score: Int, reason: String, callback: MatrixCallback): Cancelable { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun getReadMarkerLive(): LiveData> { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun getMyReadReceiptLive(): LiveData> { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun resendTextMessage(localEcho: TimelineEvent): Cancelable? { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun resendMediaMessage(localEcho: TimelineEvent): Cancelable? { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun deleteFailedEcho(localEcho: TimelineEvent) { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun clearSendingQueue() { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun resendAllFailedMessages() { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun saveDraft(draft: UserDraft) { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun deleteDraft() { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun getDraftsLive(): LiveData> { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun getEventReadReceiptsLive(eventId: String): LiveData> { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun getStateEvent(eventType: String): Event? { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun editReply(replyToEdit: TimelineEvent, originalTimelineEvent: TimelineEvent, newBodyText: String, compatibilityBodyText: String): Cancelable { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun fetchEditHistory(eventId: String, callback: MatrixCallback>) { - } - - override fun getTimeLineEventLive(eventId: String): LiveData> { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun getNumberOfJoinedMembers(): Int { - return _numberOfJoinedMembers - } - - override fun getRoomSummaryLive(): LiveData> { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun roomSummary(): RoomSummary? { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun createTimeline(eventId: String?, settings: TimelineSettings): Timeline { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun getTimeLineEvent(eventId: String): TimelineEvent? { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun sendTextMessage(text: String, msgType: String, autoMarkdown: Boolean): Cancelable { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun sendFormattedTextMessage(text: String, formattedText: String): Cancelable { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun sendMedia(attachment: ContentAttachmentData): Cancelable { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun sendMedias(attachments: List): Cancelable { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun redactEvent(event: Event, reason: String?): Cancelable { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun markAllAsRead(callback: MatrixCallback) { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun setReadReceipt(eventId: String, callback: MatrixCallback) { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun setReadMarker(fullyReadEventId: String, callback: MatrixCallback) { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun isEventRead(eventId: String): Boolean { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun loadRoomMembersIfNeeded(matrixCallback: MatrixCallback): Cancelable { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun getRoomMember(userId: String): RoomMember? { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun getRoomMemberIdsLive(): LiveData> { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun invite(userId: String, callback: MatrixCallback): Cancelable { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun join(viaServers: List, callback: MatrixCallback): Cancelable { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun leave(callback: MatrixCallback): Cancelable { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun updateTopic(topic: String, callback: MatrixCallback) { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun sendReaction(targetEventId: String, reaction: String): Cancelable { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun undoReaction(targetEventId: String, reaction: String): Cancelable { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun editTextMessage(targetEventId: String, msgType: String, newBodyText: String, - newBodyAutoMarkdown: Boolean, compatibilityBodyText: String): Cancelable { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun replyToMessage(eventReplied: TimelineEvent, replyText: String, autoMarkdown: Boolean): Cancelable? { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun getEventSummaryLive(eventId: String): LiveData> { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun isEncrypted(): Boolean { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun encryptionAlgorithm(): String? { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override fun shouldEncryptForInvitedMembers(): Boolean { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - } } diff --git a/vector/src/main/java/im/vector/riotx/features/share/ShareRoomListObservableStore.kt b/vector/src/main/java/im/vector/riotx/features/share/ShareRoomListObservableStore.kt index c46ec42d64..bf7dde65ab 100644 --- a/vector/src/main/java/im/vector/riotx/features/share/ShareRoomListObservableStore.kt +++ b/vector/src/main/java/im/vector/riotx/features/share/ShareRoomListObservableStore.kt @@ -17,9 +17,10 @@ package im.vector.riotx.features.share import im.vector.matrix.android.api.session.room.model.RoomSummary +import im.vector.riotx.core.utils.BehaviorStore import im.vector.riotx.core.utils.RxStore import javax.inject.Inject import javax.inject.Singleton @Singleton -class ShareRoomListObservableStore @Inject constructor() : RxStore>() +class ShareRoomListObservableStore @Inject constructor() : BehaviorStore>()