Search in sources :

Example 1 with Type

use of org.simpleflatmapper.test.beans.DbObject.Type 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());
}
Also used : DbFinalObject(org.simpleflatmapper.test.beans.DbFinalObject) 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) ConstantIntGetter(org.simpleflatmapper.reflect.getter.ConstantIntGetter) ExecutableInstantiatorDefinition(org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition) InstantiatorDefinition(org.simpleflatmapper.reflect.InstantiatorDefinition) Type(org.simpleflatmapper.test.beans.DbObject.Type) 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 InstantiatorDefinition (org.simpleflatmapper.reflect.InstantiatorDefinition)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 Type (org.simpleflatmapper.test.beans.DbObject.Type)1