Search in sources :

Example 21 with TypeDescription

use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.

the class TransformerForMethodTest method testNoChangesUnlessSpecified.

@Test
public void testNoChangesUnlessSpecified() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(Bar.class);
    MethodDescription methodDescription = typeDescription.getSuperClass().getDeclaredMethods().filter(named(FOO)).getOnly();
    MethodDescription transformed = Transformer.ForMethod.withModifiers().transform(typeDescription, methodDescription);
    assertThat(transformed, is(methodDescription));
    assertThat(transformed.getModifiers(), is(methodDescription.getModifiers()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 22 with TypeDescription

use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.

the class TransformerForMethodTest method testRetainsInstrumentedType.

@Test
public void testRetainsInstrumentedType() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(Bar.class);
    MethodDescription methodDescription = typeDescription.getSuperClass().getDeclaredMethods().filter(named(BAR)).getOnly();
    MethodDescription transformed = Transformer.ForMethod.withModifiers().transform(typeDescription, methodDescription);
    assertThat(transformed, is(methodDescription));
    assertThat(transformed.getModifiers(), is(methodDescription.getModifiers()));
    assertThat(transformed.getReturnType().asErasure(), is(typeDescription));
    assertThat(transformed.getReturnType().getSort(), is(TypeDefinition.Sort.PARAMETERIZED));
    assertThat(transformed.getReturnType().getTypeArguments().size(), is(1));
    assertThat(transformed.getReturnType().getTypeArguments().getOnly(), is(typeDescription.getSuperClass().getDeclaredMethods().filter(named(FOO)).getOnly().getReturnType()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 23 with TypeDescription

use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.

the class InjectionClassLoaderTest method testInjection.

@Test
@SuppressWarnings("unchecked")
public void testInjection() throws Exception {
    InjectionClassLoader classLoader = mock(InjectionClassLoader.class);
    TypeDescription typeDescription = mock(TypeDescription.class);
    byte[] binaryRepresentation = new byte[0];
    when(typeDescription.getName()).thenReturn(FOO);
    when(classLoader.defineClass(FOO, binaryRepresentation)).thenReturn((Class) Object.class);
    assertThat(InjectionClassLoader.Strategy.INSTANCE.load(classLoader, Collections.singletonMap(typeDescription, binaryRepresentation)), is(Collections.<TypeDescription, Class<?>>singletonMap(typeDescription, Object.class)));
    verify(classLoader).defineClass(FOO, binaryRepresentation);
    verifyNoMoreInteractions(classLoader);
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 24 with TypeDescription

use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.

the class ClassFileLocatorSimpleTest method testDynamicType.

@Test
public void testDynamicType() throws Exception {
    DynamicType dynamicType = mock(DynamicType.class);
    TypeDescription typeDescription = mock(TypeDescription.class);
    when(typeDescription.getName()).thenReturn(FOO);
    when(dynamicType.getAllTypes()).thenReturn(Collections.singletonMap(typeDescription, QUX));
    ClassFileLocator classFileLocator = ClassFileLocator.Simple.of(dynamicType);
    assertThat(classFileLocator.locate(FOO).isResolved(), is(true));
    assertThat(classFileLocator.locate(FOO).resolve(), is(QUX));
    assertThat(classFileLocator.locate(BAR).isResolved(), is(false));
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 25 with TypeDescription

use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.

the class AgentBuilderDescriptionStrategyTest method testDescriptionHybridWithoutLoaded.

@Test
public void testDescriptionHybridWithoutLoaded() throws Exception {
    when(typePool.describe(Object.class.getName())).thenReturn(new TypePool.Resolution.Simple(typeDescription));
    TypeDescription typeDescription = AgentBuilder.DescriptionStrategy.Default.HYBRID.apply(Object.class.getName(), null, typePool, mock(AgentBuilder.CircularityLock.class), Object.class.getClassLoader(), JavaModule.ofType(Object.class));
    assertThat(typeDescription, is(this.typeDescription));
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Aggregations

TypeDescription (net.bytebuddy.description.type.TypeDescription)177 Test (org.junit.Test)155 MethodDescription (net.bytebuddy.description.method.MethodDescription)75 ByteBuddy (net.bytebuddy.ByteBuddy)26 DynamicType (net.bytebuddy.dynamic.DynamicType)25 StackManipulation (net.bytebuddy.implementation.bytecode.StackManipulation)17 ClassFileLocator (net.bytebuddy.dynamic.ClassFileLocator)10 AnnotationList (net.bytebuddy.description.annotation.AnnotationList)9 AbstractTypeDescriptionTest (net.bytebuddy.description.type.AbstractTypeDescriptionTest)9 MethodList (net.bytebuddy.description.method.MethodList)8 Field (java.lang.reflect.Field)7 Map (java.util.Map)7 FieldDescription (net.bytebuddy.description.field.FieldDescription)5 LoadedTypeInitializer (net.bytebuddy.implementation.LoadedTypeInitializer)5 Before (org.junit.Before)5 MethodVisitor (org.objectweb.asm.MethodVisitor)5 Serializable (java.io.Serializable)4 URLClassLoader (java.net.URLClassLoader)4 TypeList (net.bytebuddy.description.type.TypeList)4 HashMap (java.util.HashMap)3