diff --git a/opentracing-noop/src/main/java/io/opentracing/noop/NoopScopeManager.java b/opentracing-noop/src/main/java/io/opentracing/noop/NoopScopeManager.java index 063cb61b..3f73b3a4 100644 --- a/opentracing-noop/src/main/java/io/opentracing/noop/NoopScopeManager.java +++ b/opentracing-noop/src/main/java/io/opentracing/noop/NoopScopeManager.java @@ -36,7 +36,7 @@ public Scope activate(Span span, boolean finishOnClose) { @Override public Scope active() { - return null; + return NoopScope.INSTANCE; } static class NoopScopeImpl implements NoopScopeManager.NoopScope { diff --git a/opentracing-noop/src/main/java/io/opentracing/noop/NoopTracer.java b/opentracing-noop/src/main/java/io/opentracing/noop/NoopTracer.java index 75770b85..9adf32c1 100644 --- a/opentracing-noop/src/main/java/io/opentracing/noop/NoopTracer.java +++ b/opentracing-noop/src/main/java/io/opentracing/noop/NoopTracer.java @@ -32,7 +32,7 @@ public ScopeManager scopeManager() { @Override public Span activeSpan() { - return null; + return NoopSpanImpl.INSTANCE; } @Override diff --git a/opentracing-noop/src/test/java/io/opentracing/noop/NoopScopeManagerTest.java b/opentracing-noop/src/test/java/io/opentracing/noop/NoopScopeManagerTest.java new file mode 100644 index 00000000..117027f7 --- /dev/null +++ b/opentracing-noop/src/test/java/io/opentracing/noop/NoopScopeManagerTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2016-2018 The OpenTracing Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package io.opentracing.noop; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import io.opentracing.Scope; + +public class NoopScopeManagerTest { + + @Test + public void activeValueToleratesUseTest() { + try{ + final Scope active = NoopScopeManager.INSTANCE.active(); + assertNotNull(active); + active.close(); + } catch (final NullPointerException e) { + fail("NoopScopeManagerImpl.active() should return a usable scope"); + } + } +} \ No newline at end of file diff --git a/opentracing-noop/src/test/java/io/opentracing/noop/NoopTracerTest.java b/opentracing-noop/src/test/java/io/opentracing/noop/NoopTracerTest.java new file mode 100644 index 00000000..cba9d779 --- /dev/null +++ b/opentracing-noop/src/test/java/io/opentracing/noop/NoopTracerTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2016-2018 The OpenTracing Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package io.opentracing.noop; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import io.opentracing.Span; +import io.opentracing.tag.Tags; + +public class NoopTracerTest { + + @Test + public void activeSpanValueToleratesUseTest() { + try { + final Span activeSpan = NoopTracerImpl.INSTANCE.activeSpan(); + assertNotNull(activeSpan); + Tags.ERROR.set(activeSpan, true); + } catch (final NullPointerException e) { + fail("NoopTracer.activeSpan() should return a usable span"); + } + } +} \ No newline at end of file