### Question:
JaegerPropagator implements TextMapPropagator { @Override public <C> void inject(Context context, C carrier, Setter<C> setter) { Objects.requireNonNull(context, "context"); Objects.requireNonNull(setter, "setter"); SpanContext spanContext = TracingContextUtils.getSpan(context).getContext(); if (!spanContext.isValid()) { return; } char[] chars = new char[PROPAGATION_HEADER_SIZE]; String traceId = spanContext.getTraceIdAsHexString(); for (int i = 0; i < traceId.length(); i++) { chars[i] = traceId.charAt(i); } chars[SPAN_ID_OFFSET - 1] = PROPAGATION_HEADER_DELIMITER; String spanId = spanContext.getSpanIdAsHexString(); for (int i = 0; i < spanId.length(); i++) { chars[SPAN_ID_OFFSET + i] = spanId.charAt(i); } chars[PARENT_SPAN_ID_OFFSET - 1] = PROPAGATION_HEADER_DELIMITER; chars[PARENT_SPAN_ID_OFFSET] = DEPRECATED_PARENT_SPAN; chars[SAMPLED_FLAG_OFFSET - 1] = PROPAGATION_HEADER_DELIMITER; chars[SAMPLED_FLAG_OFFSET] = spanContext.isSampled() ? IS_SAMPLED_CHAR : NOT_SAMPLED_CHAR; setter.set(carrier, PROPAGATION_HEADER, new String(chars)); } private  JaegerPropagator(); static JaegerPropagator 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<>(); jaegerPropagator.inject( withSpanContext( SpanContext.create( TraceId.getInvalid(), SpanId.getInvalid(), SAMPLED_TRACE_OPTIONS, TraceState.builder().set("foo", "bar").build()), Context.current()), carrier, setter); assertThat(carrier).hasSize(0); }
@Test void inject_SampledContext() { Map<String, String> carrier = new LinkedHashMap<>(); jaegerPropagator.inject( withSpanContext( SpanContext.create(TRACE_ID, SPAN_ID, SAMPLED_TRACE_OPTIONS, TRACE_STATE_DEFAULT), Context.current()), carrier, setter); assertThat(carrier) .containsEntry( PROPAGATION_HEADER, generateTraceIdHeaderValue( TRACE_ID_BASE16, SPAN_ID_BASE16, DEPRECATED_PARENT_SPAN, "1")); }
@Test void inject_SampledContext_nullCarrierUsage() { final Map<String, String> carrier = new LinkedHashMap<>(); jaegerPropagator.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( PROPAGATION_HEADER, generateTraceIdHeaderValue( TRACE_ID_BASE16, SPAN_ID_BASE16, DEPRECATED_PARENT_SPAN, "1")); }
@Test void inject_NotSampledContext() { Map<String, String> carrier = new LinkedHashMap<>(); jaegerPropagator.inject( withSpanContext( SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TRACE_STATE_DEFAULT), Context.current()), carrier, setter); assertThat(carrier) .containsEntry( PROPAGATION_HEADER, generateTraceIdHeaderValue( TRACE_ID_BASE16, SPAN_ID_BASE16, DEPRECATED_PARENT_SPAN, "0")); }