/** * Verifies an InjectableAttribute is set properly for protected fields * * @throws Exception */ public void testProtectedFieldInjectionSource() throws Exception { Injectable injectable = new Injectable(InjectableType.REFERENCE, "xyz"); Field field = Foo.class.getDeclaredField("xyz"); InjectionSite injectionSite = new FieldInjectionSite(field); definition.getPostConstruction().put(injectionSite, injectable); ImplementationManagerFactory factory = builder.build(definition); Class<?> clazz = factory.getMemberType(injectable); assertEquals(Bar.class, clazz); }
/** * Verifies an InjectableAttribute is set properly for setter methods * * @throws Exception */ public void testMethodInjectionSource() throws Exception { Injectable injectable = new Injectable(InjectableType.REFERENCE, "abc"); Method method = Foo.class.getMethod("setAbc", Bar.class); InjectionSite injectionSite = new MethodInjectionSite(method, 0); definition.getPostConstruction().put(injectionSite, injectable); ImplementationManagerFactory factory = builder.build(definition); Class<?> clazz = factory.getMemberType(injectable); assertEquals(Bar.class, clazz); }
/** * Verifies an InjectableAttribute is set properly for constructor parameters * * @throws Exception */ public void testCdiSource() throws Exception { ImplementationManagerFactory factory = builder.build(definition); assertEquals(String.class, factory.getMemberType(new Injectable(InjectableType.PROPERTY, "a"))); }