Use Junit import
This commit is contained in:
parent
ee7518bf51
commit
61380bf48a
|
@ -18,6 +18,8 @@ package org.matrix.android.sdk.internal.crypto
|
|||
|
||||
import android.util.Log
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.FixMethodOrder
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
@ -29,8 +31,6 @@ import org.matrix.android.sdk.common.CommonTestHelper
|
|||
import org.matrix.android.sdk.common.CryptoTestHelper
|
||||
import org.matrix.android.sdk.internal.crypto.model.event.EncryptedEventContent
|
||||
import org.matrix.android.sdk.internal.crypto.model.event.RoomKeyContent
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@FixMethodOrder(MethodSorters.JVM)
|
||||
|
@ -54,7 +54,7 @@ class PreShareKeysTest : InstrumentedTest {
|
|||
&& it.getClearType() == EventType.ROOM_KEY
|
||||
}
|
||||
|
||||
assertEquals(0, preShareCount, "Bob should not have receive any key from alice at this point")
|
||||
assertEquals("Bob should not have receive any key from alice at this point", 0, preShareCount)
|
||||
Log.d("#Test", "Room Key Received from alice $preShareCount")
|
||||
|
||||
// Force presharing of new outbound key
|
||||
|
@ -78,14 +78,14 @@ class PreShareKeysTest : InstrumentedTest {
|
|||
}
|
||||
|
||||
val content = latest?.getClearContent().toModel<RoomKeyContent>()
|
||||
assertNotNull(content, "Bob should have received and decrypted a room key event from alice")
|
||||
assertEquals(e2eRoomID, content.roomId, "Wrong room")
|
||||
assertNotNull("Bob should have received and decrypted a room key event from alice", content)
|
||||
assertEquals("Wrong room", e2eRoomID, content!!.roomId)
|
||||
val megolmSessionId = content.sessionId!!
|
||||
|
||||
val sharedIndex = aliceSession.cryptoService().getSharedWithInfo(e2eRoomID, megolmSessionId)
|
||||
.getObject(bobSession.myUserId, bobSession.sessionParams.deviceId)
|
||||
|
||||
assertEquals(0, sharedIndex, "The session received by bob should match what alice sent")
|
||||
assertEquals("The session received by bob should match what alice sent", 0, sharedIndex)
|
||||
|
||||
// Just send a real message as test
|
||||
val sentEvent = mTestHelper.sendTextMessage(aliceSession.getRoom(e2eRoomID)!!, "Allo", 1).first()
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.matrix.android.sdk.session.room.timeline
|
||||
|
||||
import org.junit.Assert.fail
|
||||
import org.junit.FixMethodOrder
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
@ -29,7 +30,6 @@ import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings
|
|||
import org.matrix.android.sdk.common.CommonTestHelper
|
||||
import org.matrix.android.sdk.common.CryptoTestHelper
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import kotlin.test.fail
|
||||
|
||||
@RunWith(JUnit4::class)
|
||||
@FixMethodOrder(MethodSorters.JVM)
|
||||
|
@ -80,6 +80,7 @@ class TimelineWithManyMembersTest : InstrumentedTest {
|
|||
return@createEventListener true
|
||||
} else {
|
||||
fail("User " + session.myUserId + " decrypted as " + body + " CryptoError: " + it.root.mCryptoError)
|
||||
false
|
||||
}
|
||||
} ?: return@createEventListener false
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ package org.matrix.android.sdk.session.space
|
|||
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.FixMethodOrder
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
@ -42,8 +44,6 @@ import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
|||
import org.matrix.android.sdk.api.session.space.JoinSpaceResult
|
||||
import org.matrix.android.sdk.common.CommonTestHelper
|
||||
import org.matrix.android.sdk.common.SessionTestParams
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
|
||||
@RunWith(JUnit4::class)
|
||||
@FixMethodOrder(MethodSorters.JVM)
|
||||
|
@ -68,8 +68,8 @@ class SpaceCreationTest : InstrumentedTest {
|
|||
assertEquals(topic, syncedSpace?.asRoom()?.roomSummary()?.topic, "Room topic should be set")
|
||||
// assertEquals(topic, syncedSpace.asRoom().roomSummary()?., "Room topic should be set")
|
||||
|
||||
assertNotNull(syncedSpace, "Space should be found by Id")
|
||||
val creationEvent = syncedSpace.asRoom().getStateEvent(EventType.STATE_ROOM_CREATE)
|
||||
assertNotNull("Space should be found by Id", syncedSpace)
|
||||
val creationEvent = syncedSpace!!.asRoom().getStateEvent(EventType.STATE_ROOM_CREATE)
|
||||
val createContent = creationEvent?.content.toModel<RoomCreateContent>()
|
||||
assertEquals(RoomType.SPACE, createContent?.type, "Room type should be space")
|
||||
|
||||
|
@ -81,17 +81,17 @@ class SpaceCreationTest : InstrumentedTest {
|
|||
toModel != null
|
||||
}
|
||||
}
|
||||
assertEquals(100, powerLevelsContent?.eventsDefault, "Space-rooms should be created with a power level for events_default of 100")
|
||||
assertEquals("Space-rooms should be created with a power level for events_default of 100", 100, powerLevelsContent?.eventsDefault)
|
||||
|
||||
val guestAccess = syncedSpace.asRoom().getStateEvent(EventType.STATE_ROOM_GUEST_ACCESS)?.content
|
||||
?.toModel<RoomGuestAccessContent>()?.guestAccess
|
||||
|
||||
assertEquals(GuestAccess.CanJoin, guestAccess, "Public space room should be peekable by guest")
|
||||
assertEquals("Public space room should be peekable by guest", GuestAccess.CanJoin, guestAccess)
|
||||
|
||||
val historyVisibility = syncedSpace.asRoom().getStateEvent(EventType.STATE_ROOM_HISTORY_VISIBILITY)?.content
|
||||
?.toModel<RoomHistoryVisibilityContent>()?.historyVisibility
|
||||
|
||||
assertEquals(RoomHistoryVisibility.WORLD_READABLE, historyVisibility, "Public space room should be world readable")
|
||||
assertEquals("Public space room should be world readable", RoomHistoryVisibility.WORLD_READABLE, historyVisibility)
|
||||
|
||||
commonTestHelper.signOutAndClose(session)
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ class SpaceCreationTest : InstrumentedTest {
|
|||
// check if bob has joined automatically the first room
|
||||
|
||||
val bobMembershipFirstRoom = bobSession.getRoom(firstChild)?.roomSummary()?.membership
|
||||
assertEquals(Membership.JOIN, bobMembershipFirstRoom, "Bob should have joined this room")
|
||||
assertEquals("Bob should have joined this room", Membership.JOIN, bobMembershipFirstRoom)
|
||||
RoomSummaryQueryParams.Builder()
|
||||
|
||||
val spaceSummaryBobPov = bobSession.spaceService().getSpaceSummaries(roomSummaryQueryParams {
|
||||
|
@ -186,7 +186,7 @@ class SpaceCreationTest : InstrumentedTest {
|
|||
this.memberships = listOf(Membership.JOIN)
|
||||
}).firstOrNull()
|
||||
|
||||
assertEquals(2, spaceSummaryBobPov?.spaceChildren?.size ?: -1, "Unexpected number of children")
|
||||
assertEquals("Unexpected number of children", 2, spaceSummaryBobPov?.spaceChildren?.size ?: -1)
|
||||
|
||||
commonTestHelper.signOutAndClose(aliceSession)
|
||||
commonTestHelper.signOutAndClose(bobSession)
|
||||
|
|
|
@ -23,6 +23,9 @@ import kotlinx.coroutines.GlobalScope
|
|||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.FixMethodOrder
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
@ -36,9 +39,6 @@ import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams
|
|||
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||
import org.matrix.android.sdk.common.CommonTestHelper
|
||||
import org.matrix.android.sdk.common.SessionTestParams
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@RunWith(JUnit4::class)
|
||||
@FixMethodOrder(MethodSorters.JVM)
|
||||
|
@ -84,11 +84,11 @@ class SpaceHierarchyTest : InstrumentedTest {
|
|||
}
|
||||
|
||||
assertNotNull(parents)
|
||||
assertEquals(1, parents.size)
|
||||
assertEquals(1, parents!!.size)
|
||||
assertEquals(spaceName, parents.first().roomSummary?.name)
|
||||
|
||||
assertNotNull(canonicalParents)
|
||||
assertEquals(1, canonicalParents.size)
|
||||
assertEquals(1, canonicalParents!!.size)
|
||||
assertEquals(spaceName, canonicalParents.first().roomSummary?.name)
|
||||
}
|
||||
|
||||
|
@ -133,9 +133,9 @@ class SpaceHierarchyTest : InstrumentedTest {
|
|||
val canonicalParents = session.getRoom(it.first)?.roomSummary()?.spaceParents?.filter { it.canonical == true }
|
||||
|
||||
assertNotNull(parents)
|
||||
assertEquals(1, parents.size, "Unexpected number of parent")
|
||||
assertEquals(spaceName, parents.first().roomSummary?.name, "Unexpected parent name ")
|
||||
assertEquals(if (it.second) 1 else 0, canonicalParents?.size ?: 0, "Parent of ${it.first} should be canonical ${it.second}")
|
||||
assertEquals("Unexpected number of parent", 1, parents!!.size)
|
||||
assertEquals("Unexpected parent name", spaceName, parents.first().roomSummary?.name)
|
||||
assertEquals("Parent of ${it.first} should be canonical ${it.second}", if (it.second) 1 else 0, canonicalParents?.size ?: 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,21 +178,21 @@ class SpaceHierarchyTest : InstrumentedTest {
|
|||
|
||||
val allRooms = session.getRoomSummaries(roomSummaryQueryParams { excludeType = listOf(RoomType.SPACE) })
|
||||
|
||||
assertEquals(9, allRooms.size, "Unexpected number of rooms")
|
||||
assertEquals("Unexpected number of rooms", 9, allRooms.size)
|
||||
|
||||
val orphans = session.getFlattenRoomSummaryChildrenOf(null)
|
||||
|
||||
assertEquals(2, orphans.size, "Unexpected number of orphan rooms")
|
||||
assertTrue(orphans.indexOfFirst { it.roomId == orphan1 } != -1, "O1 should be an orphan")
|
||||
assertTrue(orphans.indexOfFirst { it.roomId == orphan2 } != -1, "O2 should be an orphan ${orphans.map { it.name }}")
|
||||
assertEquals("Unexpected number of orphan rooms", 2, orphans.size)
|
||||
assertTrue("O1 should be an orphan", orphans.any { it.roomId == orphan1 })
|
||||
assertTrue("O2 should be an orphan ${orphans.map { it.name }}", orphans.any { it.roomId == orphan2 })
|
||||
|
||||
val aChildren = session.getFlattenRoomSummaryChildrenOf(spaceAInfo.spaceId)
|
||||
|
||||
assertEquals(4, aChildren.size, "Unexpected number of flatten child rooms")
|
||||
assertTrue(aChildren.indexOfFirst { it.name == "A1" } != -1, "A1 should be a child of A")
|
||||
assertTrue(aChildren.indexOfFirst { it.name == "A2" } != -1, "A2 should be a child of A")
|
||||
assertTrue(aChildren.indexOfFirst { it.name == "C1" } != -1, "CA should be a grand child of A")
|
||||
assertTrue(aChildren.indexOfFirst { it.name == "C2" } != -1, "A1 should be a grand child of A")
|
||||
assertEquals("Unexpected number of flatten child rooms", 4, aChildren.size)
|
||||
assertTrue("A1 should be a child of A", aChildren.any { it.name == "A1" })
|
||||
assertTrue("A2 should be a child of A", aChildren.any { it.name == "A2" })
|
||||
assertTrue("CA should be a grand child of A", aChildren.any { it.name == "C1" })
|
||||
assertTrue("A1 should be a grand child of A", aChildren.any { it.name == "C2" })
|
||||
|
||||
// Add a non canonical child and check that it does not appear as orphan
|
||||
val a3 = runBlocking {
|
||||
|
@ -205,7 +205,7 @@ class SpaceHierarchyTest : InstrumentedTest {
|
|||
}
|
||||
|
||||
val orphansUpdate = session.getFlattenRoomSummaryChildrenOf(null)
|
||||
assertEquals(2, orphansUpdate.size, "Unexpected number of orphan rooms ${orphansUpdate.map { it.name }}")
|
||||
assertEquals("Unexpected number of orphan rooms ${orphansUpdate.map { it.name }}", 2, orphansUpdate.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -242,11 +242,11 @@ class SpaceHierarchyTest : InstrumentedTest {
|
|||
|
||||
val aChildren = session.getFlattenRoomSummaryChildrenOf(spaceAInfo.spaceId)
|
||||
|
||||
assertEquals(4, aChildren.size, "Unexpected number of flatten child rooms ${aChildren.map { it.name }}")
|
||||
assertTrue(aChildren.indexOfFirst { it.name == "A1" } != -1, "A1 should be a child of A")
|
||||
assertTrue(aChildren.indexOfFirst { it.name == "A2" } != -1, "A2 should be a child of A")
|
||||
assertTrue(aChildren.indexOfFirst { it.name == "C1" } != -1, "CA should be a grand child of A")
|
||||
assertTrue(aChildren.indexOfFirst { it.name == "C2" } != -1, "A1 should be a grand child of A")
|
||||
assertEquals("Unexpected number of flatten child rooms ${aChildren.map { it.name }}", 4, aChildren.size)
|
||||
assertTrue("A1 should be a child of A", aChildren.any { it.name == "A1" })
|
||||
assertTrue("A2 should be a child of A", aChildren.any { it.name == "A2" })
|
||||
assertTrue("CA should be a grand child of A", aChildren.any { it.name == "C1" })
|
||||
assertTrue("A1 should be a grand child of A", aChildren.any { it.name == "C2" })
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -282,9 +282,7 @@ class SpaceHierarchyTest : InstrumentedTest {
|
|||
override fun onChanged(children: List<RoomSummary>?) {
|
||||
// Log.d("## TEST", "Space A flat children update : ${children?.map { it.name }}")
|
||||
System.out.println("## TEST | Space A flat children update : ${children?.map { it.name }}")
|
||||
if (children?.indexOfFirst { it.name == "C1" } != -1
|
||||
&& children?.indexOfFirst { it.name == "C2" } != -1
|
||||
) {
|
||||
if (children?.any { it.name == "C1" } == true && children.any { it.name == "C2" }) {
|
||||
// B1 has been added live!
|
||||
latch.countDown()
|
||||
flatAChildren.removeObserver(this)
|
||||
|
@ -409,6 +407,6 @@ class SpaceHierarchyTest : InstrumentedTest {
|
|||
|
||||
val rootSpaces = session.spaceService().getRootSpaceSummaries()
|
||||
|
||||
assertEquals(2, rootSpaces.size, "Unexpected number of root spaces ${rootSpaces.map { it.name }}")
|
||||
assertEquals("Unexpected number of root spaces ${rootSpaces.map { it.name }}", 2, rootSpaces.size)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue