Search in sources :

Example 1 with ConstantLongGetter

use of org.simpleflatmapper.reflect.getter.ConstantLongGetter 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());
}
Also used : DbFinalObject(org.simpleflatmapper.test.beans.DbFinalObject) ExecutableInstantiatorDefinition(org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition) HashMap(java.util.HashMap) ConstantGetter(org.simpleflatmapper.reflect.getter.ConstantGetter) Getter(org.simpleflatmapper.reflect.Getter) ConstantLongGetter(org.simpleflatmapper.reflect.getter.ConstantLongGetter) IntGetter(org.simpleflatmapper.reflect.primitive.IntGetter) OrdinalEnumGetter(org.simpleflatmapper.reflect.getter.OrdinalEnumGetter) ConstantIntGetter(org.simpleflatmapper.reflect.getter.ConstantIntGetter) Parameter(org.simpleflatmapper.reflect.Parameter) DbObject(org.simpleflatmapper.test.beans.DbObject) DbFinalObject(org.simpleflatmapper.test.beans.DbFinalObject) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 Test (org.junit.Test)1 Getter (org.simpleflatmapper.reflect.Getter)1 Parameter (org.simpleflatmapper.reflect.Parameter)1 ConstantGetter (org.simpleflatmapper.reflect.getter.ConstantGetter)1 ConstantIntGetter (org.simpleflatmapper.reflect.getter.ConstantIntGetter)1 ConstantLongGetter (org.simpleflatmapper.reflect.getter.ConstantLongGetter)1 OrdinalEnumGetter (org.simpleflatmapper.reflect.getter.OrdinalEnumGetter)1 ExecutableInstantiatorDefinition (org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition)1 IntGetter (org.simpleflatmapper.reflect.primitive.IntGetter)1 DbFinalObject (org.simpleflatmapper.test.beans.DbFinalObject)1 DbObject (org.simpleflatmapper.test.beans.DbObject)1