@Override
  public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(final ServerCall<ReqT, RespT> call,
      final Metadata headers,
      final ServerCallHandler<ReqT, RespT> next) {

    return getAuthenticatedDevice(call)
        .map(authenticatedDevice -> Contexts.interceptCall(Context.current()
                .withValue(AuthenticationUtil.CONTEXT_AUTHENTICATED_DEVICE, authenticatedDevice),
            call, headers, next))
        .orElseGet(() -> closeAsUnauthenticated(call));
  }
@Test
  void interceptCall() {
    final ClientConnectionManager clientConnectionManager = getClientConnectionManager();

    when(clientConnectionManager.getAuthenticatedDevice(any())).thenReturn(Optional.empty());

    GrpcTestUtils.assertStatusException(Status.UNAUTHENTICATED, this::getAuthenticatedDevice);

    final AuthenticatedDevice authenticatedDevice = new AuthenticatedDevice(UUID.randomUUID(), Device.PRIMARY_ID);
    when(clientConnectionManager.getAuthenticatedDevice(any())).thenReturn(Optional.of(authenticatedDevice));

    final GetAuthenticatedDeviceResponse response = getAuthenticatedDevice();
    assertEquals(UUIDUtil.toByteString(authenticatedDevice.accountIdentifier()), response.getAccountIdentifier());
    assertEquals(authenticatedDevice.deviceId(), response.getDeviceId());
  }