use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class TypePoolDefaultCacheTest method testCache.
@Test
public void testCache() throws Exception {
TypePool typePool = TypePool.Default.ofClassPath();
TypeDescription typeDescription = typePool.describe(Void.class.getName()).resolve();
assertThat(typePool.describe(Void.class.getName()).resolve(), sameInstance(typeDescription));
typePool.clear();
assertThat(typePool.describe(Void.class.getName()).resolve(), not(sameInstance(typeDescription)));
}
use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class TypePoolDefaultComponentPoolStrategyTest method testForAnnotationProperty.
@Test
public void testForAnnotationProperty() throws Exception {
TypePool typePool = mock(TypePool.class);
TypeDescription typeDescription = mock(TypeDescription.class);
when(typePool.describe(BAR)).thenReturn(new TypePool.Resolution.Simple(typeDescription));
MethodDescription.InDefinedShape methodDescription = mock(MethodDescription.InDefinedShape.class);
when(typeDescription.getDeclaredMethods()).thenReturn(new MethodList.Explicit<MethodDescription.InDefinedShape>(methodDescription));
when(methodDescription.getActualName()).thenReturn(FOO);
TypeDescription.Generic returnType = mock(TypeDescription.Generic.class);
TypeDescription rawReturnType = mock(TypeDescription.class);
when(returnType.asErasure()).thenReturn(rawReturnType);
when(methodDescription.getReturnType()).thenReturn(returnType);
TypeDescription rawComponentType = mock(TypeDescription.class);
when(rawReturnType.getComponentType()).thenReturn(rawComponentType);
when(rawComponentType.getName()).thenReturn(QUX);
assertThat(new TypePool.Default.ComponentTypeLocator.ForAnnotationProperty(typePool, BAR_DESCRIPTOR).bind(FOO).lookup(), is(QUX));
}
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));
}
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));
}
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));
}
Aggregations