Update Account#getNextDeviceId to not reuse disable device’s IDs

This commit is contained in:
Chris Eager
2021-09-09 17:52:45 -07:00
committed by Chris Eager
parent 016141a05d
commit 23a076a204
2 changed files with 31 additions and 8 deletions

View File

@@ -12,6 +12,8 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.whispersystems.textsecuregcm.tests.util.DevicesHelper.createDevice;
import static org.whispersystems.textsecuregcm.tests.util.DevicesHelper.setEnabled;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
@@ -315,4 +317,29 @@ class AccountTest {
assertThrows(AssertionError.class, account::getNumber);
assertDoesNotThrow(account::getUuid);
}
@Test
void getNextDeviceId() {
final Set<Device> devices = new HashSet<>();
devices.add(createDevice(Device.MASTER_ID));
final Account account = new Account("+14151234567", UUID.randomUUID(), devices, new byte[0]);
assertThat(account.getNextDeviceId()).isEqualTo(2L);
account.addDevice(createDevice(2L));
assertThat(account.getNextDeviceId()).isEqualTo(3L);
account.addDevice(createDevice(3L));
setEnabled(account.getDevice(2L).orElseThrow(), false);
assertThat(account.getNextDeviceId()).isEqualTo(4L);
account.removeDevice(2L);
assertThat(account.getNextDeviceId()).isEqualTo(2L);
}
}