### Question:
B3Propagator implements Propagator { @Override public <C> SpanContext extract(C carrier) { if (!(carrier instanceof TextMapExtract)) { return null; } Long traceId = null; Long spanId = null; String foreignTraceId = null; for (Map.Entry<String, String> entry : (TextMapExtract)carrier) { if (entry.getKey().equalsIgnoreCase(TRACE_ID_NAME)) { foreignTraceId = entry.getValue(); traceId = Util.fromHexString(normalizeTraceId(foreignTraceId)); } else if (entry.getKey().equalsIgnoreCase(SPAN_ID_NAME)) { spanId = Util.fromHexString(entry.getValue()); } } if (null != traceId && null != spanId) { return new SpanContext(traceId, spanId, foreignTraceId); } return null; }  @Override void inject(SpanContext spanContext, C carrier); @Override SpanContext extract(C carrier);  }### Answer:
@Test public void testExtract_mixedCaseIsLowered() { Map<String, String> mixedCaseHeaders = new HashMap<>(); mixedCaseHeaders.put("X-B3-SpanId", Long.toHexString(1)); mixedCaseHeaders.put("X-b3-traceId", Long.toHexString(2)); mixedCaseHeaders.put("x-B3-sampled", "1"); B3Propagator subject = new B3Propagator(); SpanContext span = subject.extract(new TextMapExtractAdapter(mixedCaseHeaders)); assertNotNull(span); assertEquals(span.getSpanId(), 1); assertEquals(span.getTraceId(), 2); }
@Test public void testExtractEmptyHeaders() { Map<String, String> headers = new HashMap<>(); headers.put("X-B3-SpanId", ""); headers.put("X-B3-TraceId", ""); B3Propagator subject = new B3Propagator(); SpanContext span = subject.extract(new TextMapExtractAdapter(headers)); assertNull(span); }
@Test public void testExtractInvalidHeaders() { Map<String, String> headers = new HashMap<>(); headers.put("X-B3-SpanId", "#$%"); headers.put("X-B3-TraceId", "#$%"); B3Propagator subject = new B3Propagator(); SpanContext span = subject.extract(new TextMapExtractAdapter(headers)); assertNull(span); }
@Test public void testExtractSampledOldFormat() { Map<String, String> headers = new HashMap<>(); headers.put("X-B3-SpanId", "12345"); headers.put("X-B3-TraceId", "67890"); headers.put("X-B3-Sampled", "true"); B3Propagator subject = new B3Propagator(); SpanContext span = subject.extract(new TextMapExtractAdapter(headers)); assertNotNull(span); assertEquals(span.toSpanId(), "12345"); assertEquals(span.toTraceId(), "67890"); }