Skip to content

Commit 8c8f0fe

Browse files
committed
convert to java
1 parent f1251bb commit 8c8f0fe

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

javaagent-tooling/src/test/java/io/opentelemetry/javaagent/test/HelperInjectionTest.java

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.net.URL;
2020
import java.net.URLClassLoader;
2121
import java.time.Duration;
22-
import java.util.Arrays;
2322
import java.util.Collections;
2423
import java.util.concurrent.atomic.AtomicReference;
2524
import net.bytebuddy.agent.ByteBuddyAgent;
@@ -28,6 +27,7 @@
2827
import net.bytebuddy.dynamic.loading.ClassInjector;
2928
import org.junit.jupiter.api.Test;
3029

30+
@SuppressWarnings("UnnecessaryAsync")
3131
class HelperInjectionTest {
3232

3333
@Test
@@ -37,8 +37,15 @@ void helpersInjectedToNonDelegatingClassloader() throws Exception {
3737
ClassLoader helpersSourceLoader = new URLClassLoader(helpersSourceUrls);
3838

3939
String helperClassName = HelperInjectionTest.class.getPackage().getName() + ".HelperClass";
40-
HelperInjector injector = new HelperInjector("test", singletonList(helperClassName), Collections.emptyList(), helpersSourceLoader, null);
41-
AtomicReference<URLClassLoader> emptyLoader = new AtomicReference<>(new URLClassLoader(new URL[0], null));
40+
HelperInjector injector =
41+
new HelperInjector(
42+
"test",
43+
singletonList(helperClassName),
44+
Collections.emptyList(),
45+
helpersSourceLoader,
46+
null);
47+
AtomicReference<URLClassLoader> emptyLoader =
48+
new AtomicReference<>(new URLClassLoader(new URL[0], null));
4249

4350
assertThatThrownBy(() -> emptyLoader.get().loadClass(helperClassName))
4451
.isInstanceOf(ClassNotFoundException.class);
@@ -48,7 +55,8 @@ void helpersInjectedToNonDelegatingClassloader() throws Exception {
4855
emptyLoader.get().loadClass(helperClassName);
4956

5057
assertThat(isClassLoaded(helperClassName, emptyLoader.get())).isTrue();
51-
// injecting into emptyLoader should not cause helper class to be load in the helper source classloader
58+
// injecting into emptyLoader should not cause helper class to be load in the helper source
59+
// classloader
5260
assertThat(isClassLoaded(helperClassName, helpersSourceLoader)).isFalse();
5361

5462
// references to emptyLoader are gone
@@ -71,12 +79,13 @@ void helpersInjectedOnBootstrapClassloader() throws Exception {
7179
EarlyInitAgentConfig.create());
7280

7381
String helperClassName = HelperInjectionTest.class.getPackage().getName() + ".HelperClass";
74-
HelperInjector injector = new HelperInjector(
75-
"test",
76-
Arrays.asList(helperClassName),
77-
Collections.emptyList(),
78-
this.getClass().getClassLoader(),
79-
ByteBuddyAgent.getInstrumentation());
82+
HelperInjector injector =
83+
new HelperInjector(
84+
"test",
85+
singletonList(helperClassName),
86+
Collections.emptyList(),
87+
this.getClass().getClassLoader(),
88+
ByteBuddyAgent.getInstrumentation());
8089
URLClassLoader bootstrapChild = new URLClassLoader(new URL[0], null);
8190

8291
assertThatThrownBy(() -> bootstrapChild.loadClass(helperClassName))
@@ -96,11 +105,13 @@ void checkHardReferencesOnClassInjection() throws Exception {
96105
// Copied from HelperInjector:
97106
ClassFileLocator locator = ClassFileLocator.ForClassLoader.of(Utils.getAgentClassLoader());
98107
byte[] classBytes = locator.locate(helperClassName).resolve();
99-
TypeDescription typeDesc = new TypeDescription.Latent(
100-
helperClassName, 0, null, Collections.emptyList());
108+
TypeDescription typeDesc =
109+
new TypeDescription.Latent(helperClassName, 0, null, Collections.emptyList());
101110

102-
AtomicReference<URLClassLoader> emptyLoader = new AtomicReference<>(new URLClassLoader(new URL[0], null));
103-
AtomicReference<ClassInjector> injector = new AtomicReference<>(new ClassInjector.UsingReflection(emptyLoader.get()));
111+
AtomicReference<URLClassLoader> emptyLoader =
112+
new AtomicReference<>(new URLClassLoader(new URL[0], null));
113+
AtomicReference<ClassInjector> injector =
114+
new AtomicReference<>(new ClassInjector.UsingReflection(emptyLoader.get()));
104115
injector.get().inject(Collections.singletonMap(typeDesc, classBytes));
105116

106117
WeakReference<ClassInjector> injectorRef = new WeakReference<>(injector.get());

0 commit comments

Comments
 (0)