mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-21 23:18:05 +01:00
Update Account#getNextDeviceId to not reuse disable device’s IDs
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user