use of org.jboss.weld.literal.NamedLiteral in project core by weld.
the class CreateBeanAttributesTest method testBeanAttributesForManagedBeanWithModifiedAnnotatedType.
@Test
public void testBeanAttributesForManagedBeanWithModifiedAnnotatedType() {
AnnotatedType<Mountain> type = manager.createAnnotatedType(Mountain.class);
AnnotatedType<Mountain> wrappedType = new WrappedAnnotatedType<Mountain>(type, new NamedLiteral("Mount Blanc"));
BeanAttributes<Mountain> attributes = manager.createBeanAttributes(wrappedType);
verifyTypes(attributes, Mountain.class, Landmark.class, Object.class);
assertTrue(attributes.getStereotypes().isEmpty());
verifyQualifierTypes(attributes, Named.class, Any.class, Default.class);
assertEquals(Dependent.class, attributes.getScope());
assertEquals("Mount Blanc", attributes.getName());
assertFalse(attributes.isAlternative());
}
use of org.jboss.weld.literal.NamedLiteral in project core by weld.
the class DummyExtension method replaceObserverMethod.
void replaceObserverMethod(@Observes ProcessObserverMethod<Number, ?> event) {
if (!checkExperimentalObserver(event.getObserverMethod().getObservedQualifiers())) {
return;
}
// first, verify getBeanClass() check
ObserverMethod<Number> wrongObserver = new ForwardingObserverMethod<Number>(event.getObserverMethod()) {
@Override
public Class<?> getBeanClass() {
return Number.class;
}
};
try {
event.setObserverMethod(wrongObserver);
throw new RuntimeException("Expected exception not thrown");
} catch (DefinitionException expected) {
}
ObserverMethod<Number> replacement = new ForwardingObserverMethod<Number>(event.getObserverMethod()) {
@Override
public Type getObservedType() {
return Integer.class;
}
@Override
public Set<Annotation> getObservedQualifiers() {
Set<Annotation> qualifiers = new HashSet<>(delegate().getObservedQualifiers());
qualifiers.add(new NamedLiteral("experimental"));
return qualifiers;
}
};
event.setObserverMethod(replacement);
}
use of org.jboss.weld.literal.NamedLiteral in project core by weld.
the class ExperimentalProcessObserverMethodTest method testReplacingObserverMethod.
@Test
public void testReplacingObserverMethod() {
@SuppressWarnings("serial") final Number number = new Number() {
@Override
public long longValue() {
return 0L;
}
@Override
public int intValue() {
return 0;
}
@Override
public float floatValue() {
return 0F;
}
@Override
public double doubleValue() {
return 0D;
}
};
Assert.assertEquals(0, manager.resolveObserverMethods(number, Experimental.Literal.INSTANCE).size());
Assert.assertEquals(0, manager.resolveObserverMethods(number, Experimental.Literal.INSTANCE, new NamedLiteral("experimental")).size());
Assert.assertEquals(0, manager.resolveObserverMethods(0, Experimental.Literal.INSTANCE).size());
Assert.assertEquals(1, manager.resolveObserverMethods(0, Experimental.Literal.INSTANCE, new NamedLiteral("experimental")).size());
}
use of org.jboss.weld.literal.NamedLiteral in project core by weld.
the class SpecializationTest method validateCharlie.
private void validateCharlie(BeanAttributes<?> attributes) {
verifyQualifiers(attributes, Foo.Literal.INSTANCE, Bar.Literal.INSTANCE, Baz.Literal.INSTANCE, Any.Literal.INSTANCE, new NamedLiteral("alpha"));
assertEquals("alpha", attributes.getName());
}
use of org.jboss.weld.literal.NamedLiteral in project core by weld.
the class ModifyingExtension method registerAdditionalFooAnnotatedType.
public void registerAdditionalFooAnnotatedType(@Observes BeforeBeanDiscovery event, BeanManager manager) {
final AnnotatedType<Foo> anotherFoo = manager.createAnnotatedType(Foo.class);
AnnotatedType<Foo> modifiedAnotherFoo = new ForwardingAnnotatedType<Foo>() {
private final NamedLiteral qualifierInstance = new NamedLiteral("anotherFoo");
@Override
public AnnotatedType<Foo> delegate() {
return anotherFoo;
}
@Override
public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
if (Named.class.equals(annotationType)) {
return cast(qualifierInstance);
}
return null;
}
@Override
public Set<Annotation> getAnnotations() {
return Collections.<Annotation>singleton(qualifierInstance);
}
@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
return Named.class.equals(annotationType);
}
};
event.addAnnotatedType(modifiedAnotherFoo);
}
Aggregations