use of net.bytebuddy.dynamic.loading.ByteArrayClassLoader in project byte-buddy by raphw.
the class TypeDescriptionForLoadedTypeTest method testLazyResolution.
@Test
public void testLazyResolution() throws Exception {
ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassFileExtraction.of(Foo.class));
new TypeDescription.ForLoadedType(classLoader.loadClass(Foo.class.getName()));
}
use of net.bytebuddy.dynamic.loading.ByteArrayClassLoader in project byte-buddy by raphw.
the class ByteBuddyTest method testImplicitStrategyInjectable.
@Test
public void testImplicitStrategyInjectable() throws Exception {
ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, Collections.<String, byte[]>emptyMap());
Class<?> type = new ByteBuddy().subclass(Object.class).make().load(classLoader).getLoaded();
assertThat(type.getClassLoader(), is(classLoader));
}
use of net.bytebuddy.dynamic.loading.ByteArrayClassLoader in project byte-buddy by raphw.
the class AgentBuilderDefaultApplicationSuperTypeLoadingTest method setUp.
@Before
public void setUp() throws Exception {
classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassFileExtraction.of(Foo.class, Bar.class, AgentBuilderDefaultApplicationSuperTypeLoadingTest.class), ByteArrayClassLoader.PersistenceHandler.MANIFEST);
executorService = Executors.newCachedThreadPool();
}
use of net.bytebuddy.dynamic.loading.ByteArrayClassLoader in project byte-buddy by raphw.
the class AnnotationAppenderDefaultTest method makeTypeWithAnnotation.
private Class<?> makeTypeWithAnnotation(Annotation annotation) throws Exception {
when(valueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true);
ClassWriter classWriter = new ClassWriter(AsmVisitorWrapper.NO_FLAGS);
classWriter.visit(ClassFileVersion.ofThisVm().getMinorMajorVersion(), Opcodes.ACC_PUBLIC, BAR.replace('.', '/'), null, Type.getInternalName(Object.class), null);
AnnotationVisitor annotationVisitor = classWriter.visitAnnotation(Type.getDescriptor(annotation.annotationType()), true);
when(target.visit(any(String.class), anyBoolean())).thenReturn(annotationVisitor);
AnnotationDescription annotationDescription = AnnotationDescription.ForLoadedAnnotation.of(annotation);
annotationAppender.append(annotationDescription, valueFilter);
classWriter.visitEnd();
Class<?> bar = new ByteArrayClassLoader(getClass().getClassLoader(), Collections.singletonMap(BAR, classWriter.toByteArray())).loadClass(BAR);
assertThat(bar.getName(), is(BAR));
assertThat(bar.getSuperclass(), CoreMatchers.<Class<?>>is(Object.class));
return bar;
}
use of net.bytebuddy.dynamic.loading.ByteArrayClassLoader in project byte-buddy by raphw.
the class MethodDelegationSuperTest method testFinalType.
@Test
public void testFinalType() throws Exception {
ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassFileExtraction.of(SimpleInterceptor.class));
Class<?> type = new ByteBuddy().rebase(FinalType.class).modifiers(TypeManifestation.PLAIN, Visibility.PUBLIC).method(named(FOO)).intercept(ExceptionMethod.throwing(RuntimeException.class)).method(named(BAR)).intercept(MethodDelegation.to(SimpleInterceptor.class)).make().load(classLoader, ClassLoadingStrategy.Default.INJECTION).getLoaded();
assertThat(type.getDeclaredMethod(BAR).invoke(type.getDeclaredConstructor().newInstance()), is((Object) FOO));
}
Aggregations