Fix issue when single user leaves ParticipantCollection.

This commit is contained in:
Alex Hart
2021-01-14 06:53:18 -04:00
parent ff11609a82
commit 790f8426ac
2 changed files with 32 additions and 1 deletions

View File

@@ -62,7 +62,7 @@ public class ParticipantCollection {
.indexOf(oldId);
if (newIndex != -1 && newIndex != i) {
Collections.swap(newParticipants, newIndex, i);
Collections.swap(newParticipants, newIndex, Math.min(i, newParticipants.size() - 1));
}
}

View File

@@ -87,6 +87,37 @@ public class ParticipantCollectionTest {
assertThat(result.getGridParticipants(), Matchers.contains(id(1), id(2), id(3)));
}
@Test
public void givenACollection_whenSomeoneLeaves_thenIDoNotExpectToSeeThemInTheNewList() {
// GIVEN
List<CallParticipant> initial = Arrays.asList(participant(1, 1, 2), participant(2, 1, 3), participant(3, 1, 4));
ParticipantCollection initialCollection = testSubject.getNext(initial);
List<CallParticipant> next = Arrays.asList(participant(2, 2, 3), participant(3, 1, 4));
// WHEN
ParticipantCollection result = initialCollection.getNext(next);
// THEN
assertThat(result.getGridParticipants(), Matchers.contains(id(2), id(3)));
}
@Test
public void givenACollection_whenMultipleLeave_thenIDoNotExpectToSeeThemInTheNewList() {
// GIVEN
ParticipantCollection testSubject = new ParticipantCollection(4);
List<CallParticipant> initial = Arrays.asList(participant(1, 1, 2), participant(2, 1, 3), participant(3, 1, 4), participant(4, 1, 5));
ParticipantCollection initialCollection = testSubject.getNext(initial);
List<CallParticipant> next = Arrays.asList(participant(3, 1, 4), participant(2, 1, 3));
// WHEN
ParticipantCollection result = initialCollection.getNext(next);
// THEN
assertThat(result.getGridParticipants(), Matchers.contains(id(2), id(3)));
}
@Test
public void bigTest() {