/** * Registers constructor injection point. */ public void bind() { petiteContainer.registerPetiteCtorInjectionPoint(beanName, ctorArgumentTypes, references); } }
@Test void testConsumer() { PetiteContainer pc = new PetiteContainer(); pc.registerPetiteBean(SomeService.class, null, null, null, false, null); pc.registerPetiteBean(PojoBean.class, "pojo", null, null, false, pb -> pb.count = 7); pc.registerPetiteCtorInjectionPoint("pojo", null, null); PojoBean pb = pc.getBean("pojo"); assertEquals(7, pb.count); } }
@Test void testManualRegistration() { PetiteContainer pc = new PetiteContainer(); pc.registerPetiteBean(SomeService.class, null, null, null, false, null); pc.registerPetiteBean(PojoBean.class, "pojo", null, null, false, null); assertEquals(2, pc.beansCount()); Set<String> names = pc.beanNames(); assertEquals(2, names.size()); assertTrue(names.contains("pojo")); assertTrue(names.contains("someService")); pc.registerPetiteCtorInjectionPoint("pojo", null, null); pc.registerPetitePropertyInjectionPoint("pojo", "service", "someService"); pc.registerPetiteMethodInjectionPoint("pojo", "injectService", null, new String[]{"someService"}); pc.registerPetiteInitMethods("pojo", POST_INITIALIZE, "init"); PojoBean pojoBean = pc.getBean("pojo"); SomeService ss = pc.getBean("someService"); assertNotNull(pojoBean); assertNotNull(ss); assertSame(ss, pojoBean.fservice); assertSame(ss, pojoBean.service); assertSame(ss, pojoBean.service2); assertEquals(1, pojoBean.count); }
@Test void testManualDefinition() { PetiteContainer pc = new PetiteContainer(); pc.registerPetiteBean(SomeService.class, null, null, null, false, null); pc.registerPetiteBean(PojoBean.class, "pojo", null, null, true, null); assertEquals(2, pc.beansCount()); pc.registerPetiteCtorInjectionPoint("pojo", null, null); pc.registerPetitePropertyInjectionPoint("pojo", "service", "someService"); pc.registerPetiteMethodInjectionPoint("pojo", "injectService", null, new String[] {"someService"}); pc.registerPetiteInitMethods("pojo", POST_INITIALIZE, "init"); PojoBean pojoBean = pc.getBean("pojo"); SomeService ss = pc.getBean("someService"); assertNotNull(pojoBean); assertNotNull(ss); assertSame(ss, pojoBean.fservice); assertSame(ss, pojoBean.service); assertSame(ss, pojoBean.service2); assertEquals(1, pojoBean.count); }
/** * Registers constructor injection point. */ public void bind() { petiteContainer.registerPetiteCtorInjectionPoint(beanName, ctorArgumentTypes, references); } }