ServiceSettingClient implements IncomingRequestAwareClient { @Override public CompletionStage<Response<ByteString>> send(Request request, Optional<Request> incoming) { final Request withService = !request.service().isPresent() ? request.withService(serviceName) : request; return delegate.send(withService, incoming); } ServiceSettingClient(String serviceName, IncomingRequestAwareClient delegate); @Override CompletionStage<Response<ByteString>> send(Request request, Optional<Request> incoming);  }
@Test public void decoratorShouldAddService() throws Exception { Request outgoing = Request.forUri("http: client.send(outgoing, Optional.empty()); Request sent = sentRequest.getValue(); assertEquals(TEST_SERVICE, sent.service().get()); }
@Test public void decoratorShouldNotOverrideService() throws Exception { Request outgoing = Request.forUri("http: client.send(outgoing, Optional.empty()); Request sent = sentRequest.getValue(); assertEquals("manual", sent.service().get()); }