Search in sources :

Example 1 with ValueTypeMapper

use of org.jdbi.v3.core.mapper.ValueTypeMapper in project jdbi by jdbi.

the class BeanMapperTest method shouldUseRegisteredMapperForUnknownPropertyType.

@Test
public void shouldUseRegisteredMapperForUnknownPropertyType() throws Exception {
    handle.registerColumnMapper(new ValueTypeMapper());
    mockColumns("longField", "valueTypeField");
    Long expected = 123L;
    when(resultSet.getLong(1)).thenReturn(expected);
    when(resultSet.getString(2)).thenReturn("foo");
    when(resultSet.wasNull()).thenReturn(false);
    SampleBean sampleBean = mapper.map(resultSet, ctx);
    assertThat(sampleBean.getLongField()).isEqualTo(expected);
    assertThat(sampleBean.getValueTypeField()).isEqualTo(ValueType.valueOf("foo"));
}
Also used : ValueTypeMapper(org.jdbi.v3.core.mapper.ValueTypeMapper) SampleBean(org.jdbi.v3.core.SampleBean) Test(org.junit.Test)

Example 2 with ValueTypeMapper

use of org.jdbi.v3.core.mapper.ValueTypeMapper in project jdbi by jdbi.

the class FieldMapperTest method shouldUseRegisteredMapperForUnknownPropertyType.

@Test
public void shouldUseRegisteredMapperForUnknownPropertyType() throws Exception {
    handle.registerColumnMapper(new ValueTypeMapper());
    mockColumns("longField", "valueTypeField");
    when(resultSet.getLong(1)).thenReturn(123L);
    when(resultSet.getString(2)).thenReturn("foo");
    when(resultSet.wasNull()).thenReturn(false);
    SampleBean sampleBean = mapper.map(resultSet, ctx);
    Long expected = 123L;
    assertThat(sampleBean.getLongField()).isEqualTo(expected);
    assertThat(sampleBean.getValueTypeField()).isEqualTo(ValueType.valueOf("foo"));
}
Also used : ValueTypeMapper(org.jdbi.v3.core.mapper.ValueTypeMapper) SampleBean(org.jdbi.v3.core.SampleBean) Test(org.junit.Test)

Aggregations

SampleBean (org.jdbi.v3.core.SampleBean)2 ValueTypeMapper (org.jdbi.v3.core.mapper.ValueTypeMapper)2 Test (org.junit.Test)2