use of com.blade.ioc.annotation.Bean in project blade by biezhi.
the class ClassDefineTest method testClassDefine.
@Test
public void testClassDefine() {
ClassDefine classDefine = ClassDefine.create(BladeClassDefineType.class);
int modifires = classDefine.getModifiers();
Field[] fields = classDefine.getDeclaredFields();
Bean bean = classDefine.getAnnotation(Bean.class);
Annotation[] annotations = classDefine.getAnnotations();
List<ClassDefine> interfaces = classDefine.getInterfaces();
String name = classDefine.getName();
String simpleName = classDefine.getSimpleName();
ClassDefine superKlass = classDefine.getSuperKlass();
Class<?> type = classDefine.getType();
assertEquals(Modifier.PUBLIC, modifires);
assertEquals(2, fields.length);
assertNotNull(bean);
assertEquals(1, annotations.length);
assertEquals(0, interfaces.size());
assertEquals("com.blade.types.BladeClassDefineType", name);
assertEquals("BladeClassDefineType", simpleName);
assertEquals(Object.class, superKlass.getType());
assertEquals(BladeClassDefineType.class, type);
assertEquals(false, classDefine.isAbstract());
assertEquals(false, classDefine.isInterface());
assertEquals(false, classDefine.isStatic());
assertEquals(true, classDefine.isPublic());
assertEquals(false, classDefine.isPrivate());
assertEquals(false, classDefine.isProtected());
assertEquals(1, ClassDefine.create(BladeWebHookType.class).getInterfaces().size());
assertEquals(1, ClassDefine.create(BladeWebHookType.class).getInterfaces().size());
}
use of com.blade.ioc.annotation.Bean in project blade by biezhi.
the class SimpleIoc method addBean.
/**
* Register @Bean marked objects
*/
@Override
public <T> T addBean(Class<T> type) {
Bean beanAnnotation = type.getAnnotation(Bean.class);
boolean isSingleton = null == beanAnnotation || beanAnnotation.singleton();
if (isSingleton) {
Object bean = put(type, true);
return type.cast(bean);
}
return null;
}
Aggregations