From 84bc1dfa89e979232c4a36e9d75bb50b1d48453e Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 3 Feb 2023 17:47:07 +0100 Subject: [PATCH] Polish RowMapper tests --- .../jdbc/core/BeanPropertyRowMapperTests.java | 14 +++++++------- .../jdbc/core/DataClassRowMapperTests.java | 18 +++++++++--------- 2 files changed, 16 insertions(+), 16 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 4d1d53e6367..0b558f5f2fd 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 @@ -51,8 +51,8 @@ class BeanPropertyRowMapperTests extends AbstractRowMapperTests { @SuppressWarnings({"unchecked", "rawtypes"}) void overridingDifferentClassDefinedForMapping() { BeanPropertyRowMapper mapper = new BeanPropertyRowMapper(Person.class); - assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> - mapper.setMappedClass(Long.class)); + assertThatExceptionOfType(InvalidDataAccessApiUsageException.class) + .isThrownBy(() -> mapper.setMappedClass(Long.class)); } @Test @@ -107,18 +107,18 @@ class BeanPropertyRowMapperTests extends AbstractRowMapperTests { @Test void mappingWithUnpopulatedFieldsNotAccepted() throws Exception { + BeanPropertyRowMapper mapper = new BeanPropertyRowMapper<>(ExtendedPerson.class, true); Mock mock = new Mock(); - assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> - mock.getJdbcTemplate().query("select name, age, birth_date, balance from people", - new BeanPropertyRowMapper<>(ExtendedPerson.class, true))); + assertThatExceptionOfType(InvalidDataAccessApiUsageException.class) + .isThrownBy(() -> mock.getJdbcTemplate().query("select name, age, birth_date, balance from people", mapper)); } @Test void mappingNullValue() throws Exception { BeanPropertyRowMapper mapper = new BeanPropertyRowMapper<>(Person.class); Mock mock = new Mock(MockType.TWO); - assertThatExceptionOfType(TypeMismatchException.class).isThrownBy(() -> - mock.getJdbcTemplate().query(SELECT_NULL_AS_AGE, mapper)); + assertThatExceptionOfType(TypeMismatchException.class) + .isThrownBy(() -> mock.getJdbcTemplate().query(SELECT_NULL_AS_AGE, mapper)); } @Test diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/DataClassRowMapperTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/DataClassRowMapperTests.java index 9a87d2c6775..8dc18636d0c 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/DataClassRowMapperTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/DataClassRowMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,10 +33,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Juergen Hoeller * @since 5.3 */ -public class DataClassRowMapperTests extends AbstractRowMapperTests { +class DataClassRowMapperTests extends AbstractRowMapperTests { @Test - public void testStaticQueryWithDataClass() throws Exception { + void staticQueryWithDataClass() throws Exception { Mock mock = new Mock(); List result = mock.getJdbcTemplate().query( "select name, age, birth_date, balance from people", @@ -48,7 +48,7 @@ public class DataClassRowMapperTests extends AbstractRowMapperTests { } @Test - public void testStaticQueryWithDataClassAndGenerics() throws Exception { + void staticQueryWithDataClassAndGenerics() throws Exception { Mock mock = new Mock(); List result = mock.getJdbcTemplate().query( "select name, age, birth_date, balance from people", @@ -57,14 +57,14 @@ public class DataClassRowMapperTests extends AbstractRowMapperTests { ConstructorPersonWithGenerics person = result.get(0); assertThat(person.name()).isEqualTo("Bubba"); assertThat(person.age()).isEqualTo(22L); - assertThat(person.birthDate()).usingComparator(Date::compareTo).isEqualTo(new java.util.Date(1221222L)); + assertThat(person.birthDate()).usingComparator(Date::compareTo).isEqualTo(new Date(1221222L)); assertThat(person.balance()).isEqualTo(Collections.singletonList(new BigDecimal("1234.56"))); mock.verifyClosed(); } @Test - public void testStaticQueryWithDataClassAndSetters() throws Exception { + void staticQueryWithDataClassAndSetters() throws Exception { Mock mock = new Mock(MockType.FOUR); List result = mock.getJdbcTemplate().query( "select name, age, birthdate, balance from people", @@ -73,14 +73,14 @@ public class DataClassRowMapperTests extends AbstractRowMapperTests { ConstructorPersonWithSetters person = result.get(0); assertThat(person.name()).isEqualTo("BUBBA"); assertThat(person.age()).isEqualTo(22L); - assertThat(person.birthDate()).usingComparator(Date::compareTo).isEqualTo(new java.util.Date(1221222L)); + assertThat(person.birthDate()).usingComparator(Date::compareTo).isEqualTo(new Date(1221222L)); assertThat(person.balance()).isEqualTo(new BigDecimal("1234.56")); mock.verifyClosed(); } @Test - public void testStaticQueryWithDataRecord() throws Exception { + void staticQueryWithDataRecord() throws Exception { Mock mock = new Mock(); List result = mock.getJdbcTemplate().query( "select name, age, birth_date, balance from people", @@ -94,7 +94,7 @@ public class DataClassRowMapperTests extends AbstractRowMapperTests { 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.birth_date()).usingComparator(Date::compareTo).isEqualTo(new Date(1221222L)); assertThat(person.balance()).isEqualTo(new BigDecimal("1234.56")); verifyPersonViaBeanWrapper(person); }