use of org.simpleflatmapper.test.beans.DbEnumObject in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperEnumTest method testIndexedEnumUndefined.
@Test
public void testIndexedEnumUndefined() throws Exception {
JdbcMapperBuilder<DbEnumObject> builder = JdbcMapperFactoryHelper.asm().newBuilder(DbEnumObject.class);
builder.addMapping("val", 1);
JdbcMapper<DbEnumObject> mapper = builder.mapper();
ResultSet rs = mock(ResultSet.class);
when(rs.getObject(1)).thenReturn(Integer.valueOf(2));
assertEquals(DbObject.Type.type3, mapper.map(rs).getVal());
when(rs.getObject(1)).thenReturn("type2");
assertEquals(DbObject.Type.type2, mapper.map(rs).getVal());
}
use of org.simpleflatmapper.test.beans.DbEnumObject in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperEnumTest method testIndexedEnumString.
@Test
public void testIndexedEnumString() throws Exception {
JdbcMapperBuilder<DbEnumObject> builder = JdbcMapperFactoryHelper.asm().newBuilder(DbEnumObject.class);
builder.addMapping("val", 1, Types.VARCHAR);
JdbcMapper<DbEnumObject> mapper = builder.mapper();
ResultSet rs = mock(ResultSet.class);
when(rs.getString(1)).thenReturn("type2");
assertEquals(DbObject.Type.type2, mapper.map(rs).getVal());
}
use of org.simpleflatmapper.test.beans.DbEnumObject in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperEnumTest method testIndexedEnumOrdinal.
@Test
public void testIndexedEnumOrdinal() throws Exception {
JdbcMapperBuilder<DbEnumObject> builder = JdbcMapperFactoryHelper.asm().newBuilder(DbEnumObject.class);
builder.addMapping("val", 1, Types.INTEGER);
JdbcMapper<DbEnumObject> mapper = builder.mapper();
ResultSet rs = mock(ResultSet.class);
when(rs.getInt(1)).thenReturn(2);
assertEquals(DbObject.Type.type3, mapper.map(rs).getVal());
}
use of org.simpleflatmapper.test.beans.DbEnumObject in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperEnumTest method testIndexedEnumFactoryMethod.
@Test
public void testIndexedEnumFactoryMethod() throws Exception {
JdbcMapperBuilder<DbEnumObject> builder = JdbcMapperFactoryHelper.asm().newBuilder(DbEnumObject.class);
builder.addMapping("val", 1, Types.VARCHAR, new Object[] { ConverterProperty.of(new ContextualConverter<String, DbObject.Type>() {
@Override
public DbObject.Type convert(String s, Context context) throws Exception {
return DbObject.Type.shortForm(s);
}
}) });
JdbcMapper<DbEnumObject> mapper = builder.mapper();
ResultSet rs = mock(ResultSet.class);
when(rs.getString(1)).thenReturn("t2");
assertEquals(DbObject.Type.type2, mapper.map(rs).getVal());
}
Aggregations