use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class MethodAttributeAppenderForInstrumentedMethodOtherTest method testIncludingFactory.
@Test
public void testIncludingFactory() throws Exception {
TypeDescription typeDescription = mock(TypeDescription.class);
assertThat(MethodAttributeAppender.ForInstrumentedMethod.INCLUDING_RECEIVER.make(typeDescription), is((MethodAttributeAppender) MethodAttributeAppender.ForInstrumentedMethod.INCLUDING_RECEIVER));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class MethodAttributeAppenderForInstrumentedMethodTest method testJdkTypeIsFiltered.
@Test
@SuppressWarnings("unchecked")
public void testJdkTypeIsFiltered() throws Exception {
when(annotationValueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true);
AnnotationDescription annotationDescription = mock(AnnotationDescription.class);
TypeDescription annotationType = mock(TypeDescription.class);
when(annotationType.getDeclaredMethods()).thenReturn(new MethodList.Empty<MethodDescription.InDefinedShape>());
when(annotationDescription.getRetention()).thenReturn(RetentionPolicy.RUNTIME);
when(annotationDescription.getAnnotationType()).thenReturn(annotationType);
when(annotationType.getActualName()).thenReturn("jdk.internal.Sample");
when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Explicit(annotationDescription));
when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<ParameterDescription>());
when(methodDescription.getReturnType()).thenReturn(TypeDescription.Generic.VOID);
when(methodDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Empty());
when(methodDescription.getExceptionTypes()).thenReturn(new TypeList.Generic.Empty());
methodAttributeAppender.apply(methodVisitor, methodDescription, annotationValueFilter);
verifyZeroInteractions(methodVisitor);
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class InvokeDynamicTest method testNegativeArgumentThrowsException.
@Test(expected = IllegalArgumentException.class)
@JavaVersionRule.Enforce(7)
public void testNegativeArgumentThrowsException() throws Exception {
Class<?> type = Class.forName(ARGUMENT_BOOTSTRAP);
TypeDescription typeDescription = new TypeDescription.ForLoadedType(type);
InvokeDynamic.bootstrap(typeDescription.getDeclaredMethods().filter(named(BOOTSTRAP)).getOnly()).invoke(QUX, String.class).withArgument(-1);
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class InvokeDynamicTest method testBootstrapFieldNotAssignable.
@Test(expected = IllegalStateException.class)
@JavaVersionRule.Enforce(7)
public void testBootstrapFieldNotAssignable() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(Class.forName(ARGUMENT_BOOTSTRAP));
new ByteBuddy().subclass(Simple.class).defineField(FOO, Object.class).method(isDeclaredBy(Simple.class)).intercept(InvokeDynamic.bootstrap(typeDescription.getDeclaredMethods().filter(named(BOOTSTRAP)).getOnly()).invoke(QUX, String.class).withField(FOO).as(String.class)).make();
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class InvokeDynamicTest method testBootstrapWithArrayArgumentsWithoutArguments.
@Test
@JavaVersionRule.Enforce(7)
public void testBootstrapWithArrayArgumentsWithoutArguments() throws Exception {
Class<?> type = Class.forName(PARAMETER_BOOTSTRAP);
Field field = type.getDeclaredField(ARGUMENTS_FIELD_NAME);
field.set(null, null);
TypeDescription typeDescription = new TypeDescription.ForLoadedType(type);
DynamicType.Loaded<Simple> dynamicType = new ByteBuddy().subclass(Simple.class).method(isDeclaredBy(Simple.class)).intercept(InvokeDynamic.bootstrap(typeDescription.getDeclaredMethods().filter(named(BOOTSTRAP_ARRAY_ARGUMENTS)).getOnly()).withoutArguments()).make().load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
assertThat(dynamicType.getLoaded().getDeclaredConstructor().newInstance().foo(), is(FOO));
Object[] arguments = (Object[]) field.get(null);
assertThat(arguments.length, is(0));
}
Aggregations