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);
}
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();
}
use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class RedefinitionDynamicTypeBuilderTest method testObjectProperties.
@Test
@SuppressWarnings("unchecked")
public void testObjectProperties() throws Exception {
ObjectPropertyAssertion.of(RedefinitionDynamicTypeBuilder.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.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
when(rawTypeDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Empty());
TypeDescription.Generic typeDescription = mock(TypeDescription.Generic.class);
when(typeDescription.asErasure()).thenReturn(rawTypeDescription);
when(typeDescription.asGenericType()).thenReturn(typeDescription);
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();
}
use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class ImplementationSpecialMethodInvocationSimpleTest method testEquality.
@Test
public void testEquality() throws Exception {
MethodDescription firstMethod = mock(MethodDescription.class), secondMethod = mock(MethodDescription.class);
MethodDescription.SignatureToken firstToken = mock(MethodDescription.SignatureToken.class), secondToken = mock(MethodDescription.SignatureToken.class);
when(firstMethod.asSignatureToken()).thenReturn(firstToken);
when(secondMethod.asSignatureToken()).thenReturn(secondToken);
TypeDescription firstType = mock(TypeDescription.class), secondType = mock(TypeDescription.class);
assertThat(new Implementation.SpecialMethodInvocation.Simple(firstMethod, firstType, mock(StackManipulation.class)), is(new Implementation.SpecialMethodInvocation.Simple(firstMethod, firstType, mock(StackManipulation.class))));
assertThat(new Implementation.SpecialMethodInvocation.Simple(firstMethod, firstType, mock(StackManipulation.class)), not(new Implementation.SpecialMethodInvocation.Simple(secondMethod, firstType, mock(StackManipulation.class))));
assertThat(new Implementation.SpecialMethodInvocation.Simple(firstMethod, firstType, mock(StackManipulation.class)), not(new Implementation.SpecialMethodInvocation.Simple(firstMethod, secondType, mock(StackManipulation.class))));
}
use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class InvokeDynamicTest method testChainedInvocation.
@Test
@JavaVersionRule.Enforce(7)
public void testChainedInvocation() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(Class.forName(ARGUMENT_BOOTSTRAP));
DynamicType.Loaded<SimpleWithArgument> dynamicType = new ByteBuddy().subclass(SimpleWithArgument.class).method(isDeclaredBy(SimpleWithArgument.class)).intercept(InvokeDynamic.bootstrap(typeDescription.getDeclaredMethods().filter(named(BOOTSTRAP)).getOnly()).invoke(QUX, String.class).withArgument(0).andThen(FixedValue.value(BAZ))).make().load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
assertThat(dynamicType.getLoaded().getDeclaredFields().length, is(0));
assertThat(dynamicType.getLoaded().getDeclaredConstructor().newInstance().foo(FOO), is(BAZ));
}
Aggregations