@ -31,74 +31,77 @@ import org.springframework.jdbc.core.test.SpacePerson;
@@ -31,74 +31,77 @@ import org.springframework.jdbc.core.test.SpacePerson;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType ;
import static org.assertj.core.api.Assertions.assertThatNoException ;
/ * *
* Tests for { @link BeanPropertyRowMapper } .
*
* @author Thomas Risberg
* @author Juergen Hoeller
* @author Sam Brannen
* /
public class BeanPropertyRowMapperTests extends AbstractRowMapperTests {
class BeanPropertyRowMapperTests extends AbstractRowMapperTests {
@Test
@SuppressWarnings ( { "unchecked" , "rawtypes" } )
public void testO verridingDifferentClassDefinedForMapping( ) {
void o verridingDifferentClassDefinedForMapping( ) {
BeanPropertyRowMapper mapper = new BeanPropertyRowMapper ( Person . class ) ;
assertThatExceptionOfType ( InvalidDataAccessApiUsageException . class ) . isThrownBy ( ( ) - >
mapper . setMappedClass ( Long . class ) ) ;
}
@Test
public void testO verridingSameClassDefinedForMapping( ) {
void o verridingSameClassDefinedForMapping( ) {
BeanPropertyRowMapper < Person > mapper = new BeanPropertyRowMapper < > ( Person . class ) ;
mapper . setMappedClass ( Person . class ) ;
assertThatNoException ( ) . isThrownBy ( ( ) - > mapper . setMappedClass ( Person . class ) ) ;
}
@Test
public void te stS taticQueryWithRowMapper( ) throws Exception {
void staticQueryWithRowMapper ( ) throws Exception {
Mock mock = new Mock ( ) ;
List < Person > result = mock . getJdbcTemplate ( ) . query (
"select name, age, birth_date, balance from people" ,
new BeanPropertyRowMapper < > ( Person . class ) ) ;
assertThat ( result . size ( ) ) . isEqualTo ( 1 ) ;
assertThat ( result ) . hasSize ( 1 ) ;
verifyPerson ( result . get ( 0 ) ) ;
mock . verifyClosed ( ) ;
}
@Test
public void testM appingWithInheritance( ) throws Exception {
void m appingWithInheritance( ) throws Exception {
Mock mock = new Mock ( ) ;
List < ConcretePerson > result = mock . getJdbcTemplate ( ) . query (
"select name, age, birth_date, balance from people" ,
new BeanPropertyRowMapper < > ( ConcretePerson . class ) ) ;
assertThat ( result . size ( ) ) . isEqualTo ( 1 ) ;
assertThat ( result ) . hasSize ( 1 ) ;
verifyPerson ( result . get ( 0 ) ) ;
mock . verifyClosed ( ) ;
}
@Test
public void testM appingWithNoUnpopulatedFieldsFound( ) throws Exception {
void m appingWithNoUnpopulatedFieldsFound( ) throws Exception {
Mock mock = new Mock ( ) ;
List < ConcretePerson > result = mock . getJdbcTemplate ( ) . query (
"select name, age, birth_date, balance from people" ,
new BeanPropertyRowMapper < > ( ConcretePerson . class , true ) ) ;
assertThat ( result . size ( ) ) . isEqualTo ( 1 ) ;
assertThat ( result ) . hasSize ( 1 ) ;
verifyPerson ( result . get ( 0 ) ) ;
mock . verifyClosed ( ) ;
}
@Test
public void testM appingWithUnpopulatedFieldsNotChecked( ) throws Exception {
void m appingWithUnpopulatedFieldsNotChecked( ) throws Exception {
Mock mock = new Mock ( ) ;
List < ExtendedPerson > result = mock . getJdbcTemplate ( ) . query (
"select name, age, birth_date, balance from people" ,
new BeanPropertyRowMapper < > ( ExtendedPerson . class ) ) ;
assertThat ( result . size ( ) ) . isEqualTo ( 1 ) ;
ExtendedPerson bean = result . get ( 0 ) ;
verifyPerson ( bean ) ;
assertThat ( result ) . hasSize ( 1 ) ;
verifyPerson ( result . get ( 0 ) ) ;
mock . verifyClosed ( ) ;
}
@Test
public void testM appingWithUnpopulatedFieldsNotAccepted( ) throws Exception {
void m appingWithUnpopulatedFieldsNotAccepted( ) throws Exception {
Mock mock = new Mock ( ) ;
assertThatExceptionOfType ( InvalidDataAccessApiUsageException . class ) . isThrownBy ( ( ) - >
mock . getJdbcTemplate ( ) . query ( "select name, age, birth_date, balance from people" ,
@ -106,7 +109,7 @@ public class BeanPropertyRowMapperTests extends AbstractRowMapperTests {
@@ -106,7 +109,7 @@ public class BeanPropertyRowMapperTests extends AbstractRowMapperTests {
}
@Test
public void testM appingNullValue( ) throws Exception {
void m appingNullValue( ) throws Exception {
BeanPropertyRowMapper < Person > mapper = new BeanPropertyRowMapper < > ( Person . class ) ;
Mock mock = new Mock ( MockType . TWO ) ;
assertThatExceptionOfType ( TypeMismatchException . class ) . isThrownBy ( ( ) - >
@ -114,34 +117,34 @@ public class BeanPropertyRowMapperTests extends AbstractRowMapperTests {
@@ -114,34 +117,34 @@ public class BeanPropertyRowMapperTests extends AbstractRowMapperTests {
}
@Test
public void testQ ueryWithSpaceInColumnNameAndLocalDateTime( ) throws Exception {
void q ueryWithSpaceInColumnNameAndLocalDateTime( ) throws Exception {
Mock mock = new Mock ( MockType . THREE ) ;
List < SpacePerson > result = mock . getJdbcTemplate ( ) . query (
"select last_name as \"Last Name\", age, birth_date, balance from people" ,
new BeanPropertyRowMapper < > ( SpacePerson . class ) ) ;
assertThat ( result . size ( ) ) . isEqualTo ( 1 ) ;
assertThat ( result ) . hasSize ( 1 ) ;
verifyPerson ( result . get ( 0 ) ) ;
mock . verifyClosed ( ) ;
}
@Test
public void testQ ueryWithSpaceInColumnNameAndLocalDate( ) throws Exception {
void q ueryWithSpaceInColumnNameAndLocalDate( ) throws Exception {
Mock mock = new Mock ( MockType . THREE ) ;
List < DatePerson > result = mock . getJdbcTemplate ( ) . query (
"select last_name as \"Last Name\", age, birth_date, balance from people" ,
new BeanPropertyRowMapper < > ( DatePerson . class ) ) ;
assertThat ( result . size ( ) ) . isEqualTo ( 1 ) ;
assertThat ( result ) . hasSize ( 1 ) ;
verifyPerson ( result . get ( 0 ) ) ;
mock . verifyClosed ( ) ;
}
@Test
public void testQueryWithUnderscor eAndPersonWithMultipleAdjacentUppercaseLettersInPropertyName( ) throws Exception {
void queryWithUnderscoreInColumnNam eAndPersonWithMultipleAdjacentUppercaseLettersInPropertyName( ) throws Exception {
Mock mock = new Mock ( ) ;
List < EmailPerson > result = mock . getJdbcTemplate ( ) . query (
"select name, age, birth_date, balance, e_mail from people" ,
new BeanPropertyRowMapper < > ( EmailPerson . class ) ) ;
assertThat ( result . size ( ) ) . isEqualTo ( 1 ) ;
assertThat ( result ) . hasSize ( 1 ) ;
verifyPerson ( result . get ( 0 ) ) ;
mock . verifyClosed ( ) ;
}