aboutsummaryrefslogtreecommitdiffstats
path: root/api/src/test
diff options
context:
space:
mode:
authorKristen Kozak <sebright@google.com>2017-10-31 18:38:19 -0700
committerKristen Kozak <sebright@google.com>2017-10-31 18:41:29 -0700
commitba5c5b1796d6dfd8ef09573dbcee8145dee5a872 (patch)
treef092b972b75e52555d47b06479355c3af02bc90f /api/src/test
parentff43823476013f2131bd82bf7d566869afd12d17 (diff)
downloadplatform_external_opencensus-java-ba5c5b1796d6dfd8ef09573dbcee8145dee5a872.tar.gz
platform_external_opencensus-java-ba5c5b1796d6dfd8ef09573dbcee8145dee5a872.tar.bz2
platform_external_opencensus-java-ba5c5b1796d6dfd8ef09573dbcee8145dee5a872.zip
Make TagContextBinarySerializer.toByteArray throw a checked exception.
The first version of the implementation will throw TagContextSerializationException when the serialized TagContext would be larger than 8192 bytes.
Diffstat (limited to 'api/src/test')
-rw-r--r--api/src/test/java/io/opencensus/tags/NoopTagsTest.java7
-rw-r--r--api/src/test/java/io/opencensus/tags/propagation/TagContextSerializationExceptionTest.java44
2 files changed, 49 insertions, 2 deletions
diff --git a/api/src/test/java/io/opencensus/tags/NoopTagsTest.java b/api/src/test/java/io/opencensus/tags/NoopTagsTest.java
index d39c5d7f..551229a7 100644
--- a/api/src/test/java/io/opencensus/tags/NoopTagsTest.java
+++ b/api/src/test/java/io/opencensus/tags/NoopTagsTest.java
@@ -22,6 +22,7 @@ import com.google.common.collect.Lists;
import io.opencensus.internal.NoopScope;
import io.opencensus.tags.propagation.TagContextBinarySerializer;
import io.opencensus.tags.propagation.TagContextParseException;
+import io.opencensus.tags.propagation.TagContextSerializationException;
import java.util.Arrays;
import java.util.Iterator;
import org.junit.Rule;
@@ -129,7 +130,8 @@ public final class NoopTagsTest {
}
@Test
- public void noopTagContextBinarySerializer() throws TagContextParseException {
+ public void noopTagContextBinarySerializer()
+ throws TagContextParseException, TagContextSerializationException {
assertThat(NoopTags.getNoopTagContextBinarySerializer().toByteArray(TAG_CONTEXT))
.isEqualTo(new byte[0]);
assertThat(NoopTags.getNoopTagContextBinarySerializer().fromByteArray(new byte[5]))
@@ -137,7 +139,8 @@ public final class NoopTagsTest {
}
@Test
- public void noopTagContextBinarySerializer_ToByteArray_DisallowsNull() {
+ public void noopTagContextBinarySerializer_ToByteArray_DisallowsNull()
+ throws TagContextSerializationException {
TagContextBinarySerializer noopSerializer = NoopTags.getNoopTagContextBinarySerializer();
thrown.expect(NullPointerException.class);
noopSerializer.toByteArray(null);
diff --git a/api/src/test/java/io/opencensus/tags/propagation/TagContextSerializationExceptionTest.java b/api/src/test/java/io/opencensus/tags/propagation/TagContextSerializationExceptionTest.java
new file mode 100644
index 00000000..54e9fab6
--- /dev/null
+++ b/api/src/test/java/io/opencensus/tags/propagation/TagContextSerializationExceptionTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.tags.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 TagContextSerializationException}. */
+@RunWith(JUnit4.class)
+public final class TagContextSerializationExceptionTest {
+
+ @Test
+ public void createWithMessage() {
+ assertThat(new TagContextSerializationException("my message").getMessage())
+ .isEqualTo("my message");
+ }
+
+ @Test
+ public void createWithMessageAndCause() {
+ IOException cause = new IOException();
+ TagContextSerializationException exception =
+ new TagContextSerializationException("my message", cause);
+ assertThat(exception.getMessage()).isEqualTo("my message");
+ assertThat(exception.getCause()).isEqualTo(cause);
+ }
+}