use of org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition in project SimpleFlatMapper by arnaudroger.
the class ReflectionInstantiatorDefinitionFactoryTest method testExtractStaticFactoryMethod.
@Test
public void testExtractStaticFactoryMethod() throws NoSuchMethodException {
List<InstantiatorDefinition> factoryMethod = ReflectionInstantiatorDefinitionFactory.extractDefinitions(ObjectWithFactoryMethod.class);
assertEquals(1, factoryMethod.size());
ExecutableInstantiatorDefinition id = (ExecutableInstantiatorDefinition) factoryMethod.get(0);
assertEquals(ObjectWithFactoryMethod.class.getMethod("valueOf", String.class), id.getExecutable());
assertEquals(1, id.getParameters().length);
Assert.assertEquals(new Parameter(0, null, String.class), id.getParameters()[0]);
}
use of org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition in project SimpleFlatMapper by arnaudroger.
the class AsmFactoryTest method testCreateInstantiatorFinalDbObjectInjectIdAndName.
@Test
public void testCreateInstantiatorFinalDbObjectInjectIdAndName() throws Exception {
ExecutableInstantiatorDefinition instantiatorDefinition = (ExecutableInstantiatorDefinition) AsmInstantiatorDefinitionFactory.extractDefinitions(DbFinalObject.class).get(0);
HashMap<Parameter, Getter<? super Object, ?>> injections = new HashMap<Parameter, Getter<? super Object, ?>>();
injections.put(new Parameter(0, "id", long.class), new ConstantLongGetter<Object>(33l));
injections.put(new Parameter(1, "name", String.class), new ConstantGetter<Object, String>("fdo"));
Instantiator<Object, DbFinalObject> instantiator = asmFactory.createInstantiator(Object.class, instantiatorDefinition, injections, true);
DbFinalObject fdo = instantiator.newInstance(new Object());
assertNotNull(fdo);
assertNull(fdo.getEmail());
assertNull(fdo.getCreationTime());
assertNull(fdo.getTypeName());
assertNull(fdo.getTypeOrdinal());
assertEquals(33l, fdo.getId());
assertEquals("fdo", fdo.getName());
assertSame(instantiator.getClass(), asmFactory.createInstantiator(Object.class, instantiatorDefinition, injections, true).getClass());
}
use of org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition in project SimpleFlatMapper by arnaudroger.
the class AsmFactoryTest method testCreateInstantiatorFinalDbObjectNameAndType.
@Test
public void testCreateInstantiatorFinalDbObjectNameAndType() throws Exception {
HashMap<Parameter, Getter<? super Object, ?>> injections = new HashMap<Parameter, Getter<? super Object, ?>>();
ConstantIntGetter<Object> getter = new ConstantIntGetter<Object>(1);
injections.put(new Parameter(4, "typeOrdinal", Type.class), new OrdinalEnumGetter<Object, Type>(getter, Type.class));
injections.put(new Parameter(1, "name", String.class), new ConstantGetter<Object, String>("fdo"));
List<InstantiatorDefinition> instantiatorDefinitions = AsmInstantiatorDefinitionFactory.extractDefinitions(DbFinalObject.class);
Instantiator<Object, DbFinalObject> instantiator = asmFactory.createInstantiator(Object.class, (ExecutableInstantiatorDefinition) instantiatorDefinitions.get(0), injections, true);
DbFinalObject fdo = instantiator.newInstance(new Object());
assertNotNull(fdo);
assertNull(fdo.getEmail());
assertNull(fdo.getCreationTime());
assertNull(fdo.getTypeName());
assertEquals(0, fdo.getId());
assertEquals("fdo", fdo.getName());
assertEquals(Type.type2, fdo.getTypeOrdinal());
}
use of org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition in project SimpleFlatMapper by arnaudroger.
the class ListClassMetaTest method hasOneInstantiatorDefinitionWithEmptyConstructorOnImpl.
private void hasOneInstantiatorDefinitionWithEmptyConstructorOnImpl(ClassMeta<?> classMeta, Class<?> impl) throws NoSuchMethodException {
assertTrue(classMeta instanceof ArrayClassMeta);
final List<InstantiatorDefinition> instantiatorDefinitions = classMeta.getInstantiatorDefinitions();
assertEquals(1, instantiatorDefinitions.size());
final ExecutableInstantiatorDefinition instantiatorDefinition = (ExecutableInstantiatorDefinition) instantiatorDefinitions.get(0);
assertEquals(0, instantiatorDefinition.getParameters().length);
assertEquals(impl.getDeclaredConstructor(), instantiatorDefinition.getExecutable());
}
use of org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition in project SimpleFlatMapper by arnaudroger.
the class MapClassMetaTest method hasOneInstantiatorDefinitionWithEmptyConstructorOnImpl.
private void hasOneInstantiatorDefinitionWithEmptyConstructorOnImpl(ClassMeta<?> classMeta, Class<?> impl) throws NoSuchMethodException {
assertTrue(classMeta instanceof MapClassMeta);
final List<InstantiatorDefinition> instantiatorDefinitions = classMeta.getInstantiatorDefinitions();
assertEquals(1, instantiatorDefinitions.size());
final ExecutableInstantiatorDefinition instantiatorDefinition = (ExecutableInstantiatorDefinition) instantiatorDefinitions.get(0);
assertEquals(0, instantiatorDefinition.getParameters().length);
assertEquals(impl.getDeclaredConstructor(), instantiatorDefinition.getExecutable());
}
Aggregations