### Question:
OtTracerPropagator implements TextMapPropagator { @Override public <C> void inject(Context context, C carrier, Setter<C> setter) { if (context == null || setter == null) { return; } final SpanContext spanContext = TracingContextUtils.getSpan(context).getContext(); if (!spanContext.isValid()) { return; } setter.set(carrier, TRACE_ID_HEADER, spanContext.getTraceIdAsHexString()); setter.set(carrier, SPAN_ID_HEADER, spanContext.getSpanIdAsHexString()); setter.set(carrier, SAMPLED_HEADER, String.valueOf(spanContext.isSampled())); } private  OtTracerPropagator(); static OtTracerPropagator getInstance(); @Override List<String> fields(); @Override void inject(Context context, C carrier, Setter<C> setter); @Override Context extract(Context context, C carrier, Getter<C> getter);  }### Answer:
@Test void inject_invalidContext() { Map<String, String> carrier = new LinkedHashMap<>(); propagator.inject( withSpanContext( SpanContext.create( TraceId.getInvalid(), SpanId.getInvalid(), SAMPLED_TRACE_OPTIONS, TraceState.builder().set("foo", "bar").build()), Context.current()), carrier, setter); assertThat(carrier).isEmpty(); }
@Test void inject_SampledContext() { Map<String, String> carrier = new LinkedHashMap<>(); propagator.inject( withSpanContext( SpanContext.create(TRACE_ID, SPAN_ID, SAMPLED_TRACE_OPTIONS, TRACE_STATE_DEFAULT), Context.current()), carrier, setter); assertThat(carrier).containsEntry(OtTracerPropagator.TRACE_ID_HEADER, TRACE_ID); assertThat(carrier).containsEntry(OtTracerPropagator.SPAN_ID_HEADER, SPAN_ID); assertThat(carrier).containsEntry(OtTracerPropagator.SAMPLED_HEADER, "true"); }
@Test void inject_SampledContext_nullCarrierUsage() { final Map<String, String> carrier = new LinkedHashMap<>(); propagator.inject( withSpanContext( SpanContext.create(TRACE_ID, SPAN_ID, SAMPLED_TRACE_OPTIONS, TRACE_STATE_DEFAULT), Context.current()), null, (Setter<Map<String, String>>) (ignored, key, value) -> carrier.put(key, value)); assertThat(carrier).containsEntry(OtTracerPropagator.TRACE_ID_HEADER, TRACE_ID); assertThat(carrier).containsEntry(OtTracerPropagator.SPAN_ID_HEADER, SPAN_ID); assertThat(carrier).containsEntry(OtTracerPropagator.SAMPLED_HEADER, "true"); }
@Test void inject_NotSampledContext() { Map<String, String> carrier = new LinkedHashMap<>(); propagator.inject( withSpanContext( SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TRACE_STATE_DEFAULT), Context.current()), carrier, setter); assertThat(carrier).containsEntry(OtTracerPropagator.TRACE_ID_HEADER, TRACE_ID); assertThat(carrier).containsEntry(OtTracerPropagator.SPAN_ID_HEADER, SPAN_ID); assertThat(carrier).containsEntry(OtTracerPropagator.SAMPLED_HEADER, "false"); }