ContainerUtils { public static Method findDestroyMethod(Class<?> targetBeanType, BindInfo<?> bindInfo) { Method destroyMethod = null; if (targetBeanType != null) { List<Method> methodList = BeanUtils.findALLMethods(targetBeanType); if (methodList != null) { for (Method method : methodList) { Destroy destroyAnno1 = method.getAnnotation(Destroy.class); PreDestroy destroyAnno2 = method.getAnnotation(PreDestroy.class); if (destroyAnno1 == null && destroyAnno2 == null) { continue; } if (Modifier.isPublic(method.getModifiers())) { destroyMethod = method; break; } } } } if (destroyMethod == null && bindInfo instanceof DefaultBindInfoProviderAdapter) { DefaultBindInfoProviderAdapter<?> defBinder = (DefaultBindInfoProviderAdapter<?>) bindInfo; destroyMethod = defBinder.getDestroyMethod(targetBeanType); } return destroyMethod; }  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 destroyMethodTest1() { assert ContainerUtils.findDestroyMethod(NonePrivateCallDestroyBean.class, null) == null; assert ContainerUtils.findDestroyMethod(NonePublicCallDestroyBean.class, null).equals(destroyMethod_2); assert ContainerUtils.findDestroyMethod(WithoutAnnoCallDestroyBean.class, null) == null; }
@Test public void destroyMethodTest2() { BindInfoContainer infoContainer = new BindInfoContainer(new SpiCallerContainer()); DefaultBindInfoProviderAdapter<NonePrivateCallDestroyBean> adapter_1 = infoContainer.createInfoAdapter(NonePrivateCallDestroyBean.class, null); adapter_1.destroyMethod("destroy"); DefaultBindInfoProviderAdapter<NonePublicCallDestroyBean> adapter_2 = infoContainer.createInfoAdapter(NonePublicCallDestroyBean.class, null); adapter_2.destroyMethod("destroy"); DefaultBindInfoProviderAdapter<WithoutAnnoCallDestroyBean> adapter_3 = infoContainer.createInfoAdapter(WithoutAnnoCallDestroyBean.class, null); adapter_3.destroyMethod("destroy"); assert ContainerUtils.findDestroyMethod(NonePrivateCallDestroyBean.class, adapter_1) == null; assert ContainerUtils.findDestroyMethod(NonePublicCallDestroyBean.class, adapter_2).equals(destroyMethod_2); assert ContainerUtils.findDestroyMethod(WithoutAnnoCallDestroyBean.class, adapter_3).equals(destroyMethod_3); }
@Test public void destroyMethodTest3() throws NoSuchMethodException { BindInfoContainer infoContainer = new BindInfoContainer(new SpiCallerContainer()); DefaultBindInfoProviderAdapter<NonePublicCallDestroyBean> adapter = infoContainer.createInfoAdapter(NonePublicCallDestroyBean.class, null); adapter.destroyMethod("isDestroy"); Method destroyMethod = NonePublicCallDestroyBean.class.getDeclaredMethod("isDestroy"); assert !ContainerUtils.findDestroyMethod(NonePublicCallDestroyBean.class, adapter).equals(destroyMethod); assert ContainerUtils.findDestroyMethod(NonePublicCallDestroyBean.class, adapter).equals(destroyMethod_2); }