@Override
  public Mono<GetAccountIdentityResponse> getAccountIdentity(final GetAccountIdentityRequest request) {
    final AuthenticatedDevice authenticatedDevice = AuthenticationUtil.requireAuthenticatedDevice();

    return Mono.fromFuture(() -> accountsManager.getByAccountIdentifierAsync(authenticatedDevice.accountIdentifier()))
        .map(maybeAccount -> maybeAccount.orElseThrow(Status.UNAUTHENTICATED::asRuntimeException))
        .map(account -> {
          final AccountIdentifiers.Builder accountIdentifiersBuilder = AccountIdentifiers.newBuilder()
              .addServiceIdentifiers(ServiceIdentifierUtil.toGrpcServiceIdentifier(new AciServiceIdentifier(account.getUuid())))
              .addServiceIdentifiers(ServiceIdentifierUtil.toGrpcServiceIdentifier(new PniServiceIdentifier(account.getPhoneNumberIdentifier())))
              .setE164(account.getNumber());

          account.getUsernameHash().ifPresent(usernameHash ->
              accountIdentifiersBuilder.setUsernameHash(ByteString.copyFrom(usernameHash)));

          return GetAccountIdentityResponse.newBuilder()
              .setAccountIdentifiers(accountIdentifiersBuilder.build())
              .build();
        });
  }
@Test
  void getAccountIdentity() {
    final UUID phoneNumberIdentifier = UUID.randomUUID();
    final String e164 = PhoneNumberUtil.getInstance().format(
        PhoneNumberUtil.getInstance().getExampleNumber("US"), PhoneNumberUtil.PhoneNumberFormat.E164);

    final byte[] usernameHash = TestRandomUtil.nextBytes(32);

    final Account account = mock(Account.class);
    when(account.getUuid()).thenReturn(AUTHENTICATED_ACI);
    when(account.getPhoneNumberIdentifier()).thenReturn(phoneNumberIdentifier);
    when(account.getNumber()).thenReturn(e164);
    when(account.getUsernameHash()).thenReturn(Optional.of(usernameHash));

    when(accountsManager.getByAccountIdentifierAsync(AUTHENTICATED_ACI))
        .thenReturn(CompletableFuture.completedFuture(Optional.of(account)));

    final GetAccountIdentityResponse expectedResponse = GetAccountIdentityResponse.newBuilder()
        .setAccountIdentifiers(AccountIdentifiers.newBuilder()
            .addServiceIdentifiers(ServiceIdentifierUtil.toGrpcServiceIdentifier(new AciServiceIdentifier(AUTHENTICATED_ACI)))
            .addServiceIdentifiers(ServiceIdentifierUtil.toGrpcServiceIdentifier(new PniServiceIdentifier(phoneNumberIdentifier)))
            .setE164(e164)
            .setUsernameHash(ByteString.copyFrom(usernameHash))
            .build())
        .build();

    assertEquals(expectedResponse, authenticatedServiceStub().getAccountIdentity(GetAccountIdentityRequest.newBuilder().build()));
  }