Search in sources :

Example 1 with MapperImpl

use of org.simpleflatmapper.map.mapper.MapperImpl in project SimpleFlatMapper by arnaudroger.

the class JdbcMapperErrorTest method testInstantiatorError.

@Test
public void testInstantiatorError() {
    MapperImpl<ResultSet, DbObject> mapper = new MapperImpl<ResultSet, DbObject>(null, null, new BiInstantiator<ResultSet, MappingContext<? super ResultSet>, DbObject>() {

        @Override
        public DbObject newInstance(ResultSet s, MappingContext<? super ResultSet> context) throws Exception {
            throw new IOException();
        }
    });
    try {
        mapper.map(null);
        fail("Expected error");
    } catch (Exception e) {
        assertTrue(e instanceof IOException);
    }
}
Also used : MappingContext(org.simpleflatmapper.map.MappingContext) MapperImpl(org.simpleflatmapper.map.mapper.MapperImpl) DbObject(org.simpleflatmapper.test.beans.DbObject) ResultSet(java.sql.ResultSet) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with MapperImpl

use of org.simpleflatmapper.map.mapper.MapperImpl in project SimpleFlatMapper by arnaudroger.

the class JdbcMapperBuilderTest method getSubMapper.

private Mapper<ResultSet, DbObject> getSubMapper(JdbcMapper<DbObject> mapper) throws Exception {
    Field field;
    try {
        field = mapper.getClass().getDeclaredField("mapper");
    } catch (NoSuchFieldException e) {
        field = mapper.getClass().getSuperclass().getDeclaredField("mapper");
    }
    field.setAccessible(true);
    return new FieldGetter<JdbcMapper<?>, MapperImpl<ResultSet, DbObject>>(field).get(mapper);
}
Also used : Field(java.lang.reflect.Field) MapperImpl(org.simpleflatmapper.map.mapper.MapperImpl) JdbcMapper(org.simpleflatmapper.jdbc.JdbcMapper)

Aggregations

MapperImpl (org.simpleflatmapper.map.mapper.MapperImpl)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 ResultSet (java.sql.ResultSet)1 Test (org.junit.Test)1 JdbcMapper (org.simpleflatmapper.jdbc.JdbcMapper)1 MappingContext (org.simpleflatmapper.map.MappingContext)1 DbObject (org.simpleflatmapper.test.beans.DbObject)1