use of org.jboss.weld.inject.WeldInstance.Handler in project core by weld.
the class WeldInstanceTest method testHandlers.
@Test
public void testHandlers() {
ActionSequence.reset();
try (WeldContainer container = new Weld().initialize()) {
WeldInstance<Processor> instance = container.select(Processor.class);
assertTrue(instance.isAmbiguous());
for (Handler<Processor> handler : instance.handlers()) {
handler.get().ping();
if (handler.getBean().getScope().equals(Dependent.class)) {
handler.destroy();
}
}
assertEquals(3, ActionSequence.getSequenceSize());
ActionSequence.assertSequenceDataContainsAll("firstPing", "secondPing", "firstDestroy");
ActionSequence.reset();
assertTrue(instance.isAmbiguous());
for (Iterator<Handler<Processor>> iterator = instance.handlers().iterator(); iterator.hasNext(); ) {
try (Handler<Processor> handler = iterator.next()) {
handler.get().ping();
}
}
assertEquals(4, ActionSequence.getSequenceSize());
ActionSequence.assertSequenceDataContainsAll("firstPing", "secondPing", "firstDestroy", "secondDestroy");
}
}
Aggregations