diff --git a/auto-instrumentation/okhttp/okhttp-3.0/library/src/test/java/io/opentelemetry/instrumentation/library/okhttp/v3_0/internal/CachedSupplierTest.java b/auto-instrumentation/okhttp/okhttp-3.0/library/src/test/java/io/opentelemetry/instrumentation/library/okhttp/v3_0/internal/CachedSupplierTest.java new file mode 100644 index 000000000..ef466cf4d --- /dev/null +++ b/auto-instrumentation/okhttp/okhttp-3.0/library/src/test/java/io/opentelemetry/instrumentation/library/okhttp/v3_0/internal/CachedSupplierTest.java @@ -0,0 +1,47 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.library.okhttp.v3_0.internal; + +import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; + +import java.util.function.Supplier; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +class CachedSupplierTest { + + @Test + void provideAndCacheSuppliersResult() { + Supplier original = + spy( + new Supplier() { + @Override + public String get() { + return "Hello World"; + } + }); + CachedSupplier cached = CachedSupplier.create(original); + + for (int i = 0; i < 3; i++) { + Assertions.assertThat(cached.get()).isEqualTo("Hello World"); + } + verify(original).get(); + } + + @Test + void validateSupplierDoesNotReturnNull() { + Supplier original = () -> null; + CachedSupplier cached = CachedSupplier.create(original); + + try { + cached.get(); + fail(); + } catch (NullPointerException ignored) { + } + } +} diff --git a/buildSrc/src/main/kotlin/otel.android-library-conventions.gradle.kts b/buildSrc/src/main/kotlin/otel.android-library-conventions.gradle.kts index 794d6654c..102a95476 100644 --- a/buildSrc/src/main/kotlin/otel.android-library-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/otel.android-library-conventions.gradle.kts @@ -28,8 +28,16 @@ android { } } +tasks.withType { + useJUnitPlatform() +} + val libs = extensions.getByType().named("libs") dependencies { implementation(libs.findLibrary("findbugs-jsr305").get()) + testImplementation(libs.findLibrary("assertj-core").get()) + testImplementation(libs.findBundle("mockito").get()) + testImplementation(libs.findBundle("junit").get()) + testImplementation(libs.findLibrary("opentelemetry-sdk-testing").get()) coreLibraryDesugaring(libs.findLibrary("desugarJdkLibs").get()) } \ No newline at end of file diff --git a/instrumentation/build.gradle.kts b/instrumentation/build.gradle.kts index 714b2c1e0..13eefeded 100644 --- a/instrumentation/build.gradle.kts +++ b/instrumentation/build.gradle.kts @@ -68,18 +68,10 @@ dependencies { implementation(libs.opentelemetry.semconv) implementation(libs.opentelemetry.diskBuffering) - testImplementation(libs.bundles.mockito) - testImplementation(libs.bundles.junit) - testImplementation(libs.opentelemetry.sdk.testing) testImplementation(libs.robolectric) testImplementation(libs.androidx.test.core) - testImplementation(libs.assertj.core) testImplementation(libs.awaitility) } -tasks.withType { - useJUnitPlatform() -} - extra["pomName"] = "OpenTelemetry Android Instrumentation" description = "A library for instrumenting Android applications with OpenTelemetry"