use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class TypePoolDefaultWithLazyResolutionTypeDescriptionTest method testGenericSuperInterfaceNavigatedHierarchyResolutionIsLazy.
@Test
public void testGenericSuperInterfaceNavigatedHierarchyResolutionIsLazy() throws Exception {
ClassFileLocator classFileLocator = spy(ClassFileLocator.ForClassLoader.ofClassPath());
assertThat(describe(GenericType.class, classFileLocator, new TypePool.CacheProvider.Simple()).getInterfaces().getOnly().getInterfaces().getOnly().asErasure(), CoreMatchers.is((TypeDescription) new TypeDescription.ForLoadedType(SuperInterface.class)));
verify(classFileLocator).locate(GenericType.class.getName());
verify(classFileLocator).locate(SampleGenericInterface.class.getName());
verifyNoMoreInteractions(classFileLocator);
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class TypePoolDefaultWithLazyResolutionTypeDescriptionTest method testReferencedTypeIsCached.
@Test
public void testReferencedTypeIsCached() throws Exception {
ClassFileLocator classFileLocator = spy(ClassFileLocator.ForClassLoader.ofClassPath());
TypePool typePool = TypePool.Default.WithLazyResolution.of(classFileLocator);
TypePool.Resolution resolution = typePool.describe(String.class.getName());
assertThat(resolution.resolve().getModifiers(), CoreMatchers.is(TypeDescription.STRING.getModifiers()));
TypeDescription superClass = resolution.resolve().getSuperClass().asErasure();
assertThat(superClass, CoreMatchers.is(TypeDescription.OBJECT));
assertThat(superClass.getModifiers(), CoreMatchers.is(TypeDescription.OBJECT.getModifiers()));
assertThat(superClass.getInterfaces(), CoreMatchers.is(TypeDescription.OBJECT.getInterfaces()));
assertThat(typePool.describe(String.class.getName()).resolve(), CoreMatchers.is(resolution.resolve()));
verify(classFileLocator).locate(String.class.getName());
verify(classFileLocator).locate(Object.class.getName());
verifyNoMoreInteractions(classFileLocator);
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.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 org.apache.beam.vendor.bytebuddy.v1_11_0.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 org.apache.beam.vendor.bytebuddy.v1_11_0.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)));
}
Aggregations