diff --git a/opentracing-mock/src/main/java/io/opentracing/mock/MockTracer.java b/opentracing-mock/src/main/java/io/opentracing/mock/MockTracer.java index 042d20ad..f4225484 100644 --- a/opentracing-mock/src/main/java/io/opentracing/mock/MockTracer.java +++ b/opentracing-mock/src/main/java/io/opentracing/mock/MockTracer.java @@ -13,23 +13,23 @@ */ package io.opentracing.mock; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import io.opentracing.ActiveSpan; import io.opentracing.ActiveSpanSource; import io.opentracing.BaseSpan; -import io.opentracing.noop.NoopActiveSpanSource; import io.opentracing.References; import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.Tracer; +import io.opentracing.noop.NoopActiveSpanSource; import io.opentracing.propagation.Format; import io.opentracing.propagation.TextMap; import io.opentracing.util.ThreadLocalActiveSpanSource; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - /** * MockTracer makes it easy to test the semantics of OpenTracing instrumentation. * @@ -39,16 +39,16 @@ * The MockTracerTest has simple usage examples. */ public class MockTracer implements Tracer { - private List finishedSpans = new ArrayList<>(); + private final List finishedSpans = new ArrayList<>(); private final Propagator propagator; - private ActiveSpanSource spanSource; + private final ActiveSpanSource spanSource; public MockTracer() { - this(new ThreadLocalActiveSpanSource(), Propagator.PRINTER); + this(new ThreadLocalActiveSpanSource(), Propagator.TEXT_MAP); } public MockTracer(ActiveSpanSource spanSource) { - this(spanSource, Propagator.PRINTER); + this(spanSource, Propagator.TEXT_MAP); } public MockTracer(ActiveSpanSource spanSource, Propagator propagator) { diff --git a/opentracing-mock/src/test/java/io/opentracing/mock/MockTracerTest.java b/opentracing-mock/src/test/java/io/opentracing/mock/MockTracerTest.java index 2f2a410b..a9243cb5 100644 --- a/opentracing-mock/src/test/java/io/opentracing/mock/MockTracerTest.java +++ b/opentracing-mock/src/test/java/io/opentracing/mock/MockTracerTest.java @@ -14,20 +14,24 @@ package io.opentracing.mock; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import io.opentracing.References; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; + +import io.opentracing.ActiveSpan; import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.Tracer; import io.opentracing.propagation.Format; import io.opentracing.propagation.TextMapExtractAdapter; import io.opentracing.propagation.TextMapInjectAdapter; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.junit.Assert; -import org.junit.Test; public class MockTracerTest { @Test @@ -277,6 +281,18 @@ public void testNonStandardReference() { assertEquals(parent.context().spanId(), nextSpan.parentId()); assertEquals(1, nextSpan.references().size()); - assertEquals(nextSpan.references().get(0), new MockSpan.Reference(parent.context(), "a_reference")); + assertEquals(nextSpan.references().get(0), + new MockSpan.Reference(parent.context(), "a_reference")); + } + + @Test + public void testDefaultConstructor() { + MockTracer mockTracer = new MockTracer(); + ActiveSpan activeSpan = mockTracer.buildSpan("foo").startActive(); + assertEquals(activeSpan, mockTracer.activeSpan()); + + Map propag = new HashMap<>(); + mockTracer.inject(activeSpan.context(), Format.Builtin.TEXT_MAP, new TextMapInjectAdapter(propag)); + assertFalse(propag.isEmpty()); } }