TypeContainer { public void gatherInformation() { Stack<Class<?>> hierarchie; Class<?> parent; InjectionSet injectionSet; List<InjectionSet> injectionSets = new ArrayList<InjectionSet>(); hierarchie = new Stack<Class<?>>(); hierarchie.push(parent = type); while ((parent = parent.getSuperclass()) != null) { if (!parent.equals(Object.class)) { hierarchie.push(parent); } } while (!hierarchie.isEmpty()) { parent = hierarchie.pop(); if (!parent.equals(Object.class)) { injectionSet = new InjectionSet(); injectionSet.type = parent; injectionSets.add(injectionSet); } } this.injectionSets = injectionSets.toArray(EMPTY_INJECTIONSET_ARRAY); singleton = type.isAnnotationPresent(Singleton.class); getFieldInformation(); getMethodInformation(); } TypeContainer(Class<?> type, Constructor<?> constructor); void gatherInformation(); Provider<?> getProvider(); void setProvider(Provider<?> provider); InjectionSet[] getInjectionSets(); void setInjectionSets(InjectionSet[] injectionSets); Class<?> getType(); void setType(Class<?> type); Constructor<?> getConstructor(); void setConstructor(Constructor<?> constructor); boolean isSingleton(); void setSingleton(boolean singleton); Method getFactoryMethod(); void setFactoryMethod(Method factoryMethod); InstanceMode getInstanceMode(); void setInstanceMode(InstanceMode instanceMode); @Override String toString();  }
@SuppressWarnings("unchecked") @Test public void gatherInformation_NoneSingleton() { Constructor<Bean3> ctor = null; for (Constructor<?> tmp : Bean3.class.getDeclaredConstructors()) { if (tmp.getParameterTypes().length == 0) { ctor = (Constructor<Bean3>) tmp; break; } } typeContainer = new TypeContainer(Bean3.class, ctor); assertNull(typeContainer.injectionSets); typeContainer.gatherInformation(); assertNotNull(typeContainer.injectionSets); assertEquals(3, typeContainer.injectionSets.length); assertEquals(Bean1.class, typeContainer.injectionSets[0].type); assertEquals(Bean2.class, typeContainer.injectionSets[1].type); assertEquals(Bean3.class, typeContainer.injectionSets[2].type); assertFalse(typeContainer.singleton); assertEquals(1, typeContainer.injectionSets[0].methods.length); assertEquals("contained1_1", typeContainer.injectionSets[0].methods[0].getName()); assertEquals(1, typeContainer.injectionSets[0].staticMethods.length); assertEquals("contained1_2", typeContainer.injectionSets[0].staticMethods[0].getName()); assertEquals(1, typeContainer.injectionSets[0].staticFields.length); assertEquals("contained1_3", typeContainer.injectionSets[0].staticFields[0].getName()); assertEquals(1, typeContainer.injectionSets[0].fields.length); assertEquals("contained1_4", typeContainer.injectionSets[0].fields[0].getName()); assertEquals(1, typeContainer.injectionSets[1].methods.length); assertEquals("contained2_1", typeContainer.injectionSets[1].methods[0].getName()); assertEquals(1, typeContainer.injectionSets[1].staticMethods.length); assertEquals("contained2_2", typeContainer.injectionSets[1].staticMethods[0].getName()); assertEquals(1, typeContainer.injectionSets[1].staticFields.length); assertEquals("contained2_3", typeContainer.injectionSets[1].staticFields[0].getName()); assertEquals(1, typeContainer.injectionSets[1].fields.length); assertEquals("contained2_4", typeContainer.injectionSets[1].fields[0].getName()); assertEquals(1, typeContainer.injectionSets[2].methods.length); assertEquals("contained3_1", typeContainer.injectionSets[2].methods[0].getName()); assertEquals(1, typeContainer.injectionSets[2].staticMethods.length); assertEquals("contained3_2", typeContainer.injectionSets[2].staticMethods[0].getName()); assertEquals(1, typeContainer.injectionSets[2].staticFields.length); assertEquals("contained3_3", typeContainer.injectionSets[2].staticFields[0].getName()); assertEquals(1, typeContainer.injectionSets[2].fields.length); assertEquals("contained3_4", typeContainer.injectionSets[2].fields[0].getName()); }
@SuppressWarnings("unchecked") @Test public void gatherInformation_Singleton() { Constructor<Bean4> ctor = null; for (Constructor<?> tmp : Bean4.class.getDeclaredConstructors()) { if (tmp.getParameterTypes().length == 0) { ctor = (Constructor<Bean4>) tmp; break; } } typeContainer = new TypeContainer(Bean4.class, ctor); assertNull(typeContainer.injectionSets); typeContainer.gatherInformation(); assertNotNull(typeContainer.injectionSets); assertEquals(4, typeContainer.injectionSets.length); assertEquals(Bean1.class, typeContainer.injectionSets[0].type); assertEquals(Bean2.class, typeContainer.injectionSets[1].type); assertEquals(Bean3.class, typeContainer.injectionSets[2].type); assertEquals(Bean4.class, typeContainer.injectionSets[3].type); assertTrue(typeContainer.singleton); assertEquals(1, typeContainer.injectionSets[0].methods.length); assertEquals("contained1_1", typeContainer.injectionSets[0].methods[0].getName()); assertEquals(1, typeContainer.injectionSets[0].staticMethods.length); assertEquals("contained1_2", typeContainer.injectionSets[0].staticMethods[0].getName()); assertEquals(1, typeContainer.injectionSets[0].staticFields.length); assertEquals("contained1_3", typeContainer.injectionSets[0].staticFields[0].getName()); assertEquals(1, typeContainer.injectionSets[0].fields.length); assertEquals("contained1_4", typeContainer.injectionSets[0].fields[0].getName()); assertEquals(1, typeContainer.injectionSets[1].methods.length); assertEquals("contained2_1", typeContainer.injectionSets[1].methods[0].getName()); assertEquals(1, typeContainer.injectionSets[1].staticMethods.length); assertEquals("contained2_2", typeContainer.injectionSets[1].staticMethods[0].getName()); assertEquals(1, typeContainer.injectionSets[1].staticFields.length); assertEquals("contained2_3", typeContainer.injectionSets[1].staticFields[0].getName()); assertEquals(1, typeContainer.injectionSets[1].fields.length); assertEquals("contained2_4", typeContainer.injectionSets[1].fields[0].getName()); assertEquals(1, typeContainer.injectionSets[2].methods.length); assertEquals("contained3_1", typeContainer.injectionSets[2].methods[0].getName()); assertEquals(1, typeContainer.injectionSets[2].staticMethods.length); assertEquals("contained3_2", typeContainer.injectionSets[2].staticMethods[0].getName()); assertEquals(1, typeContainer.injectionSets[2].staticFields.length); assertEquals("contained3_3", typeContainer.injectionSets[2].staticFields[0].getName()); assertEquals(1, typeContainer.injectionSets[2].fields.length); assertEquals("contained3_4", typeContainer.injectionSets[2].fields[0].getName()); assertEquals(1, typeContainer.injectionSets[3].methods.length); assertEquals("contained4_1", typeContainer.injectionSets[3].methods[0].getName()); assertEquals(1, typeContainer.injectionSets[3].staticMethods.length); assertEquals("contained4_2", typeContainer.injectionSets[3].staticMethods[0].getName()); assertEquals(1, typeContainer.injectionSets[3].staticFields.length); assertEquals("contained4_3", typeContainer.injectionSets[3].staticFields[0].getName()); assertEquals(1, typeContainer.injectionSets[3].fields.length); assertEquals("contained4_4", typeContainer.injectionSets[3].fields[0].getName()); }