From 420ff46b2acfc91a945a12a1ae0ea11f61b43e3e Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 17 Jan 2022 16:46:00 +0100 Subject: [PATCH] Polishing --- .../jdbc/core/BeanPropertyRowMapperTests.java | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/BeanPropertyRowMapperTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/BeanPropertyRowMapperTests.java index c61bab0a297..8cb5cd45d79 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/BeanPropertyRowMapperTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/BeanPropertyRowMapperTests.java @@ -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 testOverridingDifferentClassDefinedForMapping() { + void overridingDifferentClassDefinedForMapping() { BeanPropertyRowMapper mapper = new BeanPropertyRowMapper(Person.class); assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> mapper.setMappedClass(Long.class)); } @Test - public void testOverridingSameClassDefinedForMapping() { + void overridingSameClassDefinedForMapping() { BeanPropertyRowMapper mapper = new BeanPropertyRowMapper<>(Person.class); - mapper.setMappedClass(Person.class); + assertThatNoException().isThrownBy(() -> mapper.setMappedClass(Person.class)); } @Test - public void testStaticQueryWithRowMapper() throws Exception { + void staticQueryWithRowMapper() throws Exception { Mock mock = new Mock(); List 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 testMappingWithInheritance() throws Exception { + void mappingWithInheritance() throws Exception { Mock mock = new Mock(); List 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 testMappingWithNoUnpopulatedFieldsFound() throws Exception { + void mappingWithNoUnpopulatedFieldsFound() throws Exception { Mock mock = new Mock(); List 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 testMappingWithUnpopulatedFieldsNotChecked() throws Exception { + void mappingWithUnpopulatedFieldsNotChecked() throws Exception { Mock mock = new Mock(); List 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 testMappingWithUnpopulatedFieldsNotAccepted() throws Exception { + void mappingWithUnpopulatedFieldsNotAccepted() 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 { } @Test - public void testMappingNullValue() throws Exception { + void mappingNullValue() throws Exception { BeanPropertyRowMapper mapper = new BeanPropertyRowMapper<>(Person.class); Mock mock = new Mock(MockType.TWO); assertThatExceptionOfType(TypeMismatchException.class).isThrownBy(() -> @@ -114,34 +117,34 @@ public class BeanPropertyRowMapperTests extends AbstractRowMapperTests { } @Test - public void testQueryWithSpaceInColumnNameAndLocalDateTime() throws Exception { + void queryWithSpaceInColumnNameAndLocalDateTime() throws Exception { Mock mock = new Mock(MockType.THREE); List 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 testQueryWithSpaceInColumnNameAndLocalDate() throws Exception { + void queryWithSpaceInColumnNameAndLocalDate() throws Exception { Mock mock = new Mock(MockType.THREE); List 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 testQueryWithUnderscoreAndPersonWithMultipleAdjacentUppercaseLettersInPropertyName() throws Exception { + void queryWithUnderscoreInColumnNameAndPersonWithMultipleAdjacentUppercaseLettersInPropertyName() throws Exception { Mock mock = new Mock(); List 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(); }