use of org.apache.deltaspike.core.api.literal.ApplicationScopedLiteral in project deltaspike by apache.
the class AnnotatedTypeBuilderTest method testTypeLevelAnnotationRedefinition.
@Test
public void testTypeLevelAnnotationRedefinition() {
AnnotatedTypeBuilder<Cat> builder = new AnnotatedTypeBuilder<Cat>();
builder.readFromType(Cat.class);
AnnotatedType<Cat> cat = builder.create();
assertNotNull(cat);
assertNotNull(cat.getAnnotation(Named.class));
assertEquals("cat", cat.getAnnotation(Named.class).value());
builder.addToClass(new AlternativeLiteral()).addToClass(new ApplicationScopedLiteral()).removeFromClass(Named.class).addToClass(new NamedLiteral("tomcat"));
cat = builder.create();
assertNotNull(cat);
assertEquals(3, cat.getAnnotations().size());
assertTrue(cat.isAnnotationPresent(Named.class));
assertTrue(cat.isAnnotationPresent(Alternative.class));
assertTrue(cat.isAnnotationPresent(ApplicationScoped.class));
assertEquals("tomcat", cat.getAnnotation(Named.class).value());
AnnotatedMethod observerMethod = null;
for (AnnotatedMethod m : cat.getMethods()) {
if ("doSomeObservation".equals(m.getJavaMember().getName())) {
observerMethod = m;
break;
}
}
assertNotNull(observerMethod);
observerMethod.isAnnotationPresent(Observes.class);
{
// test reading from an AnnotatedType
AnnotatedTypeBuilder<Cat> builder2 = new AnnotatedTypeBuilder<Cat>();
builder2.readFromType(cat);
builder2.removeFromAll(Named.class);
final AnnotatedType<Cat> noNameCat = builder2.create();
assertFalse(noNameCat.isAnnotationPresent(Named.class));
assertEquals(2, noNameCat.getAnnotations().size());
}
{
// test reading from an AnnotatedType in non-overwrite mode
AnnotatedTypeBuilder<Cat> builder3 = new AnnotatedTypeBuilder<Cat>();
builder3.readFromType(cat, true);
builder3.removeFromAll(Named.class);
builder3.readFromType(cat, false);
final AnnotatedType<Cat> namedCat = builder3.create();
assertTrue(namedCat.isAnnotationPresent(Named.class));
assertEquals(3, namedCat.getAnnotations().size());
}
}
Aggregations