Search in sources :

Example 11 with ByteArrayClassLoader

use of net.bytebuddy.dynamic.loading.ByteArrayClassLoader in project byte-buddy by raphw.

the class AbstractDynamicTypeBuilderForInliningTest method testNoVisibilityBridgeForAbstractMethod.

@Test
public void testNoVisibilityBridgeForAbstractMethod() throws Exception {
    ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassFileExtraction.of(PackagePrivateVisibilityBridgeExtensionAbstractMethod.class, VisibilityBridgeAbstractMethod.class));
    Class<?> type = create(PackagePrivateVisibilityBridgeExtensionAbstractMethod.class).modifiers(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT).make().load(classLoader, ClassLoadingStrategy.Default.INJECTION).getLoaded();
    assertThat(type.getDeclaredConstructors().length, is(1));
    assertThat(type.getDeclaredMethods().length, is(0));
}
Also used : ByteArrayClassLoader(net.bytebuddy.dynamic.loading.ByteArrayClassLoader) URLClassLoader(java.net.URLClassLoader) ByteArrayClassLoader(net.bytebuddy.dynamic.loading.ByteArrayClassLoader) AbstractDynamicTypeBuilderTest(net.bytebuddy.dynamic.AbstractDynamicTypeBuilderTest) Test(org.junit.Test)

Example 12 with ByteArrayClassLoader

use of net.bytebuddy.dynamic.loading.ByteArrayClassLoader in project byte-buddy by raphw.

the class AbstractDynamicTypeBuilderForInliningTest method testNoVisibilityBridgeForNonPublicType.

@Test
public void testNoVisibilityBridgeForNonPublicType() throws Exception {
    ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassFileExtraction.of(PackagePrivateVisibilityBridgeExtension.class, VisibilityBridge.class, FooBar.class));
    Class<?> type = create(PackagePrivateVisibilityBridgeExtension.class).modifiers(0).make().load(classLoader, ClassLoadingStrategy.Default.INJECTION).getLoaded();
    assertThat(type.getDeclaredConstructors().length, is(1));
    assertThat(type.getDeclaredMethods().length, is(0));
}
Also used : ByteArrayClassLoader(net.bytebuddy.dynamic.loading.ByteArrayClassLoader) URLClassLoader(java.net.URLClassLoader) ByteArrayClassLoader(net.bytebuddy.dynamic.loading.ByteArrayClassLoader) AbstractDynamicTypeBuilderTest(net.bytebuddy.dynamic.AbstractDynamicTypeBuilderTest) Test(org.junit.Test)

Example 13 with ByteArrayClassLoader

use of net.bytebuddy.dynamic.loading.ByteArrayClassLoader in project byte-buddy by raphw.

the class AbstractDynamicTypeBuilderForInliningTest method testNoVisibilityBridgeForInheritedType.

@Test
public void testNoVisibilityBridgeForInheritedType() throws Exception {
    ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassFileExtraction.of(PublicVisibilityBridgeExtension.class, VisibilityBridge.class, FooBar.class));
    Class<?> type = new ByteBuddy().subclass(PublicVisibilityBridgeExtension.class).modifiers(Opcodes.ACC_PUBLIC).make().load(classLoader, ClassLoadingStrategy.Default.INJECTION).getLoaded();
    assertThat(type.getDeclaredConstructors().length, is(1));
    assertThat(type.getDeclaredMethods().length, is(0));
}
Also used : ByteArrayClassLoader(net.bytebuddy.dynamic.loading.ByteArrayClassLoader) URLClassLoader(java.net.URLClassLoader) ByteArrayClassLoader(net.bytebuddy.dynamic.loading.ByteArrayClassLoader) ByteBuddy(net.bytebuddy.ByteBuddy) AbstractDynamicTypeBuilderTest(net.bytebuddy.dynamic.AbstractDynamicTypeBuilderTest) Test(org.junit.Test)

Example 14 with ByteArrayClassLoader

use of net.bytebuddy.dynamic.loading.ByteArrayClassLoader in project morphia by mongodb.

the class TestClassLoader method useClassLoading.

private void useClassLoading(Function<ClassLoader, MongoCollection<BasicEntity>> collectionCreator) {
    storePreviousInstance();
    ClassLoader classLoader = new ByteArrayClassLoader(new AppClassLoader(), false, Map.of());
    Class<?> childClass = loadDynamicClass(classLoader);
    BasicEntity res = collectionCreator.apply(classLoader).find().first();
    assertTrue(childClass.isInstance(res.data));
}
Also used : ByteArrayClassLoader(net.bytebuddy.dynamic.loading.ByteArrayClassLoader) ByteArrayClassLoader(net.bytebuddy.dynamic.loading.ByteArrayClassLoader)

Example 15 with ByteArrayClassLoader

use of net.bytebuddy.dynamic.loading.ByteArrayClassLoader in project byte-buddy by raphw.

the class AbstractTypeDescriptionTest method testIsAssignableClassLoader.

@Test
public void testIsAssignableClassLoader() throws Exception {
    ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassFileExtraction.of(SimpleType.class), ByteArrayClassLoader.PersistenceHandler.MANIFEST);
    Class<?> otherSimpleType = classLoader.loadClass(SimpleType.class.getName());
    assertThat(describe(SimpleType.class).isAssignableFrom(describe(otherSimpleType)), is(true));
    assertThat(describe(SimpleType.class).isAssignableTo(describe(otherSimpleType)), is(true));
    assertThat(describe(Object.class).isAssignableFrom(describe(otherSimpleType)), is(true));
    assertThat(describe(otherSimpleType).isAssignableTo(describe(Object.class)), is(true));
}
Also used : SimpleType(net.bytebuddy.test.packaging.SimpleType) ByteArrayClassLoader(net.bytebuddy.dynamic.loading.ByteArrayClassLoader) ByteArrayClassLoader(net.bytebuddy.dynamic.loading.ByteArrayClassLoader) Test(org.junit.Test)

Aggregations

ByteArrayClassLoader (net.bytebuddy.dynamic.loading.ByteArrayClassLoader)20 Test (org.junit.Test)14 URLClassLoader (java.net.URLClassLoader)9 AbstractDynamicTypeBuilderTest (net.bytebuddy.dynamic.AbstractDynamicTypeBuilderTest)7 ByteBuddy (net.bytebuddy.ByteBuddy)4 Before (org.junit.Before)3 Annotation (java.lang.annotation.Annotation)2 AnnotationDescription (net.bytebuddy.description.annotation.AnnotationDescription)2 StubMethod (net.bytebuddy.implementation.StubMethod)2 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 DynamicType (net.bytebuddy.dynamic.DynamicType)1 SimpleType (net.bytebuddy.test.packaging.SimpleType)1 GenericType (net.bytebuddy.test.scope.GenericType)1