ContainerUtils { public static Method findInitMethod(Class<?> targetBeanType, BindInfo<?> bindInfo) { Method initMethod = null; if (targetBeanType != null) { List<Method> methodList = BeanUtils.findALLMethods(targetBeanType); if (methodList != null) { for (Method method : methodList) { Init initAnno1 = method.getAnnotation(Init.class); PostConstruct initAnno2 = method.getAnnotation(PostConstruct.class); if (initAnno1 == null && initAnno2 == null) { continue; } if (Modifier.isPublic(method.getModifiers())) { initMethod = method; break; } } } } if (initMethod == null && bindInfo instanceof DefaultBindInfoProviderAdapter) { DefaultBindInfoProviderAdapter<?> defBinder = (DefaultBindInfoProviderAdapter<?>) bindInfo; initMethod = defBinder.getInitMethod(targetBeanType); } return initMethod; }  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 initMethodTest1() { assert ContainerUtils.findInitMethod(NonePrivateCallInitBean.class, null) == null; assert ContainerUtils.findInitMethod(NonePublicCallInitBean.class, null).equals(initMethod_2); assert ContainerUtils.findInitMethod(WithoutAnnoCallInitBean.class, null) == null; }
@Test public void initMethodTest2() { BindInfoContainer infoContainer = new BindInfoContainer(new SpiCallerContainer()); DefaultBindInfoProviderAdapter<NonePrivateCallInitBean> adapter_1 = infoContainer.createInfoAdapter(NonePrivateCallInitBean.class, null); adapter_1.initMethod("init"); DefaultBindInfoProviderAdapter<NonePublicCallInitBean> adapter_2 = infoContainer.createInfoAdapter(NonePublicCallInitBean.class, null); adapter_2.initMethod("init"); DefaultBindInfoProviderAdapter<WithoutAnnoCallInitBean> adapter_3 = infoContainer.createInfoAdapter(WithoutAnnoCallInitBean.class, null); adapter_3.initMethod("init"); assert ContainerUtils.findInitMethod(NonePrivateCallInitBean.class, adapter_1) == null; assert ContainerUtils.findInitMethod(NonePublicCallInitBean.class, adapter_2).equals(initMethod_2); assert ContainerUtils.findInitMethod(WithoutAnnoCallInitBean.class, adapter_3).equals(initMethod_3); }
@Test public void initMethodTest3() throws NoSuchMethodException { BindInfoContainer infoContainer = new BindInfoContainer(new SpiCallerContainer()); DefaultBindInfoProviderAdapter<NonePublicCallInitBean> adapter = infoContainer.createInfoAdapter(NonePublicCallInitBean.class, null); adapter.initMethod("isInit"); Method initMethod = NonePublicCallInitBean.class.getDeclaredMethod("isInit"); assert !ContainerUtils.findInitMethod(NonePublicCallInitBean.class, adapter).equals(initMethod); assert ContainerUtils.findInitMethod(NonePublicCallInitBean.class, adapter).equals(initMethod_2); }