• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017, OpenCensus Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package io.opencensus.trace;
18 
19 import io.opencensus.internal.Utils;
20 import java.util.EnumSet;
21 import java.util.Map;
22 import javax.annotation.Nullable;
23 
24 /**
25  * Class to be used in tests where an implementation for the Span is needed.
26  *
27  * <p>Not final to allow Mockito to "spy" this class.
28  */
29 public class NoopSpan extends Span {
30 
31   /** Creates a new {@code NoopSpan}. */
NoopSpan(SpanContext context, @Nullable EnumSet<Options> options)32   public NoopSpan(SpanContext context, @Nullable EnumSet<Options> options) {
33     super(Utils.checkNotNull(context, "context"), options);
34   }
35 
36   @Override
putAttributes(Map<String, AttributeValue> attributes)37   public void putAttributes(Map<String, AttributeValue> attributes) {
38     Utils.checkNotNull(attributes, "attributes");
39   }
40 
41   @Override
addAnnotation(String description, Map<String, AttributeValue> attributes)42   public void addAnnotation(String description, Map<String, AttributeValue> attributes) {
43     Utils.checkNotNull(description, "description");
44     Utils.checkNotNull(attributes, "attributes");
45   }
46 
47   @Override
addAnnotation(Annotation annotation)48   public void addAnnotation(Annotation annotation) {
49     Utils.checkNotNull(annotation, "annotation");
50   }
51 
52   @Override
addNetworkEvent(NetworkEvent networkEvent)53   public void addNetworkEvent(NetworkEvent networkEvent) {}
54 
55   @Override
addMessageEvent(MessageEvent messageEvent)56   public void addMessageEvent(MessageEvent messageEvent) {
57     Utils.checkNotNull(messageEvent, "messageEvent");
58   }
59 
60   @Override
addLink(Link link)61   public void addLink(Link link) {
62     Utils.checkNotNull(link, "link");
63   }
64 
65   @Override
end(EndSpanOptions options)66   public void end(EndSpanOptions options) {
67     Utils.checkNotNull(options, "options");
68   }
69 }
70