use of net.bytebuddy.dynamic.loading.ClassInjector in project byte-buddy by raphw.
the class AgentBuilderInitializationStrategyTest method testMinimalRegistrationIndependentType.
@Test
@SuppressWarnings("unchecked")
public void testMinimalRegistrationIndependentType() throws Exception {
Annotation eagerAnnotation = mock(AuxiliaryType.SignatureRelevant.class);
when(eagerAnnotation.annotationType()).thenReturn((Class) AuxiliaryType.SignatureRelevant.class);
TypeDescription independent = mock(TypeDescription.class), dependent = mock(TypeDescription.class);
when(independent.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(eagerAnnotation));
when(dependent.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
Map<TypeDescription, byte[]> map = new HashMap<TypeDescription, byte[]>();
map.put(independent, QUX);
map.put(dependent, BAZ);
when(dynamicType.getAuxiliaryTypes()).thenReturn(map);
ClassInjector classInjector = mock(ClassInjector.class);
when(injectorFactory.resolve()).thenReturn(classInjector);
when(classInjector.inject(Collections.singletonMap(independent, QUX))).thenReturn(Collections.<TypeDescription, Class<?>>singletonMap(independent, Foo.class));
LoadedTypeInitializer loadedTypeInitializer = mock(LoadedTypeInitializer.class);
when(dynamicType.getLoadedTypeInitializers()).thenReturn(Collections.singletonMap(independent, loadedTypeInitializer));
AgentBuilder.InitializationStrategy.Minimal.INSTANCE.register(dynamicType, classLoader, injectorFactory);
verify(classInjector).inject(Collections.singletonMap(independent, QUX));
verifyNoMoreInteractions(classInjector);
verify(loadedTypeInitializer).onLoad(Foo.class);
verifyNoMoreInteractions(loadedTypeInitializer);
}
use of net.bytebuddy.dynamic.loading.ClassInjector in project byte-buddy by raphw.
the class AgentBuilderDefaultTest method testBootstrapClassLoaderCapableInjectorFactoryReflection.
@Test
public void testBootstrapClassLoaderCapableInjectorFactoryReflection() throws Exception {
AgentBuilder.Default.BootstrapInjectionStrategy bootstrapInjectionStrategy = mock(AgentBuilder.Default.BootstrapInjectionStrategy.class);
ClassLoader classLoader = mock(ClassLoader.class);
ProtectionDomain protectionDomain = mock(ProtectionDomain.class);
assertThat(new AgentBuilder.Default.Transformation.Simple.Resolution.BootstrapClassLoaderCapableInjectorFactory(bootstrapInjectionStrategy, classLoader, protectionDomain).resolve(), is((ClassInjector) new ClassInjector.UsingReflection(classLoader, protectionDomain)));
verifyZeroInteractions(bootstrapInjectionStrategy);
}
use of net.bytebuddy.dynamic.loading.ClassInjector in project byte-buddy by raphw.
the class AgentBuilderDefaultTest method testBootstrapClassLoaderCapableInjectorFactoryInstrumentation.
@Test
public void testBootstrapClassLoaderCapableInjectorFactoryInstrumentation() throws Exception {
AgentBuilder.Default.BootstrapInjectionStrategy bootstrapInjectionStrategy = mock(AgentBuilder.Default.BootstrapInjectionStrategy.class);
ProtectionDomain protectionDomain = mock(ProtectionDomain.class);
ClassInjector classInjector = mock(ClassInjector.class);
when(bootstrapInjectionStrategy.make(protectionDomain)).thenReturn(classInjector);
assertThat(new AgentBuilder.Default.Transformation.Simple.Resolution.BootstrapClassLoaderCapableInjectorFactory(bootstrapInjectionStrategy, null, protectionDomain).resolve(), is(classInjector));
verify(bootstrapInjectionStrategy).make(protectionDomain);
verifyNoMoreInteractions(bootstrapInjectionStrategy);
}
Aggregations