public CompletableFuture<Account> removeDevice(final Account account, final byte deviceId) {
    if (deviceId == Device.PRIMARY_ID) {
      throw new IllegalArgumentException("Cannot remove primary device");
    }

    return accountLockManager.withLockAsync(List.of(account.getNumber()),
        () -> removeDevice(account.getIdentifier(IdentityType.ACI), deviceId, MAX_UPDATE_ATTEMPTS),
        accountLockExecutor);
  }
@Test
  void testRemovePrimaryDevice() {
    final Device primaryDevice = new Device();
    primaryDevice.setId(Device.PRIMARY_ID);

    final Account account = AccountsHelper.generateTestAccount("+14152222222", List.of(primaryDevice));

    when(keysManager.deleteSingleUsePreKeys(any(), anyByte())).thenReturn(CompletableFuture.completedFuture(null));
    when(messagesManager.clear(any(), anyByte())).thenReturn(CompletableFuture.completedFuture(null));

    assertThrows(IllegalArgumentException.class, () -> accountsManager.removeDevice(account, Device.PRIMARY_ID));

    assertDoesNotThrow(account::getPrimaryDevice);
    verify(messagesManager, never()).clear(any(), anyByte());
    verify(keysManager, never()).deleteSingleUsePreKeys(any(), anyByte());
    verify(clientPresenceManager, never()).disconnectPresence(any(), anyByte());
  }