Skip to content

Commit

Permalink
Some more test coverage for OpenTelemetrySDK. (#2130)
Browse files Browse the repository at this point in the history
* Some more test coverage for OpenTelemetrySDK.

* Fix assertion

* Update OpenTelemetrySdk.java
  • Loading branch information
Anuraag Agrawal authored Nov 26, 2020
1 parent 8832674 commit 14d23dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,6 @@ public OpenTelemetrySdk build() {
private TracerSdkProvider buildTracerProvider() {
TracerProvider tracerProvider = super.tracerProvider;
if (tracerProvider != null) {
if (!(tracerProvider instanceof TracerSdkProvider)) {
throw new IllegalStateException(
"The OpenTelemetrySdk can only be configured with a TracerSdkProvider");
}
return (TracerSdkProvider) tracerProvider;
}
TracerSdkProvider.Builder tracerProviderBuilder = TracerSdkProvider.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package io.opentelemetry.sdk;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.InstanceOfAssertFactories.type;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -37,6 +39,24 @@ class OpenTelemetrySdkTest {
@Mock private ContextPropagators propagators;
@Mock private Clock clock;

@Test
void testGetGlobal() {
assertThat(OpenTelemetrySdk.get()).isSameAs(OpenTelemetry.get());
}

@Test
void testGetTracerManagementWhenNotTracerSdk() {
OpenTelemetry previous = OpenTelemetry.get();
assertThatCode(OpenTelemetrySdk::getGlobalTracerManagement).doesNotThrowAnyException();
try {
OpenTelemetry.set(OpenTelemetry.builder().setTracerProvider(tracerProvider).build());
assertThatThrownBy(OpenTelemetrySdk::getGlobalTracerManagement)
.isInstanceOf(IllegalStateException.class);
} finally {
OpenTelemetry.set(previous);
}
}

@Test
void testGlobalDefault() {
assertThat(((TracerSdkProvider) OpenTelemetrySdk.getGlobalTracerManagement()).get(""))
Expand Down

0 comments on commit 14d23dc

Please sign in to comment.