Search in sources :

Example 1 with GetterFactory

use of org.simpleflatmapper.reflect.getter.GetterFactory in project SimpleFlatMapper by arnaudroger.

the class JdbcMapperFactoryTest method testCustomGetterFactory.

@Test
public void testCustomGetterFactory() throws SQLException {
    JdbcMapper<DbObject> mapper = JdbcMapperFactoryHelper.asm().getterFactory(new GetterFactory<ResultSet, JdbcColumnKey>() {

        @SuppressWarnings("unchecked")
        @Override
        public <P> Getter<ResultSet, P> newGetter(Type target, JdbcColumnKey key, Object... properties) {
            return new Getter() {

                @Override
                public Object get(Object target) throws Exception {
                    return "Hello!";
                }
            };
        }
    }).newBuilder(DbObject.class).addMapping("name").mapper();
    ResultSet rs = mock(ResultSet.class);
    when(rs.next()).thenReturn(true, false);
    DbObject object = mapper.iterator(rs).next();
    assertEquals("Hello!", object.getName());
}
Also used : JdbcColumnKey(org.simpleflatmapper.jdbc.JdbcColumnKey) GetterFactory(org.simpleflatmapper.reflect.getter.GetterFactory) Type(java.lang.reflect.Type) DbObject(org.simpleflatmapper.test.beans.DbObject) Getter(org.simpleflatmapper.reflect.Getter) DbObject(org.simpleflatmapper.test.beans.DbObject) DbFinalObject(org.simpleflatmapper.test.beans.DbFinalObject) Test(org.junit.Test)

Aggregations

Type (java.lang.reflect.Type)1 Test (org.junit.Test)1 JdbcColumnKey (org.simpleflatmapper.jdbc.JdbcColumnKey)1 Getter (org.simpleflatmapper.reflect.Getter)1 GetterFactory (org.simpleflatmapper.reflect.getter.GetterFactory)1 DbFinalObject (org.simpleflatmapper.test.beans.DbFinalObject)1 DbObject (org.simpleflatmapper.test.beans.DbObject)1