Convert internal-lambda test from groovy to java (#9611)

This commit is contained in:
Jay DeLuca 2023-10-09 07:27:16 -04:00 committed by GitHub
parent e24f0be597
commit 98976e9edb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 21 deletions

View File

@ -1,21 +0,0 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.javaagent.bootstrap.VirtualFieldInstalledMarker
class LambdaInstrumentationTest extends AgentInstrumentationSpecification {
def "test transform Runnable lambda"() {
setup:
Runnable runnable = TestLambda.makeRunnable()
expect:
// RunnableInstrumentation adds a VirtualField to all implementors of Runnable. If lambda class
// is transformed then it must have context store marker interface.
runnable instanceof VirtualFieldInstalledMarker
!VirtualFieldInstalledMarker.isAssignableFrom(Runnable)
}
}

View File

@ -0,0 +1,24 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.instrumentation.internal.lambda;
import static org.assertj.core.api.Assertions.assertThat;
import io.opentelemetry.javaagent.bootstrap.VirtualFieldInstalledMarker;
import org.junit.jupiter.api.Test;
class LambdaInstrumentationTest {
@Test
void testTransformRunnableLambda() {
Runnable runnable = TestLambda.makeRunnable();
// RunnableInstrumentation adds a VirtualField to all implementors of Runnable. If lambda class
// is transformed then it must have context store marker interface.
assertThat(runnable).isInstanceOf(VirtualFieldInstalledMarker.class);
assertThat(VirtualFieldInstalledMarker.class.isAssignableFrom(Runnable.class)).isFalse();
}
}

View File

@ -3,6 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.instrumentation.internal.lambda;
public class TestLambda {
static Runnable makeRunnable() {