Skip to content

Commit 81ecb21

Browse files
author
Rafael Winterhalter
committed
Added additional test for interception.
1 parent 4db0bcf commit 81ecb21

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/scaffold/subclass/SubclassDynamicTypeBuilderTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ public void testAnnotationTypeOnSuperClass() throws Exception {
513513
@Test
514514
@JavaVersionRule.Enforce(8)
515515
@SuppressWarnings("unchecked")
516-
public void testReceiverType() throws Exception {
516+
public void testReceiverTypeDefinition() throws Exception {
517517
Class<? extends Annotation> typeAnnotationType = (Class<? extends Annotation>) Class.forName(TYPE_VARIABLE_NAME);
518518
MethodDescription.InDefinedShape value = new TypeDescription.ForLoadedType(typeAnnotationType).getDeclaredMethods().filter(named(VALUE)).getOnly();
519519
Method method = createPlain()
@@ -531,6 +531,27 @@ public void testReceiverType() throws Exception {
531531
.ofType(typeAnnotationType).getValue(value, Integer.class), is(BAZ));
532532
}
533533

534+
@Test
535+
@JavaVersionRule.Enforce(8)
536+
@SuppressWarnings("unchecked")
537+
public void testReceiverTypeInterception() throws Exception {
538+
Class<? extends Annotation> typeAnnotationType = (Class<? extends Annotation>) Class.forName(TYPE_VARIABLE_NAME);
539+
MethodDescription.InDefinedShape value = new TypeDescription.ForLoadedType(typeAnnotationType).getDeclaredMethods().filter(named(VALUE)).getOnly();
540+
Method method = createPlain()
541+
.method(named("toString"))
542+
.intercept(StubMethod.INSTANCE)
543+
.receiverType(TypeDescription.Generic.Builder.rawType(TargetType.class)
544+
.annotate(AnnotationDescription.Builder.ofType(typeAnnotationType).define(VALUE, BAZ).build())
545+
.build())
546+
.make()
547+
.load(typeAnnotationType.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
548+
.getLoaded()
549+
.getDeclaredMethod("toString");
550+
assertThat(TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveReceiverType(method).getDeclaredAnnotations().size(), is(1));
551+
assertThat(TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveReceiverType(method).getDeclaredAnnotations()
552+
.ofType(typeAnnotationType).getValue(value, Integer.class), is(BAZ));
553+
}
554+
534555
@Test
535556
public void testObjectProperties() throws Exception {
536557
ObjectPropertyAssertion.of(SubclassDynamicTypeBuilder.class).create(new ObjectPropertyAssertion.Creator<List<?>>() {

0 commit comments

Comments
 (0)