From dd13b6bd99a5b110f7568ea7718e7f45bbb12425 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 7 Feb 2020 15:44:46 +0100 Subject: [PATCH] Add test for DisplayName condition (passing) --- .../api/pushrules/PushrulesConditionTest.kt | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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 f334c0f099..960d585bdc 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 @@ -25,6 +25,7 @@ import im.vector.matrix.android.api.session.room.model.message.MessageTextConten import im.vector.matrix.android.internal.session.room.RoomGetter import io.mockk.every import io.mockk.mockk +import org.amshove.kluent.shouldBe import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test @@ -186,4 +187,31 @@ class PushrulesConditionTest { assertFalse("This room has more than 3 members", conditionLessThan3.isSatisfied(it, roomGetterStub)) } } + + /* ========================================================================================== + * Test ContainsDisplayNameCondition + * ========================================================================================== */ + + @Test + fun test_displayName_condition() { + val condition = ContainsDisplayNameCondition() + + val event = Event( + type = "m.room.message", + eventId = "mx0", + content = MessageTextContent("m.text", "How was the cake benoit?").toContent(), + originServerTs = 0, + roomId = "2joined") + + condition.isSatisfied(event, "how") shouldBe true + condition.isSatisfied(event, "How") shouldBe true + condition.isSatisfied(event, "benoit") shouldBe true + condition.isSatisfied(event, "Benoit") shouldBe true + condition.isSatisfied(event, "cake") shouldBe true + + condition.isSatisfied(event, "ben") shouldBe false + condition.isSatisfied(event, "oit") shouldBe false + condition.isSatisfied(event, "enoi") shouldBe false + condition.isSatisfied(event, "H") shouldBe false + } }