use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class TargetMethodAnnotationDrivenBinderTest method setUp.
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
when(assignmentBinding.apply(any(MethodVisitor.class), any(Implementation.Context.class))).thenReturn(new StackManipulation.Size(0, 0));
when(assigner.assign(any(TypeDescription.Generic.class), any(TypeDescription.Generic.class), any(Assigner.Typing.class))).thenReturn(assignmentBinding);
when(methodInvoker.invoke(any(MethodDescription.class))).thenReturn(methodInvocation);
when(methodInvocation.apply(any(MethodVisitor.class), any(Implementation.Context.class))).thenReturn(new StackManipulation.Size(0, 0));
when(assignmentBinding.apply(any(MethodVisitor.class), any(Implementation.Context.class))).thenReturn(new StackManipulation.Size(0, 0));
TypeDescription declaringType = mock(TypeDescription.class);
when(declaringType.getInternalName()).thenReturn(FOO);
when(declaringType.isInterface()).thenReturn(false);
when(targetMethod.getInternalName()).thenReturn(BAR);
when(targetMethod.isStatic()).thenReturn(true);
when(targetMethod.getDeclaringType()).thenReturn(declaringType);
when(targetMethod.getDescriptor()).thenReturn(BAZ);
when(firstParameter.getDeclaringMethod()).thenReturn(targetMethod);
when(firstParameter.getIndex()).thenReturn(0);
when(secondParameter.getDeclaringMethod()).thenReturn(targetMethod);
when(secondParameter.getIndex()).thenReturn(1);
when(targetMethod.getParameters()).thenReturn((ParameterList) new ParameterList.Explicit<ParameterDescription>(firstParameter, secondParameter));
when(firstPseudoAnnotation.getAnnotationType()).thenReturn(new TypeDescription.ForLoadedType(FirstPseudoAnnotation.class));
when(firstPseudoAnnotation.prepare(FirstPseudoAnnotation.class)).thenReturn(firstPseudoAnnotation);
when(secondPseudoAnnotation.getAnnotationType()).thenReturn(new TypeDescription.ForLoadedType(SecondPseudoAnnotation.class));
when(secondPseudoAnnotation.prepare(SecondPseudoAnnotation.class)).thenReturn(secondPseudoAnnotation);
when(sourceTypeDescription.getStackSize()).thenReturn(StackSize.ZERO);
when(targetTypeDescription.getStackSize()).thenReturn(StackSize.ZERO);
when(sourceMethod.getReturnType()).thenReturn(sourceTypeDescription);
when(targetMethod.getReturnType()).thenReturn(targetTypeDescription);
when(terminationHandler.resolve(assigner, typing, sourceMethod, targetMethod)).thenReturn(termination);
when(termination.apply(any(MethodVisitor.class), any(Implementation.Context.class))).thenReturn(new StackManipulation.Size(0, 0));
when(implementationTarget.getInstrumentedType()).thenReturn(instrumentedType);
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class MethodBindingBuilderTest method setUp.
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
when(methodDescription.getParameters()).thenReturn((ParameterList) methodParameterList);
when(methodDescription.isStatic()).thenReturn(false);
TypeDescription declaringType = mock(TypeDescription.class);
when(methodDescription.getDeclaringType()).thenReturn(declaringType);
when(declaringType.getInternalName()).thenReturn(FOO);
when(declaringType.isInterface()).thenReturn(false);
when(methodDescription.getInternalName()).thenReturn(BAR);
when(methodDescription.getDescriptor()).thenReturn(BAZ);
when(methodDescription.getStackSize()).thenReturn(0);
when(methodDescription.getReturnType()).thenReturn(returnType);
when(returnType.getStackSize()).thenReturn(StackSize.ZERO);
when(legalStackManipulation.isValid()).thenReturn(true);
when(illegalStackManipulation.isValid()).thenReturn(false);
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class AllArgumentsBinderTest method testNonArrayTypeBinding.
@Test(expected = IllegalStateException.class)
public void testNonArrayTypeBinding() throws Exception {
when(target.getIndex()).thenReturn(0);
TypeDescription.Generic targetType = mock(TypeDescription.Generic.class);
TypeDescription rawTargetType = mock(TypeDescription.class);
when(targetType.asErasure()).thenReturn(rawTargetType);
when(targetType.isArray()).thenReturn(false);
when(target.getType()).thenReturn(targetType);
AllArguments.Binder.INSTANCE.bind(annotationDescription, source, target, implementationTarget, assigner, Assigner.Typing.STATIC);
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class FieldProxyBinderTest method testIllegalType.
@Test(expected = IllegalStateException.class)
public void testIllegalType() throws Exception {
doReturn(Foo.class).when(annotation).declaringType();
when(annotation.value()).thenReturn(FOO);
TypeDescription targetType = mock(TypeDescription.class);
TypeDescription.Generic genericTargetType = mock(TypeDescription.Generic.class);
when(genericTargetType.asErasure()).thenReturn(targetType);
when(target.getType()).thenReturn(genericTargetType);
when(instrumentedType.isAssignableTo(new TypeDescription.ForLoadedType(Foo.class))).thenReturn(true);
new FieldProxy.Binder(getterMethod, setterMethod).bind(annotationDescription, source, target, implementationTarget, assigner, Assigner.Typing.STATIC);
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class MorphBinderTest method testObjectProperties.
@Test
@SuppressWarnings("unchecked")
public void testObjectProperties() throws Exception {
ObjectPropertyAssertion.of(Morph.Binder.class).apply();
ObjectPropertyAssertion.of(Morph.Binder.RedirectionProxy.class).apply();
ObjectPropertyAssertion.of(Morph.Binder.RedirectionProxy.MethodCall.class).apply();
ObjectPropertyAssertion.of(Morph.Binder.RedirectionProxy.MethodCall.Appender.class).refine(new ObjectPropertyAssertion.Refinement<Implementation.Target>() {
@Override
public void apply(Implementation.Target mock) {
when(mock.getInstrumentedType()).thenReturn(mock(TypeDescription.class));
}
}).apply();
ObjectPropertyAssertion.of(Morph.Binder.RedirectionProxy.StaticFieldConstructor.class).apply();
ObjectPropertyAssertion.of(Morph.Binder.RedirectionProxy.InstanceFieldConstructor.class).apply();
ObjectPropertyAssertion.of(Morph.Binder.RedirectionProxy.InstanceFieldConstructor.Appender.class).refine(new ObjectPropertyAssertion.Refinement<Implementation.Target>() {
@Override
public void apply(Implementation.Target mock) {
TypeDescription typeDescription = mock(TypeDescription.class);
FieldList<?> fieldList = mock(FieldList.class);
FieldList<?> filteredFieldList = mock(FieldList.class);
when(fieldList.filter(named(Morph.Binder.RedirectionProxy.FIELD_NAME))).thenReturn((FieldList) filteredFieldList);
when(filteredFieldList.getOnly()).thenReturn(mock(FieldDescription.class));
when(typeDescription.getDeclaredFields()).thenReturn((FieldList) fieldList);
when(mock.getInstrumentedType()).thenReturn(typeDescription);
}
}).apply();
ObjectPropertyAssertion.of(Morph.Binder.DefaultMethodLocator.Implicit.class).apply();
ObjectPropertyAssertion.of(Morph.Binder.DefaultMethodLocator.Explicit.class).apply();
}
Aggregations