aboutsummaryrefslogtreecommitdiffstats
path: root/api/src/test
diff options
context:
space:
mode:
authorKristen Kozak <sebright@google.com>2017-10-17 13:23:24 -0700
committerKristen Kozak <sebright@google.com>2017-10-25 18:39:28 -0700
commit2536bd35d6b24fab12695ee973b8a1fbba949b3a (patch)
tree2baa9688ba7b1f9d6bd3394df3fd010269b2bade /api/src/test
parent89f06e756efed61b9307f51af760d6a4b291572a (diff)
downloadplatform_external_opencensus-java-2536bd35d6b24fab12695ee973b8a1fbba949b3a.tar.gz
platform_external_opencensus-java-2536bd35d6b24fab12695ee973b8a1fbba949b3a.tar.bz2
platform_external_opencensus-java-2536bd35d6b24fab12695ee973b8a1fbba949b3a.zip
Remove support for multiple tag types.
This commit removes the class hierarchies for TagKey, TagValue, and Tag. The three classes are now concrete AutoValue classes that use Strings for keys and values. The serialization format isn't affected, because it already only supported string tags.
Diffstat (limited to 'api/src/test')
-rw-r--r--api/src/test/java/io/opencensus/stats/NoopStatsTest.java8
-rw-r--r--api/src/test/java/io/opencensus/stats/NoopViewManagerTest.java4
-rw-r--r--api/src/test/java/io/opencensus/stats/ViewDataTest.java19
-rw-r--r--api/src/test/java/io/opencensus/stats/ViewTest.java10
-rw-r--r--api/src/test/java/io/opencensus/tags/InternalUtilsTest.java5
-rw-r--r--api/src/test/java/io/opencensus/tags/NoopTagsTest.java57
-rw-r--r--api/src/test/java/io/opencensus/tags/TagContextTest.java7
-rw-r--r--api/src/test/java/io/opencensus/tags/TagKeyTest.java106
-rw-r--r--api/src/test/java/io/opencensus/tags/TagTest.java124
-rw-r--r--api/src/test/java/io/opencensus/tags/TagValueTest.java109
10 files changed, 57 insertions, 392 deletions
diff --git a/api/src/test/java/io/opencensus/stats/NoopStatsTest.java b/api/src/test/java/io/opencensus/stats/NoopStatsTest.java
index 9639ab94..dfd1136b 100644
--- a/api/src/test/java/io/opencensus/stats/NoopStatsTest.java
+++ b/api/src/test/java/io/opencensus/stats/NoopStatsTest.java
@@ -20,10 +20,9 @@ import static com.google.common.truth.Truth.assertThat;
import io.opencensus.stats.Measure.MeasureDouble;
import io.opencensus.tags.Tag;
-import io.opencensus.tags.Tag.TagString;
import io.opencensus.tags.TagContext;
-import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValue.TagValueString;
+import io.opencensus.tags.TagKey;
+import io.opencensus.tags.TagValue;
import java.util.Collections;
import java.util.Iterator;
import org.junit.Rule;
@@ -38,8 +37,7 @@ import org.junit.runners.JUnit4;
*/
@RunWith(JUnit4.class)
public final class NoopStatsTest {
- private static final TagString TAG =
- TagString.create(TagKeyString.create("key"), TagValueString.create("value"));
+ private static final Tag TAG = Tag.create(TagKey.create("key"), TagValue.create("value"));
private static final MeasureDouble MEASURE =
Measure.MeasureDouble.create("my measure", "description", "s");
diff --git a/api/src/test/java/io/opencensus/stats/NoopViewManagerTest.java b/api/src/test/java/io/opencensus/stats/NoopViewManagerTest.java
index 01196e1d..b70e49cc 100644
--- a/api/src/test/java/io/opencensus/stats/NoopViewManagerTest.java
+++ b/api/src/test/java/io/opencensus/stats/NoopViewManagerTest.java
@@ -27,7 +27,7 @@ import io.opencensus.stats.View.AggregationWindow.Interval;
import io.opencensus.stats.View.Name;
import io.opencensus.stats.ViewData.AggregationWindowData.CumulativeData;
import io.opencensus.stats.ViewData.AggregationWindowData.IntervalData;
-import io.opencensus.tags.TagKey.TagKeyString;
+import io.opencensus.tags.TagKey;
import java.util.Arrays;
import org.junit.Rule;
import org.junit.Test;
@@ -40,7 +40,7 @@ import org.junit.runners.JUnit4;
public final class NoopViewManagerTest {
private static final MeasureDouble MEASURE =
Measure.MeasureDouble.create("my measure", "description", "s");
- private static final TagKeyString KEY = TagKeyString.create("KEY");
+ private static final TagKey KEY = TagKey.create("KEY");
private static final Name VIEW_NAME = Name.create("my view");
private static final String VIEW_DESCRIPTION = "view description";
private static final Sum AGGREGATION = Sum.create();
diff --git a/api/src/test/java/io/opencensus/stats/ViewDataTest.java b/api/src/test/java/io/opencensus/stats/ViewDataTest.java
index 43cc956a..69313295 100644
--- a/api/src/test/java/io/opencensus/stats/ViewDataTest.java
+++ b/api/src/test/java/io/opencensus/stats/ViewDataTest.java
@@ -33,9 +33,8 @@ import io.opencensus.stats.View.AggregationWindow.Interval;
import io.opencensus.stats.ViewData.AggregationWindowData;
import io.opencensus.stats.ViewData.AggregationWindowData.CumulativeData;
import io.opencensus.stats.ViewData.AggregationWindowData.IntervalData;
-import io.opencensus.tags.TagKey.TagKeyString;
+import io.opencensus.tags.TagKey;
import io.opencensus.tags.TagValue;
-import io.opencensus.tags.TagValue.TagValueString;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -184,15 +183,15 @@ public final class ViewDataTest {
}
// tag keys
- private static final TagKeyString K1 = TagKeyString.create("k1");
- private static final TagKeyString K2 = TagKeyString.create("k2");
- private final List<TagKeyString> tagKeys = Arrays.asList(K1, K2);
+ private static final TagKey K1 = TagKey.create("k1");
+ private static final TagKey K2 = TagKey.create("k2");
+ private final List<TagKey> tagKeys = Arrays.asList(K1, K2);
// tag values
- private static final TagValueString V1 = TagValueString.create("v1");
- private static final TagValueString V2 = TagValueString.create("v2");
- private static final TagValueString V10 = TagValueString.create("v10");
- private static final TagValueString V20 = TagValueString.create("v20");
+ private static final TagValue V1 = TagValue.create("v1");
+ private static final TagValue V2 = TagValue.create("v2");
+ private static final TagValue V10 = TagValue.create("v10");
+ private static final TagValue V20 = TagValue.create("v20");
private static final AggregationWindow CUMULATIVE = Cumulative.create();
private static final AggregationWindow INTERVAL_HOUR = Interval.create(Duration.create(3600, 0));
@@ -202,7 +201,7 @@ public final class ViewDataTest {
private static final Aggregation DISTRIBUTION = Distribution.create(BUCKET_BOUNDARIES);
- private static final ImmutableMap<List<TagValueString>, DistributionData> ENTRIES =
+ private static final ImmutableMap<List<TagValue>, DistributionData> ENTRIES =
ImmutableMap.of(
Arrays.asList(V1, V2),
DistributionData.create(1, 1, 1, 1, 0, new long[]{0, 1, 0}),
diff --git a/api/src/test/java/io/opencensus/stats/ViewTest.java b/api/src/test/java/io/opencensus/stats/ViewTest.java
index 99215352..81584ef9 100644
--- a/api/src/test/java/io/opencensus/stats/ViewTest.java
+++ b/api/src/test/java/io/opencensus/stats/ViewTest.java
@@ -24,7 +24,7 @@ import io.opencensus.common.Duration;
import io.opencensus.stats.Aggregation.Mean;
import io.opencensus.stats.View.AggregationWindow.Cumulative;
import io.opencensus.stats.View.AggregationWindow.Interval;
-import io.opencensus.tags.TagKey.TagKeyString;
+import io.opencensus.tags.TagKey;
import java.util.Arrays;
import java.util.List;
import org.junit.Rule;
@@ -100,7 +100,7 @@ public final class ViewTest {
DESCRIPTION,
MEASURE,
MEAN,
- Arrays.asList(TagKeyString.create("duplicate"), TagKeyString.create("duplicate")),
+ Arrays.asList(TagKey.create("duplicate"), TagKey.create("duplicate")),
Cumulative.create());
}
@@ -152,9 +152,9 @@ public final class ViewTest {
private static final String DESCRIPTION = "test-view-name description";
private static final Measure MEASURE = Measure.MeasureDouble.create(
"measure", "measure description", "1");
- private static final TagKeyString FOO = TagKeyString.create("foo");
- private static final TagKeyString BAR = TagKeyString.create("bar");
- private static final List<TagKeyString> keys = ImmutableList.of(FOO, BAR);
+ private static final TagKey FOO = TagKey.create("foo");
+ private static final TagKey BAR = TagKey.create("bar");
+ private static final List<TagKey> keys = ImmutableList.of(FOO, BAR);
private static final Mean MEAN = Mean.create();
private static final Duration MINUTE = Duration.create(60, 0);
private static final Duration TWO_MINUTES = Duration.create(120, 0);
diff --git a/api/src/test/java/io/opencensus/tags/InternalUtilsTest.java b/api/src/test/java/io/opencensus/tags/InternalUtilsTest.java
index ba69ef88..db5a2d9d 100644
--- a/api/src/test/java/io/opencensus/tags/InternalUtilsTest.java
+++ b/api/src/test/java/io/opencensus/tags/InternalUtilsTest.java
@@ -19,9 +19,6 @@ package io.opencensus.tags;
import static com.google.common.truth.Truth.assertThat;
import com.google.common.collect.Lists;
-import io.opencensus.tags.Tag.TagString;
-import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValue.TagValueString;
import java.util.Iterator;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -35,7 +32,7 @@ public final class InternalUtilsTest {
public void getTags() {
final Iterator<Tag> iterator =
Lists.<Tag>newArrayList(
- TagString.create(TagKeyString.create("k"), TagValueString.create("v")))
+ Tag.create(TagKey.create("k"), TagValue.create("v")))
.iterator();
TagContext ctx =
new TagContext() {
diff --git a/api/src/test/java/io/opencensus/tags/NoopTagsTest.java b/api/src/test/java/io/opencensus/tags/NoopTagsTest.java
index 2ee1c8cc..d39c5d7f 100644
--- a/api/src/test/java/io/opencensus/tags/NoopTagsTest.java
+++ b/api/src/test/java/io/opencensus/tags/NoopTagsTest.java
@@ -20,13 +20,6 @@ import static com.google.common.truth.Truth.assertThat;
import com.google.common.collect.Lists;
import io.opencensus.internal.NoopScope;
-import io.opencensus.tags.Tag.TagString;
-import io.opencensus.tags.TagKey.TagKeyBoolean;
-import io.opencensus.tags.TagKey.TagKeyLong;
-import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValue.TagValueBoolean;
-import io.opencensus.tags.TagValue.TagValueLong;
-import io.opencensus.tags.TagValue.TagValueString;
import io.opencensus.tags.propagation.TagContextBinarySerializer;
import io.opencensus.tags.propagation.TagContextParseException;
import java.util.Arrays;
@@ -40,19 +33,15 @@ import org.junit.runners.JUnit4;
/** Unit tests for {@link NoopTags}. */
@RunWith(JUnit4.class)
public final class NoopTagsTest {
- private static final TagKeyString KEY_STRING = TagKeyString.create("key");
- private static final TagValueString VALUE_STRING = TagValueString.create("value");
- private static final TagKeyLong KEY_LONG = TagKeyLong.create("key");
- private static final TagValueLong VALUE_LONG = TagValueLong.create(1L);
- private static final TagKeyBoolean KEY_BOOLEAN = TagKeyBoolean.create("key");
- private static final TagValueBoolean VALUE_BOOLEAN = TagValueBoolean.create(true);
+ private static final TagKey KEY = TagKey.create("key");
+ private static final TagValue VALUE = TagValue.create("value");
private static final TagContext TAG_CONTEXT =
new TagContext() {
@Override
protected Iterator<Tag> getIterator() {
- return Arrays.<Tag>asList(TagString.create(KEY_STRING, VALUE_STRING)).iterator();
+ return Arrays.<Tag>asList(Tag.create(KEY, VALUE)).iterator();
}
};
@@ -100,53 +89,25 @@ public final class NoopTagsTest {
@Test
public void noopTagContextBuilder() {
assertThat(NoopTags.getNoopTagContextBuilder().build()).isSameAs(NoopTags.getNoopTagContext());
- assertThat(NoopTags.getNoopTagContextBuilder().put(KEY_STRING, VALUE_STRING).build())
+ assertThat(NoopTags.getNoopTagContextBuilder().put(KEY, VALUE).build())
.isSameAs(NoopTags.getNoopTagContext());
assertThat(NoopTags.getNoopTagContextBuilder().buildScoped()).isSameAs(NoopScope.getInstance());
- assertThat(NoopTags.getNoopTagContextBuilder().put(KEY_STRING, VALUE_STRING).buildScoped())
+ assertThat(NoopTags.getNoopTagContextBuilder().put(KEY, VALUE).buildScoped())
.isSameAs(NoopScope.getInstance());
}
@Test
- public void noopTagContextBuilder_PutString_DisallowsNullKey() {
+ public void noopTagContextBuilder_Put_DisallowsNullKey() {
TagContextBuilder noopBuilder = NoopTags.getNoopTagContextBuilder();
thrown.expect(NullPointerException.class);
- noopBuilder.put(null, VALUE_STRING);
+ noopBuilder.put(null, VALUE);
}
@Test
- public void noopTagContextBuilder_PutString_DisallowsNullValue() {
+ public void noopTagContextBuilder_Put_DisallowsNullValue() {
TagContextBuilder noopBuilder = NoopTags.getNoopTagContextBuilder();
thrown.expect(NullPointerException.class);
- noopBuilder.put(KEY_STRING, null);
- }
-
- @Test
- public void noopTagContextBuilder_PutLong_DisallowsNullKey() {
- TagContextBuilder noopBuilder = NoopTags.getNoopTagContextBuilder();
- thrown.expect(NullPointerException.class);
- noopBuilder.put(null, VALUE_LONG);
- }
-
- @Test
- public void noopTagContextBuilder_PutLong_DisallowsNullValue() {
- TagContextBuilder noopBuilder = NoopTags.getNoopTagContextBuilder();
- thrown.expect(NullPointerException.class);
- noopBuilder.put(KEY_LONG, null);
- }
-
- @Test
- public void noopTagContextBuilder_PutBoolean_DisallowsNullKey() {
- TagContextBuilder noopBuilder = NoopTags.getNoopTagContextBuilder();
- thrown.expect(NullPointerException.class);
- noopBuilder.put(null, VALUE_BOOLEAN);
- }
-
- @Test
- public void noopTagContextBuilder_PutBoolean_DisallowsNullValue() {
- TagContextBuilder noopBuilder = NoopTags.getNoopTagContextBuilder();
- thrown.expect(NullPointerException.class);
- noopBuilder.put(KEY_BOOLEAN, null);
+ noopBuilder.put(KEY, null);
}
@Test
diff --git a/api/src/test/java/io/opencensus/tags/TagContextTest.java b/api/src/test/java/io/opencensus/tags/TagContextTest.java
index d6adfe12..0e229323 100644
--- a/api/src/test/java/io/opencensus/tags/TagContextTest.java
+++ b/api/src/test/java/io/opencensus/tags/TagContextTest.java
@@ -20,9 +20,6 @@ import static com.google.common.truth.Truth.assertThat;
import com.google.common.collect.Lists;
import com.google.common.testing.EqualsTester;
-import io.opencensus.tags.Tag.TagString;
-import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValue.TagValueString;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -34,9 +31,9 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public final class TagContextTest {
private static final Tag TAG1 =
- TagString.create(TagKeyString.create("key"), TagValueString.create("val"));
+ Tag.create(TagKey.create("key"), TagValue.create("val"));
private static final Tag TAG2 =
- TagString.create(TagKeyString.create("key2"), TagValueString.create("val"));
+ Tag.create(TagKey.create("key2"), TagValue.create("val"));
@Test
public void equals_IgnoresTagOrderAndTagContextClass() {
diff --git a/api/src/test/java/io/opencensus/tags/TagKeyTest.java b/api/src/test/java/io/opencensus/tags/TagKeyTest.java
index 5b70ba7a..122c5baa 100644
--- a/api/src/test/java/io/opencensus/tags/TagKeyTest.java
+++ b/api/src/test/java/io/opencensus/tags/TagKeyTest.java
@@ -19,11 +19,6 @@ package io.opencensus.tags;
import static com.google.common.truth.Truth.assertThat;
import com.google.common.testing.EqualsTester;
-import io.opencensus.common.Function;
-import io.opencensus.common.Functions;
-import io.opencensus.tags.TagKey.TagKeyBoolean;
-import io.opencensus.tags.TagKey.TagKeyLong;
-import io.opencensus.tags.TagKey.TagKeyString;
import java.util.Arrays;
import org.junit.Rule;
import org.junit.Test;
@@ -39,118 +34,35 @@ public final class TagKeyTest {
@Test
public void testGetName() {
- assertThat(TagKeyString.create("foo").getName()).isEqualTo("foo");
+ assertThat(TagKey.create("foo").getName()).isEqualTo("foo");
}
@Test
- public void createString_AllowTagKeyNameWithMaxLength() {
+ public void create_AllowTagKeyNameWithMaxLength() {
char[] key = new char[TagKey.MAX_LENGTH];
Arrays.fill(key, 'k');
- TagKeyString.create(new String(key));
+ TagKey.create(new String(key));
}
@Test
- public void createString_DisallowTagKeyNameOverMaxLength() {
+ public void create_DisallowTagKeyNameOverMaxLength() {
char[] key = new char[TagKey.MAX_LENGTH + 1];
Arrays.fill(key, 'k');
thrown.expect(IllegalArgumentException.class);
- TagKeyString.create(new String(key));
+ TagKey.create(new String(key));
}
@Test
- public void createString_DisallowUnprintableChars() {
+ public void create_DisallowUnprintableChars() {
thrown.expect(IllegalArgumentException.class);
- TagKeyString.create("\2ab\3cd");
- }
-
- @Test
- public void testMatchStringKey() {
- assertThat(
- TagKeyString.create("key")
- .match(
- new Function<TagKeyString, String>() {
- @Override
- public String apply(TagKeyString tag) {
- return tag.getName();
- }
- },
- new Function<TagKeyLong, String>() {
- @Override
- public String apply(TagKeyLong tag) {
- throw new AssertionError();
- }
- },
- new Function<TagKeyBoolean, String>() {
- @Override
- public String apply(TagKeyBoolean tag) {
- throw new AssertionError();
- }
- },
- Functions.<String>throwIllegalArgumentException()))
- .isEqualTo("key");
- }
-
- @Test
- public void testMatchLongKey() {
- assertThat(
- TagKeyLong.create("key")
- .match(
- new Function<TagKeyString, String>() {
- @Override
- public String apply(TagKeyString tag) {
- throw new AssertionError();
- }
- },
- new Function<TagKeyLong, String>() {
- @Override
- public String apply(TagKeyLong tag) {
- return tag.getName();
- }
- },
- new Function<TagKeyBoolean, String>() {
- @Override
- public String apply(TagKeyBoolean tag) {
- throw new AssertionError();
- }
- },
- Functions.<String>throwIllegalArgumentException()))
- .isEqualTo("key");
- }
-
- @Test
- public void testMatchBooleanKey() {
- assertThat(
- TagKeyBoolean.create("key")
- .match(
- new Function<TagKeyString, String>() {
- @Override
- public String apply(TagKeyString tag) {
- throw new AssertionError();
- }
- },
- new Function<TagKeyLong, String>() {
- @Override
- public String apply(TagKeyLong tag) {
- throw new AssertionError();
- }
- },
- new Function<TagKeyBoolean, String>() {
- @Override
- public String apply(TagKeyBoolean tag) {
- return tag.getName();
- }
- },
- Functions.<String>throwIllegalArgumentException()))
- .isEqualTo("key");
+ TagKey.create("\2ab\3cd");
}
@Test
public void testTagKeyEquals() {
new EqualsTester()
- .addEqualityGroup(TagKeyString.create("foo"), TagKeyString.create("foo"))
- .addEqualityGroup(TagKeyLong.create("foo"))
- .addEqualityGroup(TagKeyBoolean.create("foo"))
- .addEqualityGroup(TagKeyString.create("bar"))
+ .addEqualityGroup(TagKey.create("foo"), TagKey.create("foo"))
+ .addEqualityGroup(TagKey.create("bar"))
.testEquals();
}
}
diff --git a/api/src/test/java/io/opencensus/tags/TagTest.java b/api/src/test/java/io/opencensus/tags/TagTest.java
index 79b2eb4d..f3fe6dc4 100644
--- a/api/src/test/java/io/opencensus/tags/TagTest.java
+++ b/api/src/test/java/io/opencensus/tags/TagTest.java
@@ -19,17 +19,6 @@ package io.opencensus.tags;
import static com.google.common.truth.Truth.assertThat;
import com.google.common.testing.EqualsTester;
-import io.opencensus.common.Function;
-import io.opencensus.common.Functions;
-import io.opencensus.tags.Tag.TagBoolean;
-import io.opencensus.tags.Tag.TagLong;
-import io.opencensus.tags.Tag.TagString;
-import io.opencensus.tags.TagKey.TagKeyBoolean;
-import io.opencensus.tags.TagKey.TagKeyLong;
-import io.opencensus.tags.TagKey.TagKeyString;
-import io.opencensus.tags.TagValue.TagValueBoolean;
-import io.opencensus.tags.TagValue.TagValueLong;
-import io.opencensus.tags.TagValue.TagValueString;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -39,120 +28,21 @@ import org.junit.runners.JUnit4;
public final class TagTest {
@Test
- public void testGetStringKey() {
- assertThat(TagString.create(TagKeyString.create("k"), TagValueString.create("v")).getKey())
- .isEqualTo(TagKeyString.create("k"));
- }
-
- @Test
- public void testGetLongKey() {
- assertThat(TagLong.create(TagKeyLong.create("k"), TagValueLong.create(2L)).getKey())
- .isEqualTo(TagKeyLong.create("k"));
- }
-
- @Test
- public void testGetBooleanKey() {
- assertThat(TagBoolean.create(TagKeyBoolean.create("k"), TagValueBoolean.create(false)).getKey())
- .isEqualTo(TagKeyBoolean.create("k"));
- }
-
- @Test
- public void testMatchStringTag() {
- assertThat(
- TagString.create(TagKeyString.create("k1"), TagValueString.create("value"))
- .match(
- new Function<TagString, String>() {
- @Override
- public String apply(TagString tag) {
- return tag.getValue().asString();
- }
- },
- new Function<TagLong, String>() {
- @Override
- public String apply(TagLong tag) {
- throw new AssertionError();
- }
- },
- new Function<TagBoolean, String>() {
- @Override
- public String apply(TagBoolean tag) {
- throw new AssertionError();
- }
- },
- Functions.<String>throwIllegalArgumentException()))
- .isEqualTo("value");
- }
-
- @Test
- public void testMatchLong() {
- assertThat(
- TagLong.create(TagKeyLong.create("k2"), TagValueLong.create(3L))
- .match(
- new Function<TagString, Long>() {
- @Override
- public Long apply(TagString tag) {
- throw new AssertionError();
- }
- },
- new Function<TagLong, Long>() {
- @Override
- public Long apply(TagLong tag) {
- return tag.getValue().asLong();
- }
- },
- new Function<TagBoolean, Long>() {
- @Override
- public Long apply(TagBoolean tag) {
- throw new AssertionError();
- }
- },
- Functions.<Long>throwIllegalArgumentException()))
- .isEqualTo(3L);
- }
-
- @Test
- public void testMatchBoolean() {
- assertThat(
- TagBoolean.create(TagKeyBoolean.create("k3"), TagValueBoolean.create(false))
- .match(
- new Function<TagString, Boolean>() {
- @Override
- public Boolean apply(TagString tag) {
- throw new AssertionError();
- }
- },
- new Function<TagLong, Boolean>() {
- @Override
- public Boolean apply(TagLong tag) {
- throw new AssertionError();
- }
- },
- new Function<TagBoolean, Boolean>() {
- @Override
- public Boolean apply(TagBoolean tag) {
- return tag.getValue().asBoolean();
- }
- },
- Functions.<Boolean>throwIllegalArgumentException()))
- .isEqualTo(false);
+ public void testGetKey() {
+ assertThat(Tag.create(TagKey.create("k"), TagValue.create("v")).getKey())
+ .isEqualTo(TagKey.create("k"));
}
@Test
public void testTagEquals() {
new EqualsTester()
.addEqualityGroup(
- TagString.create(TagKeyString.create("Key1"), TagValueString.create("foo")),
- TagString.create(TagKeyString.create("Key1"), TagValueString.create("foo")))
- .addEqualityGroup(
- TagLong.create(TagKeyLong.create("Key1"), TagValueLong.create(100L)),
- TagLong.create(TagKeyLong.create("Key1"), TagValueLong.create(100L)))
- .addEqualityGroup(
- TagBoolean.create(TagKeyBoolean.create("Key1"), TagValueBoolean.create(true)),
- TagBoolean.create(TagKeyBoolean.create("Key1"), TagValueBoolean.create(true)))
+ Tag.create(TagKey.create("Key"), TagValue.create("foo")),
+ Tag.create(TagKey.create("Key"), TagValue.create("foo")))
.addEqualityGroup(
- TagBoolean.create(TagKeyBoolean.create("Key2"), TagValueBoolean.create(true)))
+ Tag.create(TagKey.create("Key"), TagValue.create("bar")))
.addEqualityGroup(
- TagBoolean.create(TagKeyBoolean.create("Key1"), TagValueBoolean.create(false)))
+ Tag.create(TagKey.create("Key2"), TagValue.create("foo")))
.testEquals();
}
}
diff --git a/api/src/test/java/io/opencensus/tags/TagValueTest.java b/api/src/test/java/io/opencensus/tags/TagValueTest.java
index b1382312..7b4b68af 100644
--- a/api/src/test/java/io/opencensus/tags/TagValueTest.java
+++ b/api/src/test/java/io/opencensus/tags/TagValueTest.java
@@ -19,11 +19,6 @@ package io.opencensus.tags;
import static com.google.common.truth.Truth.assertThat;
import com.google.common.testing.EqualsTester;
-import io.opencensus.common.Function;
-import io.opencensus.common.Functions;
-import io.opencensus.tags.TagValue.TagValueBoolean;
-import io.opencensus.tags.TagValue.TagValueLong;
-import io.opencensus.tags.TagValue.TagValueString;
import java.util.Arrays;
import org.junit.Rule;
import org.junit.Test;
@@ -34,121 +29,37 @@ import org.junit.runners.JUnit4;
/** Tests for {@link TagValue}. */
@RunWith(JUnit4.class)
public final class TagValueTest {
-
@Rule public final ExpectedException thrown = ExpectedException.none();
@Test
- public void testMatchStringValue() {
- assertThat(
- TagValueString.create("value")
- .match(
- new Function<TagValueString, String>() {
- @Override
- public String apply(TagValueString tag) {
- return tag.asString();
- }
- },
- new Function<TagValueLong, String>() {
- @Override
- public String apply(TagValueLong tag) {
- throw new AssertionError();
- }
- },
- new Function<TagValueBoolean, String>() {
- @Override
- public String apply(TagValueBoolean tag) {
- throw new AssertionError();
- }
- },
- Functions.<String>throwIllegalArgumentException()))
- .isEqualTo("value");
- }
-
- @Test
- public void testMatchLongValue() {
- assertThat(
- TagValueLong.create(1234)
- .match(
- new Function<TagValueString, Long>() {
- @Override
- public Long apply(TagValueString tag) {
- throw new AssertionError();
- }
- },
- new Function<TagValueLong, Long>() {
- @Override
- public Long apply(TagValueLong tag) {
- return tag.asLong();
- }
- },
- new Function<TagValueBoolean, Long>() {
- @Override
- public Long apply(TagValueBoolean tag) {
- throw new AssertionError();
- }
- },
- Functions.<Long>throwIllegalArgumentException()))
- .isEqualTo(1234);
- }
-
- @Test
- public void testMatchBooleanValue() {
- assertThat(
- TagValueBoolean.create(false)
- .match(
- new Function<TagValueString, Boolean>() {
- @Override
- public Boolean apply(TagValueString tag) {
- throw new AssertionError();
- }
- },
- new Function<TagValueLong, Boolean>() {
- @Override
- public Boolean apply(TagValueLong tag) {
- throw new AssertionError();
- }
- },
- new Function<TagValueBoolean, Boolean>() {
- @Override
- public Boolean apply(TagValueBoolean tag) {
- return tag.asBoolean();
- }
- },
- Functions.<Boolean>throwIllegalArgumentException()))
- .isEqualTo(false);
- }
-
- @Test
- public void allowStringTagValueWithMaxLength() {
- char[] chars = new char[TagValueString.MAX_LENGTH];
+ public void allowTagValueWithMaxLength() {
+ char[] chars = new char[TagValue.MAX_LENGTH];
Arrays.fill(chars, 'v');
String value = new String(chars);
- assertThat(TagValueString.create(value).asString()).isEqualTo(value);
+ assertThat(TagValue.create(value).asString()).isEqualTo(value);
}
@Test
- public void disallowStringTagValueOverMaxLength() {
- char[] chars = new char[TagValueString.MAX_LENGTH + 1];
+ public void disallowTagValueOverMaxLength() {
+ char[] chars = new char[TagValue.MAX_LENGTH + 1];
Arrays.fill(chars, 'v');
String value = new String(chars);
thrown.expect(IllegalArgumentException.class);
- TagValueString.create(value);
+ TagValue.create(value);
}
@Test
- public void disallowStringTagValueWithUnprintableChars() {
+ public void disallowTagValueWithUnprintableChars() {
String value = "\2ab\3cd";
thrown.expect(IllegalArgumentException.class);
- TagValueString.create(value);
+ TagValue.create(value);
}
@Test
public void testTagValueEquals() {
new EqualsTester()
- .addEqualityGroup(TagValueString.create("foo"), TagValueString.create("foo"))
- .addEqualityGroup(TagValueLong.create(2))
- .addEqualityGroup(TagValueBoolean.create(true))
- .addEqualityGroup(TagValueString.create("bar"))
+ .addEqualityGroup(TagValue.create("foo"), TagValue.create("foo"))
+ .addEqualityGroup(TagValue.create("bar"))
.testEquals();
}
}