MockTracer implements Tracer { public synchronized Map<String, Map<String, MockSpan>> finishedTraces() { Map<String, Map<String, MockSpan>> result = new LinkedHashMap<>(); for (MockSpan span: this.finishedSpans) { String traceId = span.context().toTraceId(); Map<String, MockSpan> spanId2Span = result.get(traceId); if (null == spanId2Span) { spanId2Span = new LinkedHashMap<>(); result.put(traceId, spanId2Span); } String spanId = span.context().toSpanId(); spanId2Span.put(spanId, span); } return result; } MockTracer();  MockTracer(ScopeManager scopeManager);  MockTracer(ScopeManager scopeManager, Propagator propagator);  MockTracer(Propagator propagator); synchronized void reset(); synchronized List<MockSpan> finishedSpans(); synchronized Map<String, Map<String, MockSpan>> finishedTraces(); @Override ScopeManager scopeManager(); @Override SpanBuilder buildSpan(String operationName); @Override void inject(SpanContext spanContext, Format<C> format, C carrier); @Override SpanContext extract(Format<C> format, C carrier); @Override Span activeSpan(); @Override Scope activateSpan(Span span); @Override synchronized void close();  }
@Test public void testFinishedTraces() { final int TRACE_CNT = 3; Map<String, Map<String, MockSpan>> expect = new LinkedHashMap<>(); try(MockTracer tracer = new MockTracer()) { for (int i = 0; i < TRACE_CNT; i++) { MockSpan parent = tracer.buildSpan("parent").withStartTimestamp(1000).start(); MockSpan child = tracer.buildSpan("child").withStartTimestamp(1100).asChildOf(parent).start(); child.finish(1900); parent.finish(2000); Map<String, MockSpan> spans = new LinkedHashMap<>(); spans.put(parent.context().toSpanId(), parent); spans.put(child.context().toSpanId(), child); expect.put(parent.context().toTraceId(), spans); } Assert.assertTrue(expect.equals(tracer.finishedTraces())); } }