Unit tests for record binding

See gh-27437
This commit is contained in:
Juergen Hoeller
2021-09-23 16:13:20 +02:00
parent 0241c5ebb3
commit f440fb8baf
3 changed files with 128 additions and 79 deletions

View File

@@ -89,7 +89,7 @@ public abstract class AbstractRowMapperTests {
verifyPersonViaBeanWrapper(person);
}
private void verifyPersonViaBeanWrapper(Object person) {
protected void verifyPersonViaBeanWrapper(Object person) {
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(person);
assertThat(bw.getPropertyValue("name")).isEqualTo("Bubba");
assertThat(bw.getPropertyValue("age")).isEqualTo(22L);

View File

@@ -79,4 +79,28 @@ public class DataClassRowMapperTests extends AbstractRowMapperTests {
mock.verifyClosed();
}
@Test
public void testStaticQueryWithDataRecord() throws Exception {
Mock mock = new Mock();
List<RecordPerson> result = mock.getJdbcTemplate().query(
"select name, age, birth_date, balance from people",
new DataClassRowMapper<>(RecordPerson.class));
assertThat(result.size()).isEqualTo(1);
verifyPerson(result.get(0));
mock.verifyClosed();
}
protected void verifyPerson(RecordPerson person) {
assertThat(person.name()).isEqualTo("Bubba");
assertThat(person.age()).isEqualTo(22L);
assertThat(person.birth_date()).usingComparator(Date::compareTo).isEqualTo(new java.util.Date(1221222L));
assertThat(person.balance()).isEqualTo(new BigDecimal("1234.56"));
verifyPersonViaBeanWrapper(person);
}
static record RecordPerson(String name, long age, Date birth_date, BigDecimal balance) {
}
}