1 /*
2  * Copyright 2018, 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.common;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import io.opencensus.common.ServerStatsFieldEnums.Id;
22 import io.opencensus.common.ServerStatsFieldEnums.Size;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.junit.runners.JUnit4;
26 
27 /** Unit tests for {@link ServerStatsFieldEnums}. */
28 @RunWith(JUnit4.class)
29 public class ServerStatsFieldEnumsTest {
30 
31   @Test
enumIdValueOfTest()32   public void enumIdValueOfTest() {
33     assertThat(Id.valueOf(0)).isEqualTo(Id.SERVER_STATS_LB_LATENCY_ID);
34     assertThat(Id.valueOf(1)).isEqualTo(Id.SERVER_STATS_SERVICE_LATENCY_ID);
35     assertThat(Id.valueOf(2)).isEqualTo(Id.SERVER_STATS_TRACE_OPTION_ID);
36   }
37 
38   @Test
enumIdInvalidValueOfTest()39   public void enumIdInvalidValueOfTest() {
40     assertThat(Id.valueOf(-1)).isNull();
41     assertThat(Id.valueOf(Id.values().length)).isNull();
42     assertThat(Id.valueOf(Id.values().length + 1)).isNull();
43   }
44 
45   @Test
enumSizeValueTest()46   public void enumSizeValueTest() {
47     assertThat(Size.SERVER_STATS_LB_LATENCY_SIZE.value()).isEqualTo(8);
48     assertThat(Size.SERVER_STATS_SERVICE_LATENCY_SIZE.value()).isEqualTo(8);
49     assertThat(Size.SERVER_STATS_TRACE_OPTION_SIZE.value()).isEqualTo(1);
50   }
51 
52   @Test
totalSizeTest()53   public void totalSizeTest() {
54     assertThat(ServerStatsFieldEnums.getTotalSize()).isEqualTo(20);
55   }
56 }
57