use of 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);
}
use of 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);
}
use of 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));
}
use of 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));
}
use of 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));
}
Aggregations