正在显示
1 个修改的文件
包含
42 行增加
和
3 行删除
| @@ -2,23 +2,35 @@ package io.livekit.android.room.participant | @@ -2,23 +2,35 @@ package io.livekit.android.room.participant | ||
| 2 | 2 | ||
| 3 | import io.livekit.android.room.RTCClient | 3 | import io.livekit.android.room.RTCClient |
| 4 | import livekit.LivekitModels | 4 | import livekit.LivekitModels |
| 5 | -import org.junit.Assert.assertEquals | ||
| 6 | -import org.junit.Assert.assertNotNull | 5 | +import org.junit.Assert.* |
| 7 | import org.junit.Before | 6 | import org.junit.Before |
| 8 | import org.junit.Test | 7 | import org.junit.Test |
| 9 | import org.mockito.Mockito | 8 | import org.mockito.Mockito |
| 10 | 9 | ||
| 11 | class RemoteParticipantTest { | 10 | class RemoteParticipantTest { |
| 12 | 11 | ||
| 12 | + lateinit var rtcClient: RTCClient | ||
| 13 | lateinit var participant: RemoteParticipant | 13 | lateinit var participant: RemoteParticipant |
| 14 | 14 | ||
| 15 | @Before | 15 | @Before |
| 16 | fun setup() { | 16 | fun setup() { |
| 17 | - val rtcClient = Mockito.mock(RTCClient::class.java) | 17 | + rtcClient = Mockito.mock(RTCClient::class.java) |
| 18 | participant = RemoteParticipant(rtcClient, "sid") | 18 | participant = RemoteParticipant(rtcClient, "sid") |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | @Test | 21 | @Test |
| 22 | + fun constructorAddsTrack() { | ||
| 23 | + val info = LivekitModels.ParticipantInfo.newBuilder(INFO) | ||
| 24 | + .addTracks(TRACK_INFO) | ||
| 25 | + .build() | ||
| 26 | + | ||
| 27 | + participant = RemoteParticipant(rtcClient, info) | ||
| 28 | + | ||
| 29 | + assertEquals(1, participant.tracks.values.size) | ||
| 30 | + assertNotNull(participant.getTrackPublication(TRACK_INFO.sid)) | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + @Test | ||
| 22 | fun updateFromInfoAddsTrack() { | 34 | fun updateFromInfoAddsTrack() { |
| 23 | val newTrackInfo = LivekitModels.ParticipantInfo.newBuilder(INFO) | 35 | val newTrackInfo = LivekitModels.ParticipantInfo.newBuilder(INFO) |
| 24 | .addTracks(TRACK_INFO) | 36 | .addTracks(TRACK_INFO) |
| @@ -30,6 +42,33 @@ class RemoteParticipantTest { | @@ -30,6 +42,33 @@ class RemoteParticipantTest { | ||
| 30 | assertNotNull(participant.getTrackPublication(TRACK_INFO.sid)) | 42 | assertNotNull(participant.getTrackPublication(TRACK_INFO.sid)) |
| 31 | } | 43 | } |
| 32 | 44 | ||
| 45 | + @Test | ||
| 46 | + fun updateFromInfoRemovesTrack() { | ||
| 47 | + val newTrackInfo = LivekitModels.ParticipantInfo.newBuilder(INFO) | ||
| 48 | + .addTracks(TRACK_INFO) | ||
| 49 | + .build() | ||
| 50 | + | ||
| 51 | + participant.updateFromInfo(newTrackInfo) | ||
| 52 | + participant.updateFromInfo(INFO) | ||
| 53 | + | ||
| 54 | + assertEquals(0, participant.tracks.values.size) | ||
| 55 | + assertNull(participant.getTrackPublication(TRACK_INFO.sid)) | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + | ||
| 59 | + @Test | ||
| 60 | + fun unpublishTrackRemoves() { | ||
| 61 | + val newTrackInfo = LivekitModels.ParticipantInfo.newBuilder(INFO) | ||
| 62 | + .addTracks(TRACK_INFO) | ||
| 63 | + .build() | ||
| 64 | + | ||
| 65 | + participant.updateFromInfo(newTrackInfo) | ||
| 66 | + participant.unpublishTrack(TRACK_INFO.sid) | ||
| 67 | + | ||
| 68 | + assertEquals(0, participant.tracks.values.size) | ||
| 69 | + assertNull(participant.getTrackPublication(TRACK_INFO.sid)) | ||
| 70 | + } | ||
| 71 | + | ||
| 33 | 72 | ||
| 34 | companion object { | 73 | companion object { |
| 35 | val INFO = LivekitModels.ParticipantInfo.newBuilder() | 74 | val INFO = LivekitModels.ParticipantInfo.newBuilder() |
-
请 注册 或 登录 后发表评论