aboutsummaryrefslogtreecommitdiffstats
path: root/api/src/test
diff options
context:
space:
mode:
authorBogdan Drutu <bdrutu@google.com>2017-09-18 11:33:49 -0700
committerGitHub <noreply@github.com>2017-09-18 11:33:49 -0700
commit53cb6c8bec4540c66c4cbd22535797a76fef921a (patch)
treec36ab607d3685d7524e95feba0c046c8a87b7f58 /api/src/test
parentee94e55010d67c5041aa8e6011a0c1b2d813f8a5 (diff)
downloadplatform_external_opencensus-java-53cb6c8bec4540c66c4cbd22535797a76fef921a.tar.gz
platform_external_opencensus-java-53cb6c8bec4540c66c4cbd22535797a76fef921a.tar.bz2
platform_external_opencensus-java-53cb6c8bec4540c66c4cbd22535797a76fef921a.zip
Add a new SpanContextParseException and use it in BinaryFormat. (#642)
* Add a new SpanContextParseException and use it in BinaryFormat * Fix review comments.
Diffstat (limited to 'api/src/test')
-rw-r--r--api/src/test/java/io/opencensus/trace/propagation/BinaryFormatTest.java23
-rw-r--r--api/src/test/java/io/opencensus/trace/propagation/SpanContextParseExceptionTest.java42
2 files changed, 63 insertions, 2 deletions
diff --git a/api/src/test/java/io/opencensus/trace/propagation/BinaryFormatTest.java b/api/src/test/java/io/opencensus/trace/propagation/BinaryFormatTest.java
index 4cb11938..64544ffe 100644
--- a/api/src/test/java/io/opencensus/trace/propagation/BinaryFormatTest.java
+++ b/api/src/test/java/io/opencensus/trace/propagation/BinaryFormatTest.java
@@ -27,8 +27,7 @@ import org.junit.runners.JUnit4;
/** Unit tests for {@link BinaryFormat}. */
@RunWith(JUnit4.class)
public class BinaryFormatTest {
- private static final BinaryFormat binaryFormat =
- BinaryFormat.getNoopBinaryFormat();
+ private static final BinaryFormat binaryFormat = BinaryFormat.getNoopBinaryFormat();
@Test(expected = NullPointerException.class)
public void toBinaryValue_NullSpanContext() {
@@ -41,6 +40,16 @@ public class BinaryFormatTest {
}
@Test(expected = NullPointerException.class)
+ public void toByteArray_NullSpanContext() {
+ binaryFormat.toByteArray(null);
+ }
+
+ @Test
+ public void toByteArray_NotNullSpanContext() {
+ assertThat(binaryFormat.toByteArray(SpanContext.INVALID)).isEqualTo(new byte[0]);
+ }
+
+ @Test(expected = NullPointerException.class)
public void fromBinaryValue_NullInput() throws ParseException {
binaryFormat.fromBinaryValue(null);
}
@@ -49,4 +58,14 @@ public class BinaryFormatTest {
public void fromBinaryValue_NotNullInput() throws ParseException {
assertThat(binaryFormat.fromBinaryValue(new byte[0])).isEqualTo(SpanContext.INVALID);
}
+
+ @Test(expected = NullPointerException.class)
+ public void fromByteArray_NullInput() throws SpanContextParseException {
+ binaryFormat.fromByteArray(null);
+ }
+
+ @Test
+ public void fromByteArray_NotNullInput() throws SpanContextParseException {
+ assertThat(binaryFormat.fromByteArray(new byte[0])).isEqualTo(SpanContext.INVALID);
+ }
}
diff --git a/api/src/test/java/io/opencensus/trace/propagation/SpanContextParseExceptionTest.java b/api/src/test/java/io/opencensus/trace/propagation/SpanContextParseExceptionTest.java
new file mode 100644
index 00000000..92efb35d
--- /dev/null
+++ b/api/src/test/java/io/opencensus/trace/propagation/SpanContextParseExceptionTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2017, OpenCensus Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.opencensus.trace.propagation;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import java.io.IOException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Unit tests for {@link SpanContextParseException}. */
+@RunWith(JUnit4.class)
+public class SpanContextParseExceptionTest {
+
+ @Test
+ public void createWithMessage() {
+ assertThat(new SpanContextParseException("my message").getMessage()).isEqualTo("my message");
+ }
+
+ @Test
+ public void createWithMessageAndCause() {
+ IOException cause = new IOException();
+ SpanContextParseException parseException = new SpanContextParseException("my message", cause);
+ assertThat(parseException.getMessage()).isEqualTo("my message");
+ assertThat(parseException.getCause()).isEqualTo(cause);
+ }
+}