aboutsummaryrefslogtreecommitdiff
path: root/api/src/test/java/io/opencensus/metrics/MetricsTest.java
diff options
context:
space:
mode:
authorYang Song <songy23@users.noreply.github.com>2018-09-14 15:45:30 -0700
committerGitHub <noreply@github.com>2018-09-14 15:45:30 -0700
commit937d2296642d9bcdae23a2be469d1d0f367ae3de (patch)
tree452b70aefb0a257f4373574a936ffa189f1e23c8 /api/src/test/java/io/opencensus/metrics/MetricsTest.java
parent98fb8ad4e40b67b92d8688f45dbd8ac41399d8d7 (diff)
downloadopencensus-java-937d2296642d9bcdae23a2be469d1d0f367ae3de.tar.gz
Revert "Temporarily move "metrics" package into impl_core/ for release. (#1426)" (#1432)
This reverts commit d3fa0e5c60903f95c184d7c7bafae8fdd12156ad.
Diffstat (limited to 'api/src/test/java/io/opencensus/metrics/MetricsTest.java')
-rw-r--r--api/src/test/java/io/opencensus/metrics/MetricsTest.java71
1 files changed, 71 insertions, 0 deletions
diff --git a/api/src/test/java/io/opencensus/metrics/MetricsTest.java b/api/src/test/java/io/opencensus/metrics/MetricsTest.java
new file mode 100644
index 00000000..9e0eee1f
--- /dev/null
+++ b/api/src/test/java/io/opencensus/metrics/MetricsTest.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2018, 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.metrics;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import io.opencensus.metrics.export.ExportComponent;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Unit tests for {@link Metrics}. */
+@RunWith(JUnit4.class)
+public class MetricsTest {
+ @Rule public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void loadMetricsComponent_UsesProvidedClassLoader() {
+ final RuntimeException toThrow = new RuntimeException("UseClassLoader");
+ thrown.expect(RuntimeException.class);
+ thrown.expectMessage("UseClassLoader");
+ Metrics.loadMetricsComponent(
+ new ClassLoader() {
+ @Override
+ public Class<?> loadClass(String name) {
+ throw toThrow;
+ }
+ });
+ }
+
+ @Test
+ public void loadMetricsComponent_IgnoresMissingClasses() {
+ ClassLoader classLoader =
+ new ClassLoader() {
+ @Override
+ public Class<?> loadClass(String name) throws ClassNotFoundException {
+ throw new ClassNotFoundException();
+ }
+ };
+ assertThat(Metrics.loadMetricsComponent(classLoader).getClass().getName())
+ .isEqualTo("io.opencensus.metrics.MetricsComponent$NoopMetricsComponent");
+ }
+
+ @Test
+ public void defaultExportComponent() {
+ assertThat(Metrics.getExportComponent())
+ .isInstanceOf(ExportComponent.newNoopExportComponent().getClass());
+ }
+
+ @Test
+ public void defaultMetricRegistry() {
+ assertThat(Metrics.getMetricRegistry())
+ .isInstanceOf(MetricRegistry.newNoopMetricRegistry().getClass());
+ }
+}