Search in sources :

Example 1 with Handler

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");
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Handler(org.jboss.weld.inject.WeldInstance.Handler) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Aggregations

Weld (org.jboss.weld.environment.se.Weld)1 WeldContainer (org.jboss.weld.environment.se.WeldContainer)1 Handler (org.jboss.weld.inject.WeldInstance.Handler)1 Test (org.junit.Test)1