Search in sources :

Example 11 with TypeDescription

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

the class TypePoolDefaultLazyTypeContainmentTest method testDeclaredInMethodGetTypeIsNotNull.

@Test
public void testDeclaredInMethodGetTypeIsNotNull() throws Exception {
    TypeDescription typeDescription = mock(TypeDescription.class);
    TypePool typePool = mock(TypePool.class);
    when(typePool.describe(FOO)).thenReturn(new TypePool.Resolution.Simple(typeDescription));
    assertThat(new TypePool.Default.LazyTypeDescription.TypeContainment.WithinMethod(FOO_INTERNAL, BAR, QUX).getEnclosingType(typePool), is(typeDescription));
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 12 with TypeDescription

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

the class TypePoolDefaultLazyTypeContainmentTest method testDeclaredInMethodGetMethodIsNull.

@Test
@SuppressWarnings("unchecked")
public void testDeclaredInMethodGetMethodIsNull() throws Exception {
    MethodDescription methodDescription = mock(MethodDescription.class);
    when(methodDescription.getActualName()).thenReturn(BAR);
    when(methodDescription.getDescriptor()).thenReturn(QUX);
    TypeDescription typeDescription = mock(TypeDescription.class);
    TypePool typePool = mock(TypePool.class);
    when(typePool.describe(FOO)).thenReturn(new TypePool.Resolution.Simple(typeDescription));
    when(typeDescription.getDeclaredMethods()).thenReturn((MethodList) new MethodList.Explicit<MethodDescription>(methodDescription));
    assertThat(new TypePool.Default.LazyTypeDescription.TypeContainment.WithinMethod(FOO_INTERNAL, BAR, QUX).getEnclosingMethod(typePool), is(methodDescription));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 13 with TypeDescription

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

the class TypePoolDefaultLazyTypeContainmentTest method testDeclaredInTypeGetTypeIsNotNull.

@Test
public void testDeclaredInTypeGetTypeIsNotNull() throws Exception {
    TypePool typePool = mock(TypePool.class);
    TypeDescription typeDescription = mock(TypeDescription.class);
    when(typePool.describe(FOO)).thenReturn(new TypePool.Resolution.Simple(typeDescription));
    assertThat(new TypePool.Default.LazyTypeDescription.TypeContainment.WithinType(FOO_INTERNAL, false).getEnclosingType(typePool), is(typeDescription));
    assertThat(new TypePool.Default.LazyTypeDescription.TypeContainment.WithinType(FOO_INTERNAL, true).getEnclosingType(typePool), is(typeDescription));
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 14 with TypeDescription

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

the class TypePoolDefaultWithLazyResolutionTypeDescriptionTest method testGenericSuperInterfaceHierarchyResolutionIsLazy.

@Test
public void testGenericSuperInterfaceHierarchyResolutionIsLazy() throws Exception {
    ClassFileLocator classFileLocator = spy(ClassFileLocator.ForClassLoader.ofClassPath());
    assertThat(describe(GenericType.class, classFileLocator, new TypePool.CacheProvider.Simple()).getInterfaces().getOnly().asErasure(), CoreMatchers.is((TypeDescription) new TypeDescription.ForLoadedType(SampleGenericInterface.class)));
    verify(classFileLocator).locate(GenericType.class.getName());
    verifyNoMoreInteractions(classFileLocator);
}
Also used : ClassFileLocator(net.bytebuddy.dynamic.ClassFileLocator) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test) AbstractTypeDescriptionTest(net.bytebuddy.description.type.AbstractTypeDescriptionTest)

Example 15 with TypeDescription

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

the class RebaseDynamicTypeBuilderTest method testObjectProperties.

@Test
public void testObjectProperties() throws Exception {
    ObjectPropertyAssertion.of(RebaseDynamicTypeBuilder.class).create(new ObjectPropertyAssertion.Creator<List<?>>() {

        @Override
        public List<?> create() {
            TypeDescription typeDescription = mock(TypeDescription.class);
            when(typeDescription.asErasure()).thenReturn(typeDescription);
            return Collections.singletonList(typeDescription);
        }
    }).create(new ObjectPropertyAssertion.Creator<TypeDescription>() {

        @Override
        public TypeDescription create() {
            TypeDescription rawTypeDescription = mock(TypeDescription.class);
            when(rawTypeDescription.asErasure()).thenReturn(rawTypeDescription);
            when(rawTypeDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
            when(rawTypeDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Empty());
            TypeDescription.Generic typeDescription = mock(TypeDescription.Generic.class);
            when(typeDescription.asGenericType()).thenReturn(typeDescription);
            when(typeDescription.asErasure()).thenReturn(rawTypeDescription);
            when(rawTypeDescription.getInterfaces()).thenReturn(new TypeList.Generic.Explicit(typeDescription));
            when(rawTypeDescription.getDeclaredFields()).thenReturn(new FieldList.Empty<FieldDescription.InDefinedShape>());
            when(rawTypeDescription.getDeclaredMethods()).thenReturn(new MethodList.Empty<MethodDescription.InDefinedShape>());
            return rawTypeDescription;
        }
    }).apply();
}
Also used : MethodList(net.bytebuddy.description.method.MethodList) AnnotationList(net.bytebuddy.description.annotation.AnnotationList) FieldList(net.bytebuddy.description.field.FieldList) TypeDescription(net.bytebuddy.description.type.TypeDescription) AnnotationList(net.bytebuddy.description.annotation.AnnotationList) TypeList(net.bytebuddy.description.type.TypeList) MethodList(net.bytebuddy.description.method.MethodList) List(java.util.List) FieldList(net.bytebuddy.description.field.FieldList) ObjectPropertyAssertion(net.bytebuddy.test.utility.ObjectPropertyAssertion) 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