Skip to content

Commit

Permalink
Unit tests for record binding
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Sep 23, 2021
1 parent 0241c5e commit f440fb8
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 79 deletions.
Expand Up @@ -89,7 +89,7 @@ protected void verifyPerson(ConstructorPerson person) {
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);
Expand Down
Expand Up @@ -79,4 +79,28 @@ public void testStaticQueryWithDataClassAndSetters() throws Exception {
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) {
}

}

0 comments on commit f440fb8

Please sign in to comment.