ContainerUtils { public static Object injSettings(AppContext appContext, InjectSettings injectSettings, Class<?> toType) { if (injectSettings == null || StringUtils.isBlank(injectSettings.value())) { return BeanUtils.getDefaultValue(toType); } String useNS = injectSettings.ns(); String defaultVal = injectSettings.defaultValue(); String settingVar = injectSettings.value(); String settingValue = null; if (settingVar.startsWith("${") && settingVar.endsWith("}")) { settingVar = settingVar.substring(2, settingVar.length() - 1); settingValue = appContext.getEnvironment().evalString("%" + settingVar + "%"); if (StringUtils.isBlank(settingValue)) { settingValue = defaultVal; } } else { if (StringUtils.isBlank(defaultVal)) { defaultVal = null; } Settings settings = appContext.getEnvironment().getSettings(); if (StringUtils.isNotBlank(useNS)) { settings = settings.getSettings(useNS); } settingValue = settings.getString(settingVar, defaultVal); } if (settingValue == null && !toType.isPrimitive()) { return null; } else { return ConverterUtils.convert(settingValue, toType); } }  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 testInject5() throws IOException, URISyntaxException { AppContext appContext = PowerMockito.mock(AppContext.class); Environment environment = PowerMockito.mock(Environment.class); Settings settings = new StandardContextSettings(); PowerMockito.when(appContext.getEnvironment()).thenReturn(environment); PowerMockito.when(appContext.getEnvironment().getSettings()).thenReturn(settings); PowerMockito.when(appContext.getEnvironment().evalString(anyString())).thenReturn("EVAL_STRING"); class InjectSettingsImpl implements InjectSettings { private String value; private String defaultValue; public InjectSettingsImpl(String value, String defaultValue) { this.value = value; this.defaultValue = defaultValue; } @Override public String ns() { return ""; } @Override public String value() { return value; } @Override public String defaultValue() { return defaultValue; } @Override public Class<? extends Annotation> annotationType() { return InjectSettings.class; } } settings.addSetting("mock.test1", "abc"); assert ContainerUtils.injSettings(appContext, new InjectSettingsImpl("mock.test1", ""), String.class).equals("abc"); assert ContainerUtils.injSettings(appContext, new InjectSettingsImpl("mock.test2", "123"), String.class).equals("123"); assert ContainerUtils.injSettings(appContext, new InjectSettingsImpl("${java_home}", "123"), String.class).equals("EVAL_STRING"); assert ContainerUtils.injSettings(appContext, null, Integer.TYPE).equals(0); }