use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class TypePoolResolutionTest method testArrayResolutionPositiveArity.
@Test
public void testArrayResolutionPositiveArity() throws Exception {
TypePool.Resolution resolution = mock(TypePool.Resolution.class);
when(resolution.isResolved()).thenReturn(true);
when(resolution.resolve()).thenReturn(mock(TypeDescription.class));
assertThat(TypePool.Default.ArrayTypeResolution.of(resolution, 1), not(resolution));
TypeDescription typeDescription = TypePool.Default.ArrayTypeResolution.of(resolution, 1).resolve();
assertThat(typeDescription.isArray(), is(true));
}
use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class JavaConstantMethodHandleTest method testMethodNotSpecializable.
@Test(expected = IllegalArgumentException.class)
public void testMethodNotSpecializable() throws Exception {
MethodDescription.InDefinedShape methodDescription = mock(MethodDescription.InDefinedShape.class);
TypeDescription typeDescription = mock(TypeDescription.class);
when(methodDescription.isSpecializableFor(typeDescription)).thenReturn(false);
JavaConstant.MethodHandle.ofSpecial(methodDescription, typeDescription);
}
use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class JavaConstantMethodHandleTest method testMethodHandleOfLoadedMethodHandle.
@Test
@SuppressWarnings("unchecked")
@JavaVersionRule.Enforce(value = 7, hotSpot = 7)
public void testMethodHandleOfLoadedMethodHandle() throws Exception {
Method publicLookup = Class.forName("java.lang.invoke.MethodHandles").getDeclaredMethod("publicLookup");
Object lookup = publicLookup.invoke(null);
Method unreflected = Class.forName("java.lang.invoke.MethodHandles$Lookup").getDeclaredMethod("unreflect", Method.class);
Object methodHandleLoaded = unreflected.invoke(lookup, Foo.class.getDeclaredMethod(BAR, Void.class));
JavaConstant.MethodHandle methodHandle = JavaConstant.MethodHandle.ofLoaded(methodHandleLoaded);
assertThat(methodHandle.getHandleType(), is(JavaConstant.MethodHandle.HandleType.INVOKE_VIRTUAL));
assertThat(methodHandle.getName(), is(BAR));
assertThat(methodHandle.getOwnerType(), is((TypeDescription) new TypeDescription.ForLoadedType(Foo.class)));
assertThat(methodHandle.getReturnType(), is(TypeDescription.VOID));
assertThat(methodHandle.getParameterTypes(), is((List<TypeDescription>) new TypeList.ForLoadedTypes(Void.class)));
}
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));
}
Aggregations