Migrate MethodTest to Java
MODIFY
instrumentation/methods/javaagent/build.gradle.kts
instrumentation/methods/javaagent/build.gradle.kts
@@ -14,5 +14,5 @@ dependencies {
}
tasks.withType<Test>().configureEach {
- jvmArgs("-Dotel.instrumentation.methods.include=package.ClassName[method1,method2];MethodTest\$ConfigTracedCallable[call]")
+ jvmArgs("-Dotel.instrumentation.methods.include=io.opentelemetry.javaagent.instrumentation.methods.MethodTest\$ConfigTracedCallable[call]")
}

DELETE
instrumentation/methods/javaagent/src/test/groovy/MethodTest.groovy
-/*
- * Copyright The OpenTelemetry Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
-
-import java.util.concurrent.Callable
-
-class MethodTest extends AgentInstrumentationSpecification {
-
- static class ConfigTracedCallable implements Callable<String> {
- @Override
- String call() throws Exception {
- return "Hello!"
- }
- }
-
- def "test configuration based trace"() {
- expect:
- new ConfigTracedCallable().call() == "Hello!"
-
- and:
- assertTraces(1) {
- trace(0, 1) {
- span(0) {
- name "ConfigTracedCallable.call"
- attributes {
- }
- }
- }
- }
- }
-}

ADD
instrumentation/methods/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/methods/MethodTest.java
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.javaagent.instrumentation.methods;
+
+import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
+
+import io.opentelemetry.api.common.Attributes;
+import io.opentelemetry.api.trace.SpanKind;
+import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
+import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
+import java.util.concurrent.Callable;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+class MethodTest {
+
+ @RegisterExtension
+ static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
+
+ @Test
+ void methodTraced() {
+ assertThat(new ConfigTracedCallable().call()).isEqualTo("Hello!");
+
+ testing.waitAndAssertTraces(
+ trace ->
+ trace.hasSpansSatisfyingExactly(
+ span ->
+ span.hasName("ConfigTracedCallable.call")
+ .hasKind(SpanKind.INTERNAL)
+ .hasAttributes(Attributes.empty())));
+ }
+
+ static class ConfigTracedCallable implements Callable<String> {
+ @Override
+ public String call() {
+ return "Hello!";
+ }
+ }
+}

Migrate MethodTest to Java (#5581)