ContainerUtils { public static Annotation findInject(boolean injectDefault, Annotation[] annotations) { if (annotations == null || annotations.length == 0) { return null; } boolean injectBoolean = injectDefault; Annotation qualifier = null; for (Annotation anno : annotations) { if (anno instanceof net.hasor.core.Inject) { injectBoolean = true; if (Type.ByName == ((net.hasor.core.Inject) anno).byType()) { qualifier = new NamedImpl(((net.hasor.core.Inject) anno).value()); } if (Type.ByID == ((net.hasor.core.Inject) anno).byType()) { qualifier = new IDImpl(((net.hasor.core.Inject) anno).value()); } break; } if (anno instanceof InjectSettings) { injectBoolean = true; qualifier = anno; break; } if (anno instanceof javax.inject.Inject) { injectBoolean = true; qualifier = (qualifier == null) ? anno : qualifier; continue; } if (anno.annotationType().getAnnotation(Qualifier.class) != null) { qualifier = anno; } if (qualifier != null && injectBoolean) { break; } } if (injectBoolean) { if (qualifier instanceof ID || qualifier instanceof Named || qualifier instanceof InjectSettings) { return qualifier; } if (qualifier instanceof javax.inject.Inject) { return new NamedImpl(""); } return new NamedImpl(qualifier.annotationType().getName()); } return null; }  static Method findInitMethod(Class<?> targetBeanType, BindInfo<?> bindInfo); static Method findDestroyMethod(Class<?> targetBeanType, BindInfo<?> bindInfo); static Class<T> findImplClass(final Class<?> notSureType); static Annotation findInject(boolean injectDefault, Annotation[] annotations); static boolean isInjectConstructor(Constructor<?> constructor); static Object injSettings(AppContext appContext, InjectSettings injectSettings, Class<?> toType); static void invokeMethod(Object targetBean, Method initMethod); static void invokeField(Field field, Object targetBean, Object newValue); static boolean testAopIgnore(Class<T> targetType, ClassLoader rootLoader);  }
@Test public void testInject1() throws NoSuchFieldException { assert ContainerUtils.findInject(false, null) == null; Annotation injectAnno_1 = ContainerUtils.findInject(false, PropertyPojoBeanRef.class.getDeclaredField("pojoBean").getAnnotations()); Annotation injectAnno_2 = ContainerUtils.findInject(false, PropertyPojoBeanRef.class.getDeclaredField("pojoBean").getAnnotations()); injectAnno_1.toString(); assert injectAnno_1 instanceof Named; assert injectAnno_2 instanceof Named; assert injectAnno_1 != injectAnno_2; assert injectAnno_1.equals(injectAnno_2); assert injectAnno_1.hashCode() == injectAnno_2.hashCode(); assert !injectAnno_1.equals(new Object()); }
@Test public void testInject2() throws NoSuchFieldException { Annotation injectAnno_1 = ContainerUtils.findInject(false, ByIDPropertyPojoBeanRef.class.getDeclaredField("pojoBean").getAnnotations()); Annotation injectAnno_2 = ContainerUtils.findInject(false, ByIDPropertyPojoBeanRef.class.getDeclaredField("pojoBean").getAnnotations()); injectAnno_1.toString(); assert injectAnno_1 instanceof ID; assert injectAnno_2 instanceof ID; assert injectAnno_1 != injectAnno_2; assert injectAnno_1.equals(injectAnno_2); assert injectAnno_1.hashCode() == injectAnno_2.hashCode(); assert !injectAnno_1.equals(new Object()); }
@Test public void testInject3() throws NoSuchFieldException { Annotation injectAnno_1 = ContainerUtils.findInject(false, PropertyPojoBeanRef.class.getDeclaredField("pojoBean").getAnnotations()); assert injectAnno_1 instanceof Named; assert ((Named) injectAnno_1).value().equals(""); assert injectAnno_1.annotationType() == Named.class; Annotation injectAnno_2 = ContainerUtils.findInject(false, ByIDPropertyPojoBeanRef.class.getDeclaredField("pojoBean").getAnnotations()); assert injectAnno_2 instanceof ID; assert injectAnno_2.annotationType() == ID.class; assert ((ID) injectAnno_2).value().equals("my_pojoBean"); Annotation injectAnno_3 = ContainerUtils.findInject(false, ByNamePropertyPojoBeanRef.class.getDeclaredField("pojoBean").getAnnotations()); assert injectAnno_3 instanceof Named; assert ((Named) injectAnno_3).value().equals("my_pojoBean"); assert injectAnno_3.annotationType() == Named.class; }
@Test public void jsrInject1() throws NoSuchFieldException { Annotation injectAnno_1 = ContainerUtils.findInject(false, Jsr330BasicRef.class.getDeclaredField("pojoBean1").getAnnotations()); Annotation injectAnno_2 = ContainerUtils.findInject(false, Jsr330BasicRef.class.getDeclaredField("pojoBean2").getAnnotations()); Annotation injectAnno_3 = ContainerUtils.findInject(false, Jsr330BasicRef.class.getDeclaredField("pojoBean3").getAnnotations()); Annotation injectAnno_4 = ContainerUtils.findInject(false, Jsr330BasicRef.class.getDeclaredField("pojoBean4").getAnnotations()); Annotation injectAnno_5 = ContainerUtils.findInject(false, Jsr330BasicRef.class.getDeclaredField("pojoBean5").getAnnotations()); Annotation injectAnno_6 = ContainerUtils.findInject(false, Jsr330BasicRef.class.getDeclaredField("pojoBean6").getAnnotations()); assert injectAnno_1 == null; assert injectAnno_2 instanceof Named && ((Named) injectAnno_2).value().equals(""); assert injectAnno_3 instanceof Named && ((Named) injectAnno_3).value().equals(ByOrder.class.getName()); assert injectAnno_4 instanceof Named && ((Named) injectAnno_4).value().equals(ByOrder.class.getName()); assert injectAnno_5 instanceof Named && ((Named) injectAnno_5).value().equals(ByOrder.class.getName()); assert injectAnno_6 instanceof Named && ((Named) injectAnno_6).value().equals(ByOrder.class.getName()); }