Search in sources :

Example 1 with ParameterList

use of net.bytebuddy.description.method.ParameterList in project byte-buddy by raphw.

the class ImplementationContextDefaultTest method testFieldGetterRegistration.

@Test
public void testFieldGetterRegistration() throws Exception {
    Implementation.Context.Default implementationContext = new Implementation.Context.Default(instrumentedType, classFileVersion, auxiliaryTypeNamingStrategy, typeInitializer, auxiliaryClassFileVersion);
    MethodDescription firstFieldGetter = implementationContext.registerGetterFor(firstField, MethodAccessorFactory.AccessType.DEFAULT);
    assertThat(firstFieldGetter.getParameters(), is((ParameterList) new ParameterList.Empty<ParameterDescription>()));
    assertThat(firstFieldGetter.getReturnType(), is(firstFieldType));
    assertThat(firstFieldGetter.getInternalName(), startsWith(FOO));
    assertThat(firstFieldGetter.getModifiers(), is(accessorMethodModifiers));
    assertThat(firstFieldGetter.getExceptionTypes(), is((TypeList.Generic) new TypeList.Generic.Empty()));
    assertThat(implementationContext.registerGetterFor(firstField, MethodAccessorFactory.AccessType.DEFAULT), is(firstFieldGetter));
    when(secondField.isStatic()).thenReturn(true);
    MethodDescription secondFieldGetter = implementationContext.registerGetterFor(secondField, MethodAccessorFactory.AccessType.DEFAULT);
    assertThat(secondFieldGetter.getParameters(), is((ParameterList) new ParameterList.Empty<ParameterDescription>()));
    assertThat(secondFieldGetter.getReturnType(), is(secondFieldType));
    assertThat(secondFieldGetter.getInternalName(), startsWith(BAR));
    assertThat(secondFieldGetter.getModifiers(), is(accessorMethodModifiers | Opcodes.ACC_STATIC));
    assertThat(secondFieldGetter.getExceptionTypes(), is((TypeList.Generic) new TypeList.Generic.Empty()));
    assertThat(implementationContext.registerGetterFor(firstField, MethodAccessorFactory.AccessType.DEFAULT), is(firstFieldGetter));
    assertThat(implementationContext.registerGetterFor(secondField, MethodAccessorFactory.AccessType.DEFAULT), is(secondFieldGetter));
    implementationContext.drain(drain, classVisitor, annotationValueFilterFactory);
    verify(classVisitor).visitMethod(eq(accessorMethodModifiers), Matchers.startsWith(FOO), eq("()" + BAR), isNull(String.class), isNull(String[].class));
    verify(classVisitor).visitMethod(eq(accessorMethodModifiers | Opcodes.ACC_STATIC), Matchers.startsWith(BAR), eq("()" + QUX), isNull(String.class), isNull(String[].class));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) ParameterList(net.bytebuddy.description.method.ParameterList) ParameterDescription(net.bytebuddy.description.method.ParameterDescription) Test(org.junit.Test)

Aggregations

MethodDescription (net.bytebuddy.description.method.MethodDescription)1 ParameterDescription (net.bytebuddy.description.method.ParameterDescription)1 ParameterList (net.bytebuddy.description.method.ParameterList)1 Test (org.junit.Test)1