• 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 static com.google.common.truth.Truth.assertThat;
20 
21 import com.google.common.testing.EqualsTester;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.junit.runners.JUnit4;
25 
26 /** Unit tests for {@link EndSpanOptions}. */
27 @RunWith(JUnit4.class)
28 public class EndSpanOptionsTest {
29   @Test
endSpanOptions_DefaultOptions()30   public void endSpanOptions_DefaultOptions() {
31     assertThat(EndSpanOptions.DEFAULT.getStatus()).isNull();
32     assertThat(EndSpanOptions.DEFAULT.getSampleToLocalSpanStore()).isFalse();
33   }
34 
35   @Test
setStatus_Ok()36   public void setStatus_Ok() {
37     EndSpanOptions endSpanOptions = EndSpanOptions.builder().setStatus(Status.OK).build();
38     assertThat(endSpanOptions.getStatus()).isEqualTo(Status.OK);
39   }
40 
41   @Test
setStatus_Error()42   public void setStatus_Error() {
43     EndSpanOptions endSpanOptions =
44         EndSpanOptions.builder()
45             .setStatus(Status.CANCELLED.withDescription("ThisIsAnError"))
46             .build();
47     assertThat(endSpanOptions.getStatus())
48         .isEqualTo(Status.CANCELLED.withDescription("ThisIsAnError"));
49   }
50 
51   @Test
setSampleToLocalSpanStore()52   public void setSampleToLocalSpanStore() {
53     EndSpanOptions endSpanOptions =
54         EndSpanOptions.builder().setSampleToLocalSpanStore(true).build();
55     assertThat(endSpanOptions.getSampleToLocalSpanStore()).isTrue();
56   }
57 
58   @Test
endSpanOptions_EqualsAndHashCode()59   public void endSpanOptions_EqualsAndHashCode() {
60     EqualsTester tester = new EqualsTester();
61     tester.addEqualityGroup(
62         EndSpanOptions.builder()
63             .setStatus(Status.CANCELLED.withDescription("ThisIsAnError"))
64             .build(),
65         EndSpanOptions.builder()
66             .setStatus(Status.CANCELLED.withDescription("ThisIsAnError"))
67             .build());
68     tester.addEqualityGroup(EndSpanOptions.builder().build(), EndSpanOptions.DEFAULT);
69     tester.testEquals();
70   }
71 
72   @Test
endSpanOptions_ToString()73   public void endSpanOptions_ToString() {
74     EndSpanOptions endSpanOptions =
75         EndSpanOptions.builder()
76             .setStatus(Status.CANCELLED.withDescription("ThisIsAnError"))
77             .build();
78     assertThat(endSpanOptions.toString()).contains("ThisIsAnError");
79   }
80 }
81