GrpcHeaderInterceptor implements ClientInterceptor { public String getUserAgentHeader() { return userAgentHeader; } GrpcHeaderInterceptor(Map<String, String> staticHeaders); @Override ClientCall<ReqT, RespT> interceptCall(
      MethodDescriptor<ReqT, RespT> method, final CallOptions callOptions, Channel next); String getUserAgentHeader();  }
@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); interceptedCall.start(listener, new Metadata()); 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()); }