@Test
public void testInterceptor() {

  Map<String, String> data = ImmutableMap.of("x-goog-api-client", "abcd", "user-agent", "defg");
  GrpcHeaderInterceptor interceptor = new GrpcHeaderInterceptor(data);
  Channel intercepted = ClientInterceptors.intercept(channel, interceptor);
  @SuppressWarnings("unchecked")
  ClientCall.Listener<Integer> listener = mock(ClientCall.Listener.class);
  ClientCall<String, Integer> interceptedCall = intercepted.newCall(method, CallOptions.DEFAULT);
  // start() on the intercepted call will eventually reach the call created by the real channel
  interceptedCall.start(listener, new Metadata());
  // The headers passed to the real channel call will contain the information inserted by the
  // interceptor.
  ArgumentCaptor<Metadata> captor = ArgumentCaptor.forClass(Metadata.class);
  verify(call).start(same(listener), captor.capture());
  final Metadata.Key<String> headerKey =
      Metadata.Key.of("x-goog-api-client", Metadata.ASCII_STRING_MARSHALLER);
  assertEquals("abcd", captor.getValue().get(headerKey));
  assertEquals("defg", interceptor.getUserAgentHeader());
}