use of net.bytebuddy.description.annotation.AnnotationDescription in project byte-buddy by raphw.
the class AnnotationAppenderDefaultTest method makeTypeWithSuperClassAnnotation.
private Class<?> makeTypeWithSuperClassAnnotation(Annotation annotation) throws Exception {
when(valueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true);
ClassWriter classWriter = new ClassWriter(AsmVisitorWrapper.NO_FLAGS);
classWriter.visit(ClassFileVersion.ofThisVm().getMinorMajorVersion(), Opcodes.ACC_PUBLIC, BAR.replace('.', '/'), null, Type.getInternalName(Object.class), null);
AnnotationVisitor annotationVisitor = classWriter.visitTypeAnnotation(TypeReference.newSuperTypeReference(-1).getValue(), null, Type.getDescriptor(annotation.annotationType()), true);
when(target.visit(any(String.class), anyBoolean())).thenReturn(annotationVisitor);
AnnotationDescription annotationDescription = AnnotationDescription.ForLoadedAnnotation.of(annotation);
annotationAppender.append(annotationDescription, valueFilter);
classWriter.visitEnd();
Class<?> bar = new ByteArrayClassLoader(getClass().getClassLoader(), Collections.singletonMap(BAR, classWriter.toByteArray())).loadClass(BAR);
assertThat(bar.getName(), is(BAR));
assertThat(bar.getSuperclass(), CoreMatchers.<Class<?>>is(Object.class));
return bar;
}
use of net.bytebuddy.description.annotation.AnnotationDescription in project byte-buddy by raphw.
the class AnnotationAppenderDefaultTest method testSourceRetentionAnnotation.
@Test
public void testSourceRetentionAnnotation() throws Exception {
AnnotationVisitor annotationVisitor = mock(AnnotationVisitor.class);
when(target.visit(anyString(), anyBoolean())).thenReturn(annotationVisitor);
AnnotationDescription annotationDescription = mock(AnnotationDescription.class);
when(annotationDescription.getRetention()).thenReturn(RetentionPolicy.SOURCE);
annotationAppender.append(annotationDescription, valueFilter);
verifyZeroInteractions(valueFilter);
verifyZeroInteractions(annotationVisitor);
}
use of net.bytebuddy.description.annotation.AnnotationDescription in project byte-buddy by raphw.
the class AnnotationAppenderDefaultTest method testSourceRetentionTypeAnnotation.
@Test
public void testSourceRetentionTypeAnnotation() throws Exception {
AnnotationVisitor annotationVisitor = mock(AnnotationVisitor.class);
when(target.visit(anyString(), anyBoolean())).thenReturn(annotationVisitor);
AnnotationDescription annotationDescription = mock(AnnotationDescription.class);
when(annotationDescription.getRetention()).thenReturn(RetentionPolicy.SOURCE);
annotationAppender.append(annotationDescription, valueFilter, 0, null);
verifyZeroInteractions(valueFilter);
verifyZeroInteractions(annotationVisitor);
}
use of net.bytebuddy.description.annotation.AnnotationDescription 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.annotation.AnnotationDescription in project byte-buddy by raphw.
the class ElementMatchersTest method testAnyOfAnnotation.
@Test
public void testAnyOfAnnotation() throws Exception {
AnnotationDescription annotationDescription = new TypeDescription.ForLoadedType(IsAnnotatedWith.class).getDeclaredAnnotations().ofType(IsAnnotatedWithAnnotation.class);
assertThat(ElementMatchers.anyOf(IsAnnotatedWith.class.getAnnotation(IsAnnotatedWithAnnotation.class)).matches(annotationDescription), is(true));
assertThat(ElementMatchers.anyOf(IsAnnotatedWith.class.getAnnotation(IsAnnotatedWithAnnotation.class), Other.class.getAnnotation(OtherAnnotation.class)).matches(annotationDescription), is(true));
assertThat(ElementMatchers.anyOf(Other.class.getAnnotation(OtherAnnotation.class)).matches(annotationDescription), is(false));
}
Aggregations