Search in sources :

Example 11 with SampleBean

use of org.jdbi.v3.core.SampleBean 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 12 with SampleBean

use of org.jdbi.v3.core.SampleBean in project jdbi by jdbi.

the class BeanMapperTest method shouldSetValueOnPublicSetter.

@Test
public void shouldSetValueOnPublicSetter() throws Exception {
    mockColumns("longField");
    Long aLongVal = 100L;
    mockLongResult(aLongVal);
    SampleBean sampleBean = mapper.map(resultSet, ctx);
    assertThat(sampleBean.getLongField()).isEqualTo(aLongVal);
}
Also used : SampleBean(org.jdbi.v3.core.SampleBean) Test(org.junit.Test)

Example 13 with SampleBean

use of org.jdbi.v3.core.SampleBean in project jdbi by jdbi.

the class BeanMapperTest method shouldBeCaseInSensitiveOfColumnAndPropertyNames.

@Test
public void shouldBeCaseInSensitiveOfColumnAndPropertyNames() throws Exception {
    mockColumns("LoNgfielD");
    Long aLongVal = 100L;
    mockLongResult(aLongVal);
    SampleBean sampleBean = mapper.map(resultSet, ctx);
    assertThat(sampleBean.getLongField()).isEqualTo(aLongVal);
}
Also used : SampleBean(org.jdbi.v3.core.SampleBean) Test(org.junit.Test)

Example 14 with SampleBean

use of org.jdbi.v3.core.SampleBean 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)

Example 15 with SampleBean

use of org.jdbi.v3.core.SampleBean in project jdbi by jdbi.

the class FieldMapperTest method shouldHandleNullValue.

@Test
public void shouldHandleNullValue() throws Exception {
    mockColumns("LoNgfielD");
    when(resultSet.getLong(1)).thenReturn(0L);
    when(resultSet.wasNull()).thenReturn(true);
    SampleBean sampleBean = mapper.map(resultSet, ctx);
    assertThat(sampleBean.getLongField()).isNull();
}
Also used : SampleBean(org.jdbi.v3.core.SampleBean) Test(org.junit.Test)

Aggregations

SampleBean (org.jdbi.v3.core.SampleBean)16 Test (org.junit.Test)16 ValueTypeMapper (org.jdbi.v3.core.mapper.ValueTypeMapper)2 BigDecimal (java.math.BigDecimal)1