public static void verify(Optional<Account> requestAccount,
      Optional<Anonymous> accessKey,
      Optional<Account> targetAccount,
      ServiceIdentifier targetIdentifier,
      String deviceSelector) {

    try {
      verify(requestAccount, accessKey, targetAccount, targetIdentifier);

      if (!ALL_DEVICES_SELECTOR.equals(deviceSelector)) {
        byte deviceId = Byte.parseByte(deviceSelector);

        Optional<Device> targetDevice = targetAccount.get().getDevice(deviceId);

        if (targetDevice.isPresent()) {
          return;
        }

        if (requestAccount.isPresent()) {
          throw new NotFoundException();
        } else {
          throw new NotAuthorizedException(Response.Status.UNAUTHORIZED);
        }
      }
    } catch (NumberFormatException e) {
      throw new WebApplicationException(Response.status(422).build());
    }
  }
@Test
  void testTargetIdentifierIllegalArgument() {
    final String unidentifiedAccessKey = RandomStringUtils.randomAlphanumeric(16);

    final Anonymous correctUakHeader =
        new Anonymous(Base64.getEncoder().encodeToString(unidentifiedAccessKey.getBytes()));

    final Account targetAccount = mock(Account.class);
    when(targetAccount.getDevice(Device.PRIMARY_ID)).thenReturn(Optional.of(mock(Device.class)));
    when(targetAccount.getUnidentifiedAccessKey())
        .thenReturn(Optional.of(unidentifiedAccessKey.getBytes(StandardCharsets.UTF_8)));

    assertThrows(IllegalArgumentException.class,
        () -> OptionalAccess.verify(Optional.empty(), Optional.of(correctUakHeader), Optional.of(targetAccount),
            new AciServiceIdentifier(UUID.randomUUID())));
  }