Search in sources :

Example 6 with SampleBean

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

the class FieldMapperTest method shouldNotThrowOnMismatchedColumns.

@Test
public void shouldNotThrowOnMismatchedColumns() throws Exception {
    mockColumns("longField", "extraColumn");
    Long expected = 666L;
    when(resultSet.getLong(1)).thenReturn(expected);
    when(resultSet.getString(2)).thenReturn("foo");
    SampleBean sampleBean = mapper.map(resultSet, ctx);
    assertThat(sampleBean.getLongField()).isEqualTo(expected);
}
Also used : SampleBean(org.jdbi.v3.core.SampleBean) Test(org.junit.Test)

Example 7 with SampleBean

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

the class FieldMapperTest method shouldHandleEmptyResult.

@Test
public void shouldHandleEmptyResult() throws Exception {
    mockColumns();
    SampleBean sampleBean = mapper.map(resultSet, ctx);
    assertThat(sampleBean).isNotNull();
}
Also used : SampleBean(org.jdbi.v3.core.SampleBean) Test(org.junit.Test)

Example 8 with SampleBean

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

the class FieldMapperTest method shouldSetValuesOnAllFieldAccessTypes.

@Test
public void shouldSetValuesOnAllFieldAccessTypes() throws Exception {
    mockColumns("longField", "protectedStringField", "packagePrivateIntField", "privateBigDecimalField");
    Long aLongVal = 100L;
    String aStringVal = "something";
    int aIntVal = 1;
    BigDecimal aBigDecimal = BigDecimal.TEN;
    when(resultSet.getLong(1)).thenReturn(aLongVal);
    when(resultSet.getString(2)).thenReturn(aStringVal);
    when(resultSet.getInt(3)).thenReturn(aIntVal);
    when(resultSet.getBigDecimal(4)).thenReturn(aBigDecimal);
    when(resultSet.wasNull()).thenReturn(false);
    SampleBean sampleBean = mapper.map(resultSet, ctx);
    assertThat(sampleBean.getLongField()).isEqualTo(aLongVal);
    assertThat(sampleBean.getPrivateBigDecimalField()).isEqualTo(aBigDecimal);
    assertThat(sampleBean.getPackagePrivateIntField()).isEqualTo(aIntVal);
    assertThat(sampleBean.getProtectedStringField()).isEqualTo(aStringVal);
}
Also used : SampleBean(org.jdbi.v3.core.SampleBean) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 9 with SampleBean

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

the class BeanMapperTest method shouldSetValuesOnPublicSetter.

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

Example 10 with SampleBean

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

the class BeanMapperTest method shouldNotThrowOnMismatchedColumns.

@Test
public void shouldNotThrowOnMismatchedColumns() throws Exception {
    mockColumns("longField", "extraColumn");
    Long expected = 666L;
    when(resultSet.getLong(1)).thenReturn(expected);
    when(resultSet.getString(2)).thenReturn("foo");
    SampleBean sampleBean = mapper.map(resultSet, ctx);
    assertThat(sampleBean.getLongField()).isEqualTo(expected);
}
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