public class InjectionServicesTest {
@Test
public void testInjectionOfTarget() {
TestContainer container = new TestContainer(Foo.class, Bar.class);
CheckableInjectionServices ijs = new CheckableInjectionServices();
for (BeanDeploymentArchive bda : container.getDeployment().getBeanDeploymentArchives()) {
bda.getServices().add(InjectionServices.class, ijs);
}
container.startContainer();
container.ensureRequestActive();
BeanManager manager = getBeanManager(container);
Bean<? extends Object> bean = manager.resolve(manager.getBeans(Foo.class));
ijs.reset();
Foo foo = (Foo) manager.getReference(bean, Foo.class, manager.createCreationalContext(bean));
Assert.assertTrue(ijs.isBefore());
Assert.assertTrue(ijs.isAfter());
Assert.assertTrue(ijs.isInjectedAfter());
Assert.assertTrue(ijs.isInjectionTargetCorrect());
Assert.assertEquals(ijs.getAroundInjectForFooCalled(), 1);
Assert.assertEquals(ijs.getAroundInjectForBarCalled(), 1);
Assert.assertNotNull(foo.getBar());
Assert.assertEquals("hi!", foo.getMessage());
container.stopContainer();
}