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 static com.google.common.truth.Truth.assertThat; 20 21 import java.util.HashMap; 22 import java.util.Map; 23 import org.junit.Test; 24 import org.junit.runner.RunWith; 25 import org.junit.runners.JUnit4; 26 27 /** Unit tests for {@link BlankSpan}. */ 28 @RunWith(JUnit4.class) 29 public class BlankSpanTest { 30 @Test hasInvalidContextAndDefaultSpanOptions()31 public void hasInvalidContextAndDefaultSpanOptions() { 32 assertThat(BlankSpan.INSTANCE.getContext()).isEqualTo(SpanContext.INVALID); 33 assertThat(BlankSpan.INSTANCE.getOptions().isEmpty()).isTrue(); 34 } 35 36 @Test doNotCrash()37 public void doNotCrash() { 38 Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>(); 39 attributes.put( 40 "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue")); 41 Map<String, AttributeValue> multipleAttributes = new HashMap<String, AttributeValue>(); 42 multipleAttributes.put( 43 "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue")); 44 multipleAttributes.put("MyBooleanAttributeKey", AttributeValue.booleanAttributeValue(true)); 45 multipleAttributes.put("MyLongAttributeKey", AttributeValue.longAttributeValue(123)); 46 // Tests only that all the methods are not crashing/throwing errors. 47 BlankSpan.INSTANCE.putAttribute( 48 "MyStringAttributeKey2", AttributeValue.stringAttributeValue("MyStringAttributeValue2")); 49 BlankSpan.INSTANCE.addAttributes(attributes); 50 BlankSpan.INSTANCE.addAttributes(multipleAttributes); 51 BlankSpan.INSTANCE.addAnnotation("MyAnnotation"); 52 BlankSpan.INSTANCE.addAnnotation("MyAnnotation", attributes); 53 BlankSpan.INSTANCE.addAnnotation("MyAnnotation", multipleAttributes); 54 BlankSpan.INSTANCE.addAnnotation(Annotation.fromDescription("MyAnnotation")); 55 BlankSpan.INSTANCE.addNetworkEvent(NetworkEvent.builder(NetworkEvent.Type.SENT, 1L).build()); 56 BlankSpan.INSTANCE.addMessageEvent(MessageEvent.builder(MessageEvent.Type.SENT, 1L).build()); 57 BlankSpan.INSTANCE.addLink( 58 Link.fromSpanContext(SpanContext.INVALID, Link.Type.CHILD_LINKED_SPAN)); 59 BlankSpan.INSTANCE.setStatus(Status.OK); 60 BlankSpan.INSTANCE.end(EndSpanOptions.DEFAULT); 61 BlankSpan.INSTANCE.end(); 62 } 63 64 @Test blankSpan_ToString()65 public void blankSpan_ToString() { 66 assertThat(BlankSpan.INSTANCE.toString()).isEqualTo("BlankSpan"); 67 } 68 } 69