public static void injectSpringBeanByName(final ApplicationContext ctx, final Class testedClazz,
final Object testedObject) {
Set<Field> springBeanByNamefields = getFieldsAnnotatedWith(testedClazz, SpringBeanByName.class);
for (Field field : springBeanByNamefields) {
try {
SpringBeanByName byName = field.getAnnotation(SpringBeanByName.class);
String beanName = field.getName();
if (StringHelper.isBlankOrNull(byName.value()) == false) {
beanName = byName.value();
}
FieldHelper.setFieldValue(testedObject, field, ctx.getBean(beanName));
} catch (Throwable e) {
throw new JTesterException(
"Unable to assign the Spring bean value to field annotated with @SpringBeanByName", e);