Migrate ResourceLocatingTest to Java.
DELETE
javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/test/ResourceLocatingTest.groovy
-/*
- * Copyright The OpenTelemetry Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package io.opentelemetry.javaagent.test
-
-import io.opentelemetry.javaagent.tooling.bytebuddy.AgentLocationStrategy
-import java.util.concurrent.atomic.AtomicReference
-import net.bytebuddy.agent.builder.AgentBuilder
-import spock.lang.Shared
-import spock.lang.Specification
-
-class ResourceLocatingTest extends Specification {
- @Shared
- def lastLookup = new AtomicReference<String>()
- @Shared
- def childLoader = new ClassLoader(this.getClass().getClassLoader()) {
- @Override
- URL getResource(String name) {
- lastLookup.set(name)
- // do not delegate resource lookup
- return findResource(name)
- }
- }
-
- def cleanup() {
- lastLookup.set(null)
- }
-
- def "finds resources from parent classloader"() {
- expect:
- locator.locate("java/lang/Object").isResolved() == usesProvidedClassloader
- // lastLookup verifies that the given classloader is only used when expected
- lastLookup.get() == usesProvidedClassloader ? null : "java/lang/Object.class"
-
- and:
- !locator.locate("java/lang/InvalidClass").isResolved()
- lastLookup.get() == "java/lang/InvalidClass.class"
-
- where:
- locator | usesProvidedClassloader
- new AgentLocationStrategy().classFileLocator(childLoader, null) | true
- AgentBuilder.LocationStrategy.ForClassLoader.STRONG.classFileLocator(childLoader, null) | false
- }
-}

ADD
javaagent-tooling/src/test/java/io/opentelemetry/javaagent/test/ResourceLocatingTest.java
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.javaagent.test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import io.opentelemetry.javaagent.tooling.bytebuddy.AgentLocationStrategy;
+import java.net.URL;
+import java.util.concurrent.atomic.AtomicReference;
+import net.bytebuddy.dynamic.ClassFileLocator;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+class ResourceLocatingTest {
+
+ private static final AtomicReference<String> lastLookup = new AtomicReference<>();
+
+ private static final ClassLoader childLoader =
+ new ClassLoader(ResourceLocatingTest.class.getClassLoader()) {
+ @Override
+ public URL getResource(String name) {
+ lastLookup.set(name);
+ // do not delegate resource lookup
+ return findResource(name);
+ }
+ };
+
+ @AfterEach
+ void cleanup() {
+ lastLookup.set(null);
+ }
+
+ @Test
+ void findsResourcesFromParentClassloader() throws Exception {
+ ClassFileLocator locator = new AgentLocationStrategy(null).classFileLocator(childLoader, null);
+ assertThat(locator.locate("java/lang/Object").isResolved()).isTrue();
+ assertThat(lastLookup).hasValue("java/lang/Object.class");
+
+ assertThat(locator.locate("java/lang/InvalidClass").isResolved()).isFalse();
+ assertThat(lastLookup).hasValue("java/lang/InvalidClass.class");
+ }
+}

Migrate ResourceLocatingTest to Java. (#3550)