Search in sources :

Example 96 with MethodDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class TypeProxyCreationTest method testAllLegalSerializable.

@Test
public void testAllLegalSerializable() throws Exception {
    when(implementationTarget.getInstrumentedType()).thenReturn(foo);
    when(invocationFactory.invoke(eq(implementationTarget), eq(foo), any(MethodDescription.class))).thenReturn(specialMethodInvocation);
    when(specialMethodInvocation.isValid()).thenReturn(true);
    when(specialMethodInvocation.apply(any(MethodVisitor.class), any(Implementation.Context.class))).thenReturn(new StackManipulation.Size(0, 0));
    when(methodAccessorFactory.registerAccessorFor(specialMethodInvocation, MethodAccessorFactory.AccessType.DEFAULT)).thenReturn(proxyMethod);
    TypeDescription dynamicType = new TypeProxy(foo, implementationTarget, invocationFactory, true, true).make(BAR, ClassFileVersion.ofThisVm(), methodAccessorFactory).getTypeDescription();
    assertThat(dynamicType.getModifiers(), is(modifiers));
    assertThat(dynamicType.getSuperClass().asErasure(), is(foo));
    assertThat(dynamicType.getInterfaces(), is((TypeList.Generic) new TypeList.Generic.ForLoadedTypes(Serializable.class)));
    assertThat(dynamicType.getName(), is(BAR));
    assertThat(dynamicType.getDeclaredMethods().size(), is(2));
    assertThat(dynamicType.isAssignableTo(Serializable.class), is(true));
    verify(methodAccessorFactory, times(fooMethods.size())).registerAccessorFor(specialMethodInvocation, MethodAccessorFactory.AccessType.DEFAULT);
    for (MethodDescription methodDescription : fooMethods) {
        verify(invocationFactory).invoke(implementationTarget, foo, methodDescription);
    }
    verifyNoMoreInteractions(invocationFactory);
    verify(specialMethodInvocation, times(fooMethods.size())).isValid();
    verifyNoMoreInteractions(specialMethodInvocation);
}
Also used : Serializable(java.io.Serializable) MethodDescription(net.bytebuddy.description.method.MethodDescription) StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) TypeDescription(net.bytebuddy.description.type.TypeDescription) MethodVisitor(org.objectweb.asm.MethodVisitor) Test(org.junit.Test)

Example 97 with MethodDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class AnnotationValueFilterDefaultTest method testAppendsDefaults.

@Test
public void testAppendsDefaults() throws Exception {
    AnnotationDescription annotationDescription = mock(AnnotationDescription.class);
    MethodDescription.InDefinedShape methodDescription = mock(MethodDescription.InDefinedShape.class);
    assertThat(AnnotationValueFilter.Default.APPEND_DEFAULTS.isRelevant(annotationDescription, methodDescription), is(true));
    verifyZeroInteractions(annotationDescription);
    verifyZeroInteractions(methodDescription);
}
Also used : AnnotationDescription(net.bytebuddy.description.annotation.AnnotationDescription) MethodDescription(net.bytebuddy.description.method.MethodDescription) Test(org.junit.Test)

Example 98 with MethodDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class ElementMatchersTest method testIsSynchronized.

@Test
public void testIsSynchronized() throws Exception {
    MethodDescription methodDescription = mock(MethodDescription.class);
    when(methodDescription.getModifiers()).thenReturn(Opcodes.ACC_SYNCHRONIZED);
    assertThat(ElementMatchers.isSynchronized().matches(methodDescription), is(true));
    assertThat(ElementMatchers.isSynchronized().matches(mock(MethodDescription.class)), is(false));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) Test(org.junit.Test)

Example 99 with MethodDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class ElementMatchersTest method testIsBridge.

@Test
public void testIsBridge() throws Exception {
    MethodDescription modifierReviewable = mock(MethodDescription.class);
    when(modifierReviewable.getModifiers()).thenReturn(Opcodes.ACC_BRIDGE);
    assertThat(ElementMatchers.isBridge().matches(modifierReviewable), is(true));
    assertThat(ElementMatchers.isBridge().matches(mock(MethodDescription.class)), is(false));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) Test(org.junit.Test)

Example 100 with MethodDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class ElementMatchersTest method testIsConstructorDefinedShape.

@Test
public void testIsConstructorDefinedShape() throws Exception {
    Constructor<?> constructor = GenericConstructorType.class.getDeclaredConstructor(Exception.class);
    MethodDescription methodDescription = new TypeDescription.ForLoadedType(GenericConstructorType.Inner.class).getSuperClass().getDeclaredMethods().filter(isConstructor()).getOnly();
    assertThat(ElementMatchers.is(constructor).matches(methodDescription), is(true));
    assertThat(ElementMatchers.definedMethod(ElementMatchers.is(methodDescription.asDefined())).matches(methodDescription), is(true));
    assertThat(ElementMatchers.is(methodDescription.asDefined()).matches(methodDescription.asDefined()), is(true));
    assertThat(ElementMatchers.is(methodDescription.asDefined()).matches(methodDescription), is(true));
    assertThat(ElementMatchers.is(methodDescription).matches(methodDescription.asDefined()), is(false));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) Test(org.junit.Test)

Aggregations

MethodDescription (net.bytebuddy.description.method.MethodDescription)105 Test (org.junit.Test)102 TypeDescription (net.bytebuddy.description.type.TypeDescription)62 MethodVisitor (org.objectweb.asm.MethodVisitor)15 StackManipulation (net.bytebuddy.implementation.bytecode.StackManipulation)12 MethodList (net.bytebuddy.description.method.MethodList)9 Implementation (net.bytebuddy.implementation.Implementation)8 AbstractImplementationTargetTest (net.bytebuddy.implementation.AbstractImplementationTargetTest)6 Serializable (java.io.Serializable)4 TypeVariableSource (net.bytebuddy.description.TypeVariableSource)4 FieldList (net.bytebuddy.description.field.FieldList)4 TypePool (net.bytebuddy.pool.TypePool)4 ClassVisitor (org.objectweb.asm.ClassVisitor)4 ByteBuddy (net.bytebuddy.ByteBuddy)3 DynamicType (net.bytebuddy.dynamic.DynamicType)3 AnnotationDescription (net.bytebuddy.description.annotation.AnnotationDescription)2 LoadedTypeInitializer (net.bytebuddy.implementation.LoadedTypeInitializer)2 ByteCodeAppender (net.bytebuddy.implementation.bytecode.ByteCodeAppender)2 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1