Java Code Examples for net.bytebuddy.dynamic.loading.ClassLoadingStrategy#BOOTSTRAP_LOADER

The following examples show how to use net.bytebuddy.dynamic.loading.ClassLoadingStrategy#BOOTSTRAP_LOADER . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluginEngineDefaultTest.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
@Test
public void testLiveInitializer() throws Exception {
    Plugin.Engine.Listener listener = mock(Plugin.Engine.Listener.class);
    Plugin plugin = new LiveInitializerPlugin();
    Plugin.Engine.Source source = Plugin.Engine.Source.InMemory.ofTypes(Sample.class);
    Plugin.Engine.Target.InMemory target = new Plugin.Engine.Target.InMemory();
    Plugin.Engine.Summary summary = new Plugin.Engine.Default()
            .with(listener)
            .withoutErrorHandlers()
            .with(ClassFileLocator.ForClassLoader.of(SimplePlugin.class.getClassLoader()))
            .with(dispatcherFactory)
            .apply(source, target, new Plugin.Factory.Simple(plugin));
    ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, target.toTypeMap());
    Class<?> type = classLoader.loadClass(Sample.class.getName());
    assertThat(type.getDeclaredField(FOO).getType(), is((Object) Void.class));
    assertThat(summary.getTransformed(), hasItems(TypeDescription.ForLoadedType.of(Sample.class)));
    assertThat(summary.getFailed().size(), is(0));
    assertThat(summary.getUnresolved().size(), is(0));
    verify(listener).onManifest(Plugin.Engine.Source.Origin.NO_MANIFEST);
    verify(listener).onDiscovery(Sample.class.getName());
    verify(listener).onTransformation(TypeDescription.ForLoadedType.of(Sample.class), plugin);
    verify(listener).onTransformation(TypeDescription.ForLoadedType.of(Sample.class), Collections.singletonList(plugin));
    verify(listener).onLiveInitializer(TypeDescription.ForLoadedType.of(Sample.class), TypeDescription.ForLoadedType.of(Sample.class));
    verify(listener).onComplete(TypeDescription.ForLoadedType.of(Sample.class));
    verifyNoMoreInteractions(listener);
}
 
Example 2
Source File: PluginEngineDefaultTest.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleTransformationIgnoredByMatcher() throws Exception {
    Plugin.Engine.Listener listener = mock(Plugin.Engine.Listener.class);
    Plugin plugin = eager
            ? new SimplePlugin()
            : new PreprocessingPlugin(new SimplePlugin());
    Plugin.Engine.Source source = Plugin.Engine.Source.InMemory.ofTypes(Sample.class);
    Plugin.Engine.Target.InMemory target = new Plugin.Engine.Target.InMemory();
    Plugin.Engine.Summary summary = new Plugin.Engine.Default()
            .with(listener)
            .with(ClassFileLocator.ForClassLoader.of(SimplePlugin.class.getClassLoader()))
            .with(dispatcherFactory)
            .ignore(ElementMatchers.is(Sample.class))
            .apply(source, target, new Plugin.Factory.Simple(plugin));
    ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, target.toTypeMap());
    Class<?> type = classLoader.loadClass(Sample.class.getName());
    assertThat(type.getDeclaredFields().length, is(0));
    assertThat(summary.getTransformed().size(), is(0));
    assertThat(summary.getFailed().size(), is(0));
    assertThat(summary.getUnresolved().size(), is(0));
    verify(listener).onManifest(Plugin.Engine.Source.Origin.NO_MANIFEST);
    verify(listener).onDiscovery(Sample.class.getName());
    verify(listener).onIgnored(TypeDescription.ForLoadedType.of(Sample.class), Collections.singletonList(plugin));
    verify(listener).onComplete(TypeDescription.ForLoadedType.of(Sample.class));
    verifyNoMoreInteractions(listener);
}
 
Example 3
Source File: AbstractDynamicTypeBuilderTest.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
@Test
public void testPreparedField() throws Exception {
    ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassFileLocator.ForClassLoader.readToNames(SampleAnnotation.class));
    Class<?> type = createPlain()
            .defineMethod(BAR, String.class, Visibility.PUBLIC)
            .intercept(new PreparedField())
            .make()
            .load(classLoader, ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded();
    assertThat(type.getDeclaredFields().length, is(1));
    assertThat(type.getDeclaredField(FOO).getName(), is(FOO));
    assertThat(type.getDeclaredField(FOO).getType(), CoreMatchers.<Class<?>>is(Object.class));
    assertThat(type.getDeclaredField(FOO).getModifiers(), is(MODIFIERS));
    assertThat(type.getDeclaredField(FOO).getAnnotations().length, is(1));
    Annotation annotation = type.getDeclaredField(FOO).getAnnotations()[0];
    assertThat(annotation.annotationType().getName(), is(SampleAnnotation.class.getName()));
    Method foo = annotation.annotationType().getDeclaredMethod(FOO);
    assertThat(foo.invoke(annotation), is((Object) BAR));
}
 
Example 4
Source File: ByteBuddyTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testImplicitStrategyInjectable() throws Exception {
    ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, false, Collections.<String, byte[]>emptyMap());
    Class<?> type = new ByteBuddy()
            .subclass(Object.class)
            .make()
            .load(classLoader)
            .getLoaded();
    assertThat(type.getClassLoader(), is(classLoader));
}
 
Example 5
Source File: PluginEngineDefaultTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnresolved() throws Exception {
    Plugin.Engine.Listener listener = mock(Plugin.Engine.Listener.class);
    Plugin plugin = eager
            ? new SimplePlugin()
            : new PreprocessingPlugin(new SimplePlugin());
    Plugin.Engine.Source source = new Plugin.Engine.Source.InMemory(Collections.singletonMap(
            Sample.class.getName().replace('.', '/') + ".class",
            ClassFileLocator.ForClassLoader.read(Sample.class))) {
        @Override
        public ClassFileLocator getClassFileLocator() {
            return ClassFileLocator.NoOp.INSTANCE;
        }
    };
    Plugin.Engine.Target.InMemory target = new Plugin.Engine.Target.InMemory();
    Plugin.Engine.Summary summary = new Plugin.Engine.Default()
            .with(listener)
            .withoutErrorHandlers()
            .with(dispatcherFactory)
            .apply(source, target, new Plugin.Factory.Simple(plugin));
    ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, target.toTypeMap());
    Class<?> type = classLoader.loadClass(Sample.class.getName());
    assertThat(type.getDeclaredFields().length, is(0));
    assertThat(summary.getTransformed().size(), is(0));
    assertThat(summary.getFailed().size(), is(0));
    assertThat(summary.getUnresolved().size(), is(1));
    assertThat(summary.getUnresolved().contains(Sample.class.getName()), is(true));
    verify(listener).onManifest(Plugin.Engine.Source.Origin.NO_MANIFEST);
    verify(listener).onDiscovery(Sample.class.getName());
    verify(listener).onUnresolved(Sample.class.getName());
    verifyNoMoreInteractions(listener);
}
 
Example 6
Source File: AbstractDynamicTypeBuilderForInliningTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoVisibilityBridgeForInheritedType() throws Exception {
    InjectionClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER,
            false,
            ClassFileLocator.ForClassLoader.readToNames(PublicVisibilityBridgeExtension.class, VisibilityBridge.class, FooBar.class));
    Class<?> type = new ByteBuddy().subclass(PublicVisibilityBridgeExtension.class)
            .modifiers(Opcodes.ACC_PUBLIC)
            .make()
            .load(classLoader, InjectionClassLoader.Strategy.INSTANCE)
            .getLoaded();
    assertThat(type.getDeclaredConstructors().length, is(1));
    assertThat(type.getDeclaredMethods().length, is(0));
}
 
Example 7
Source File: AbstractTypeDescriptionTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
public static Class<?> malform(Class<?> type) throws Exception {
    ClassReader classReader = new ClassReader(type.getName());
    ClassWriter classWriter = new ClassWriter(classReader, 0);
    classReader.accept(new SignatureMalformer(classWriter), 0);
    ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER,
            Collections.singletonMap(type.getName(), classWriter.toByteArray()),
            ByteArrayClassLoader.PersistenceHandler.MANIFEST);
    return classLoader.loadClass(type.getName());
}
 
Example 8
Source File: AbstractTypeDescriptionTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsAssignableClassLoader() throws Exception {
    ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER,
            ClassFileLocator.ForClassLoader.readToNames(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));
}
 
Example 9
Source File: AbstractDynamicTypeBuilderForInliningTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoVisibilityBridgeForAbstractMethod() throws Exception {
    InjectionClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER,
            false,
            ClassFileLocator.ForClassLoader.readToNames(PackagePrivateVisibilityBridgeExtensionAbstractMethod.class, VisibilityBridgeAbstractMethod.class));
    Class<?> type = create(PackagePrivateVisibilityBridgeExtensionAbstractMethod.class)
            .modifiers(Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT)
            .make()
            .load(classLoader, InjectionClassLoader.Strategy.INSTANCE)
            .getLoaded();
    assertThat(type.getDeclaredConstructors().length, is(1));
    assertThat(type.getDeclaredMethods().length, is(0));
}
 
Example 10
Source File: AbstractDynamicTypeBuilderForInliningTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testVisibilityBridge() throws Exception {
    InjectionClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER,
            false,
            ClassFileLocator.ForClassLoader.readToNames(VisibilityBridge.class, FooBar.class));
    Class<?> type = create(PackagePrivateVisibilityBridgeExtension.class)
            .modifiers(Opcodes.ACC_PUBLIC)
            .make()
            .load(classLoader, InjectionClassLoader.Strategy.INSTANCE)
            .getLoaded();
    assertThat(type.getDeclaredConstructors().length, is(1));
    Constructor<?> constructor = type.getDeclaredConstructor();
    constructor.setAccessible(true);
    assertThat(type.getDeclaredMethods().length, is(2));
    Method foo = type.getDeclaredMethod(FOO, String.class);
    foo.setAccessible(true);
    assertThat(foo.isBridge(), is(true));
    assertThat(foo.getDeclaredAnnotations().length, is(1));
    assertThat(foo.getDeclaredAnnotations()[0].annotationType().getName(), is(FooBar.class.getName()));
    assertThat(foo.invoke(constructor.newInstance(), BAR), is((Object) (FOO + BAR)));
    assertThat(foo.getParameterAnnotations()[0].length, is(1));
    assertThat(foo.getParameterAnnotations()[0][0].annotationType().getName(), is(FooBar.class.getName()));
    assertThat(foo.invoke(constructor.newInstance(), BAR), is((Object) (FOO + BAR)));
    Method bar = type.getDeclaredMethod(BAR, List.class);
    bar.setAccessible(true);
    assertThat(bar.isBridge(), is(true));
    assertThat(bar.getDeclaredAnnotations().length, is(0));
    List<?> list = new ArrayList<Object>();
    assertThat(bar.invoke(constructor.newInstance(), list), sameInstance((Object) list));
    assertThat(bar.getGenericReturnType(), instanceOf(Class.class));
    assertThat(bar.getGenericParameterTypes()[0], instanceOf(Class.class));
    assertThat(bar.getGenericExceptionTypes()[0], instanceOf(Class.class));
}
 
Example 11
Source File: ByteBuddyTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testImplicitStrategyNonBootstrap() throws Exception {
    ClassLoader classLoader = new URLClassLoader(new URL[0], ClassLoadingStrategy.BOOTSTRAP_LOADER);
    Class<?> type = new ByteBuddy()
            .subclass(Object.class)
            .make()
            .load(classLoader)
            .getLoaded();
    assertThat(type.getClassLoader(), not(classLoader));
}
 
Example 12
Source File: AgentBuilderDefaultApplicationRedefineTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    simpleTypeLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER,
            ClassFileLocator.ForClassLoader.readToNames(SimpleType.class),
            ByteArrayClassLoader.PersistenceHandler.MANIFEST);
    optionalTypeLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER,
            ClassFileLocator.ForClassLoader.readToNames(SimpleOptionalType.class),
            ByteArrayClassLoader.PersistenceHandler.MANIFEST);
}
 
Example 13
Source File: AbstractDynamicTypeBuilderForInliningTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoVisibilityBridgeForNonPublicType() throws Exception {
    InjectionClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER,
            false,
            ClassFileLocator.ForClassLoader.readToNames(PackagePrivateVisibilityBridgeExtension.class, VisibilityBridge.class, FooBar.class));
    Class<?> type = create(PackagePrivateVisibilityBridgeExtension.class)
            .modifiers(0)
            .make()
            .load(classLoader, InjectionClassLoader.Strategy.INSTANCE)
            .getLoaded();
    assertThat(type.getDeclaredConstructors().length, is(1));
    assertThat(type.getDeclaredMethods().length, is(0));
}
 
Example 14
Source File: AgentBuilderDefaultApplicationSuperTypeLoadingTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER,
            ClassFileLocator.ForClassLoader.readToNames(Foo.class, Bar.class, AgentBuilderDefaultApplicationSuperTypeLoadingTest.class),
            ByteArrayClassLoader.PersistenceHandler.MANIFEST);
    executorService = Executors.newCachedThreadPool();
}
 
Example 15
Source File: MethodDelegationSuperTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testFinalType() throws Exception {
    InjectionClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER,
            false,
            ClassFileLocator.ForClassLoader.readToNames(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, InjectionClassLoader.Strategy.INSTANCE)
            .getLoaded();
    assertThat(type.getDeclaredMethod(BAR).invoke(type.getDeclaredConstructor().newInstance()), is((Object) FOO));
}
 
Example 16
Source File: AgentBuilderRedefinitionStrategyResubmissionStrategyTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testLookupKeyBootstrapLoaderReference() throws Exception {
    AgentBuilder.RedefinitionStrategy.ResubmissionStrategy.Enabled.LookupKey key = new AgentBuilder.RedefinitionStrategy.ResubmissionStrategy.Enabled.LookupKey(ClassLoadingStrategy.BOOTSTRAP_LOADER);
    assertThat(key.hashCode(), is(0));
    AgentBuilder.RedefinitionStrategy.ResubmissionStrategy.Enabled.LookupKey other = new AgentBuilder.RedefinitionStrategy.ResubmissionStrategy.Enabled.LookupKey(new URLClassLoader(new URL[0]));
    System.gc();
    assertThat(key, not(is(other)));
    assertThat(key, is(new AgentBuilder.RedefinitionStrategy.ResubmissionStrategy.Enabled.LookupKey(ClassLoadingStrategy.BOOTSTRAP_LOADER)));
    assertThat(key, is((Object) new AgentBuilder.RedefinitionStrategy.ResubmissionStrategy.Enabled.StorageKey(ClassLoadingStrategy.BOOTSTRAP_LOADER)));
    assertThat(key, not(is((Object) new AgentBuilder.RedefinitionStrategy.ResubmissionStrategy.Enabled.StorageKey(new URLClassLoader(new URL[0])))));
    assertThat(key, is(key));
    assertThat(key, not(is(new Object())));
}
 
Example 17
Source File: TypeDescriptionForLoadedTypeTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
@Test
public void testLazyResolution() throws Exception {
    ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassFileLocator.ForClassLoader.readToNames(Foo.class));
    TypeDescription.ForLoadedType.of(classLoader.loadClass(Foo.class.getName()));
}
 
Example 18
Source File: AbstractDynamicTypeBuilderForInliningTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
@Test
public void testGenericType() throws Exception {
    InjectionClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER,
            false,
            ClassFileLocator.ForClassLoader.readToNames(GenericType.class));
    Class<?> dynamicType = create(GenericType.Inner.class)
            .method(named(FOO)).intercept(StubMethod.INSTANCE)
            .make()
            .load(classLoader, InjectionClassLoader.Strategy.INSTANCE)
            .getLoaded();
    assertThat(dynamicType.getTypeParameters().length, is(2));
    assertThat(dynamicType.getTypeParameters()[0].getName(), is("T"));
    assertThat(dynamicType.getTypeParameters()[0].getBounds().length, is(1));
    assertThat(dynamicType.getTypeParameters()[0].getBounds()[0], instanceOf(Class.class));
    assertThat(dynamicType.getTypeParameters()[0].getBounds()[0], is((Type) String.class));
    assertThat(dynamicType.getTypeParameters()[1].getName(), is("S"));
    assertThat(dynamicType.getTypeParameters()[1].getBounds().length, is(1));
    assertThat(dynamicType.getTypeParameters()[1].getBounds()[0], is((Type) dynamicType.getTypeParameters()[0]));
    assertThat(dynamicType.getGenericSuperclass(), instanceOf(ParameterizedType.class));
    assertThat(((ParameterizedType) dynamicType.getGenericSuperclass()).getActualTypeArguments().length, is(1));
    assertThat(((ParameterizedType) dynamicType.getGenericSuperclass()).getActualTypeArguments()[0], instanceOf(ParameterizedType.class));
    ParameterizedType superClass = (ParameterizedType) ((ParameterizedType) dynamicType.getGenericSuperclass()).getActualTypeArguments()[0];
    assertThat(superClass.getActualTypeArguments().length, is(2));
    assertThat(superClass.getActualTypeArguments()[0], is((Type) dynamicType.getTypeParameters()[0]));
    assertThat(superClass.getActualTypeArguments()[1], is((Type) dynamicType.getTypeParameters()[1]));
    assertThat(superClass.getOwnerType(), instanceOf(ParameterizedType.class));
    assertThat(((ParameterizedType) superClass.getOwnerType()).getRawType(), instanceOf(Class.class));
    assertThat(((Class<?>) ((ParameterizedType) superClass.getOwnerType()).getRawType()).getName(), is(GenericType.class.getName()));
    assertThat(((ParameterizedType) superClass.getOwnerType()).getActualTypeArguments().length, is(1));
    assertThat(((ParameterizedType) superClass.getOwnerType()).getActualTypeArguments()[0],
            is((Type) ((Class<?>) ((ParameterizedType) superClass.getOwnerType()).getRawType()).getTypeParameters()[0]));
    assertThat(dynamicType.getGenericInterfaces().length, is(1));
    assertThat(dynamicType.getGenericInterfaces()[0], instanceOf(ParameterizedType.class));
    assertThat(((ParameterizedType) dynamicType.getGenericInterfaces()[0]).getActualTypeArguments()[0], instanceOf(ParameterizedType.class));
    assertThat(((ParameterizedType) dynamicType.getGenericInterfaces()[0]).getRawType(), is((Type) Callable.class));
    assertThat(((ParameterizedType) dynamicType.getGenericInterfaces()[0]).getOwnerType(), nullValue(Type.class));
    assertThat(((ParameterizedType) ((ParameterizedType) dynamicType.getGenericInterfaces()[0]).getActualTypeArguments()[0])
            .getActualTypeArguments().length, is(2));
    ParameterizedType interfaceType = (ParameterizedType) ((ParameterizedType) dynamicType.getGenericInterfaces()[0]).getActualTypeArguments()[0];
    assertThat(interfaceType.getRawType(), is((Type) Map.class));
    assertThat(interfaceType.getActualTypeArguments().length, is(2));
    assertThat(interfaceType.getActualTypeArguments()[0], instanceOf(WildcardType.class));
    assertThat(((WildcardType) interfaceType.getActualTypeArguments()[0]).getUpperBounds().length, is(1));
    assertThat(((WildcardType) interfaceType.getActualTypeArguments()[0]).getUpperBounds()[0], is((Type) Object.class));
    assertThat(((WildcardType) interfaceType.getActualTypeArguments()[0]).getLowerBounds().length, is(1));
    assertThat(((WildcardType) interfaceType.getActualTypeArguments()[0]).getLowerBounds()[0], is((Type) String.class));
    assertThat(interfaceType.getActualTypeArguments()[1], instanceOf(WildcardType.class));
    assertThat(((WildcardType) interfaceType.getActualTypeArguments()[1]).getUpperBounds().length, is(1));
    assertThat(((WildcardType) interfaceType.getActualTypeArguments()[1]).getUpperBounds()[0], is((Type) String.class));
    assertThat(((WildcardType) interfaceType.getActualTypeArguments()[1]).getLowerBounds().length, is(0));
    Method foo = dynamicType.getDeclaredMethod(FOO, String.class);
    assertThat(foo.getGenericReturnType(), instanceOf(ParameterizedType.class));
    assertThat(((ParameterizedType) foo.getGenericReturnType()).getActualTypeArguments().length, is(1));
    assertThat(((ParameterizedType) foo.getGenericReturnType()).getActualTypeArguments()[0], instanceOf(GenericArrayType.class));
    assertThat(((GenericArrayType) ((ParameterizedType) foo.getGenericReturnType()).getActualTypeArguments()[0]).getGenericComponentType(),
            is((Type) dynamicType.getTypeParameters()[0]));
    assertThat(foo.getTypeParameters().length, is(2));
    assertThat(foo.getTypeParameters()[0].getName(), is("V"));
    assertThat(foo.getTypeParameters()[0].getBounds().length, is(1));
    assertThat(foo.getTypeParameters()[0].getBounds()[0], is((Type) dynamicType.getTypeParameters()[0]));
    assertThat(foo.getTypeParameters()[1].getName(), is("W"));
    assertThat(foo.getTypeParameters()[1].getBounds().length, is(1));
    assertThat(foo.getTypeParameters()[1].getBounds()[0], is((Type) Exception.class));
    assertThat(foo.getGenericParameterTypes().length, is(1));
    assertThat(foo.getGenericParameterTypes()[0], is((Type) foo.getTypeParameters()[0]));
    assertThat(foo.getGenericExceptionTypes().length, is(1));
    assertThat(foo.getGenericExceptionTypes()[0], is((Type) foo.getTypeParameters()[1]));
    Method call = dynamicType.getDeclaredMethod("call");
    assertThat(call.getGenericReturnType(), is((Type) interfaceType));
}
 
Example 19
Source File: AgentBuilderDefaultApplicationResubmissionTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassFileLocator.ForClassLoader.readToNames(SimpleType.class));
}
 
Example 20
Source File: ClassFileLocator.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ClassLoader run() {
    return new URLClassLoader(url, ClassLoadingStrategy.BOOTSTRAP_LOADER);
}