Home | History | Annotate | Download | only in propagation
      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.propagation;
     18 
     19 import static com.google.common.truth.Truth.assertThat;
     20 
     21 import io.opencensus.trace.SpanContext;
     22 import java.text.ParseException;
     23 import org.junit.Test;
     24 import org.junit.runner.RunWith;
     25 import org.junit.runners.JUnit4;
     26 
     27 /** Unit tests for {@link BinaryFormat}. */
     28 @RunWith(JUnit4.class)
     29 public class BinaryFormatTest {
     30   private static final BinaryFormat binaryFormat = BinaryFormat.getNoopBinaryFormat();
     31 
     32   @Test(expected = NullPointerException.class)
     33   public void toBinaryValue_NullSpanContext() {
     34     binaryFormat.toBinaryValue(null);
     35   }
     36 
     37   @Test
     38   public void toBinaryValue_NotNullSpanContext() {
     39     assertThat(binaryFormat.toBinaryValue(SpanContext.INVALID)).isEqualTo(new byte[0]);
     40   }
     41 
     42   @Test(expected = NullPointerException.class)
     43   public void toByteArray_NullSpanContext() {
     44     binaryFormat.toByteArray(null);
     45   }
     46 
     47   @Test
     48   public void toByteArray_NotNullSpanContext() {
     49     assertThat(binaryFormat.toByteArray(SpanContext.INVALID)).isEqualTo(new byte[0]);
     50   }
     51 
     52   @Test(expected = NullPointerException.class)
     53   public void fromBinaryValue_NullInput() throws ParseException {
     54     binaryFormat.fromBinaryValue(null);
     55   }
     56 
     57   @Test
     58   public void fromBinaryValue_NotNullInput() throws ParseException {
     59     assertThat(binaryFormat.fromBinaryValue(new byte[0])).isEqualTo(SpanContext.INVALID);
     60   }
     61 
     62   @Test(expected = NullPointerException.class)
     63   public void fromByteArray_NullInput() throws SpanContextParseException {
     64     binaryFormat.fromByteArray(null);
     65   }
     66 
     67   @Test
     68   public void fromByteArray_NotNullInput() throws SpanContextParseException {
     69     assertThat(binaryFormat.fromByteArray(new byte[0])).isEqualTo(SpanContext.INVALID);
     70   }
     71 }
     72