InjectorFactory { public <R> TraceContext.Injector<R> newInjector(Setter<R, String> setter) { if (setter == null) throw new NullPointerException("setter == null"); if (setter instanceof RemoteSetter) { RemoteSetter<?> remoteSetter = (RemoteSetter<?>) setter; switch (remoteSetter.spanKind()) { case CLIENT: return new RemoteInjector<>(setter, clientInjectorFunction); case PRODUCER: return new RemoteInjector<>(setter, producerInjectorFunction); case CONSUMER: return new RemoteInjector<>(setter, consumerInjectorFunction); default: } } return new DeferredInjector<>(setter, this); } InjectorFactory(Builder builder); static Builder newBuilder(InjectorFunction injectorFunction); List<String> keyNames(); TraceContext.Injector<R> newInjector(Setter<R, String> setter); @Override int hashCode(); @Override boolean equals(Object o); @Override String toString();  }
@Test public void oneFunction_injects_deferred() { DeferredInjector<Object> deferredInjector = (DeferredInjector<Object>) oneFunction.newInjector(setter); for (Kind kind : injectableKinds) { when(request.spanKind()).thenReturn(kind); deferredInjector.inject(context, request); assertThat(oneCount.getAndSet(0)).isOne(); } deferredInjector.inject(context, notRequest); assertThat(oneCount.getAndSet(0)).isOne(); when(request.spanKind()).thenReturn(Kind.SERVER); deferredInjector.inject(context, request); assertThat(oneCount.getAndSet(0)).isOne(); }
@Test public void twoFunctions_injects_deferred() { DeferredInjector<Object> deferredInjector = (DeferredInjector<Object>) twoFunctions.newInjector(setter); for (Kind kind : injectableKinds) { when(request.spanKind()).thenReturn(kind); deferredInjector.inject(context, request); assertThat(oneCount.getAndSet(0)).isOne(); assertThat(twoCount.getAndSet(0)).isOne(); } deferredInjector.inject(context, notRequest); assertThat(oneCount.getAndSet(0)).isOne(); assertThat(twoCount.getAndSet(0)).isOne(); when(request.spanKind()).thenReturn(Kind.SERVER); deferredInjector.inject(context, request); assertThat(oneCount.getAndSet(0)).isOne(); assertThat(twoCount.getAndSet(0)).isOne(); }