InjectorFactory { static InjectorFunction injectorFunction(InjectorFunction existing, InjectorFunction... update) { if (update == null) throw new NullPointerException("injectorFunctions == null"); LinkedHashSet<InjectorFunction> injectorFunctionSet = new LinkedHashSet<>(Arrays.asList(update)); if (injectorFunctionSet.contains(null)) { throw new NullPointerException("injectorFunction == null"); } injectorFunctionSet.remove(InjectorFunction.NOOP); if (injectorFunctionSet.isEmpty()) return existing; if (injectorFunctionSet.size() == 1) return injectorFunctionSet.iterator().next(); return new CompositeInjectorFunction(injectorFunctionSet.toArray(new InjectorFunction[0])); } 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 injectorFunction_emptyIgnored() { InjectorFunction existing = mock(InjectorFunction.class); assertThat(injectorFunction(existing)) .isSameAs(existing); }
@Test public void injectorFunction_noopIgnored() { InjectorFunction existing = mock(InjectorFunction.class); assertThat(injectorFunction(existing, InjectorFunction.NOOP)) .isSameAs(existing); }
@Test public void injectorFunction_null() { InjectorFunction existing = mock(InjectorFunction.class); assertThatThrownBy(() -> injectorFunction(existing, null)) .hasMessage("injectorFunctions == null"); assertThatThrownBy(() -> injectorFunction(existing, new InjectorFunction[] {null})) .hasMessage("injectorFunction == null"); assertThatThrownBy(() -> injectorFunction(existing, one, null)) .hasMessage("injectorFunction == null"); }
@Test public void injectorFunction_single() { InjectorFunction existing = mock(InjectorFunction.class); assertThat(injectorFunction(existing, two)) .isSameAs(two); }
@Test public void injectorFunction_composite() { InjectorFunction existing = mock(InjectorFunction.class); CompositeInjectorFunction injectorFunction = (CompositeInjectorFunction) injectorFunction(existing, two, three); assertThat(injectorFunction.injectorFunctions) .containsExactly(two, three); injectorFunction.inject(setter, context, notRequest); assertThat(twoCount.getAndSet(0)).isOne(); assertThat(threeCount.getAndSet(0)).isOne(); }