Browse Source

Polishing

pull/31496/head
Juergen Hoeller 2 years ago
parent
commit
2aae0a4e0c
  1. 6
      spring-jdbc/src/test/java/org/springframework/jdbc/core/BeanPropertyRowMapperTests.java
  2. 49
      spring-jdbc/src/test/java/org/springframework/jdbc/core/support/LobSupportTests.java

6
spring-jdbc/src/test/java/org/springframework/jdbc/core/BeanPropertyRowMapperTests.java

@ -50,7 +50,7 @@ class BeanPropertyRowMapperTests extends AbstractRowMapperTests { @@ -50,7 +50,7 @@ class BeanPropertyRowMapperTests extends AbstractRowMapperTests {
void overridingDifferentClassDefinedForMapping() {
BeanPropertyRowMapper mapper = new BeanPropertyRowMapper(Person.class);
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(() -> mapper.setMappedClass(Long.class));
.isThrownBy(() -> mapper.setMappedClass(Long.class));
}
@Test
@ -104,7 +104,7 @@ class BeanPropertyRowMapperTests extends AbstractRowMapperTests { @@ -104,7 +104,7 @@ class BeanPropertyRowMapperTests extends AbstractRowMapperTests {
BeanPropertyRowMapper<ExtendedPerson> 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", mapper));
.isThrownBy(() -> mock.getJdbcTemplate().query("select name, age, birth_date, balance from people", mapper));
}
@Test
@ -112,7 +112,7 @@ class BeanPropertyRowMapperTests extends AbstractRowMapperTests { @@ -112,7 +112,7 @@ class BeanPropertyRowMapperTests extends AbstractRowMapperTests {
BeanPropertyRowMapper<Person> mapper = new BeanPropertyRowMapper<>(Person.class);
Mock mock = new Mock(MockType.TWO);
assertThatExceptionOfType(TypeMismatchException.class)
.isThrownBy(() -> mock.getJdbcTemplate().query(SELECT_NULL_AS_AGE, mapper));
.isThrownBy(() -> mock.getJdbcTemplate().query(SELECT_NULL_AS_AGE, mapper));
}
@Test

49
spring-jdbc/src/test/java/org/springframework/jdbc/core/support/LobSupportTests.java

@ -23,7 +23,6 @@ import java.sql.SQLException; @@ -23,7 +23,6 @@ import java.sql.SQLException;
import org.junit.jupiter.api.Test;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.jdbc.LobRetrievalFailureException;
import org.springframework.jdbc.support.lob.LobCreator;
@ -55,11 +54,9 @@ public class LobSupportTests { @@ -55,11 +54,9 @@ public class LobSupportTests {
final SetValuesCalled svc = new SetValuesCalled();
AbstractLobCreatingPreparedStatementCallback psc = new AbstractLobCreatingPreparedStatementCallback(
handler) {
AbstractLobCreatingPreparedStatementCallback psc = new AbstractLobCreatingPreparedStatementCallback(handler) {
@Override
protected void setValues(PreparedStatement ps, LobCreator lobCreator)
throws SQLException, DataAccessException {
protected void setValues(PreparedStatement ps, LobCreator lobCreator) {
svc.b = true;
}
};
@ -73,46 +70,43 @@ public class LobSupportTests { @@ -73,46 +70,43 @@ public class LobSupportTests {
@Test
public void testAbstractLobStreamingResultSetExtractorNoRows() throws SQLException {
ResultSet rset = mock();
ResultSet rs = mock();
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(false);
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class).isThrownBy(() ->
lobRse.extractData(rset));
verify(rset).next();
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class)
.isThrownBy(() -> lobRse.extractData(rs));
verify(rs).next();
}
@Test
public void testAbstractLobStreamingResultSetExtractorOneRow() throws SQLException {
ResultSet rset = mock();
given(rset.next()).willReturn(true, false);
ResultSet rs = mock();
given(rs.next()).willReturn(true, false);
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(false);
lobRse.extractData(rset);
verify(rset).clearWarnings();
lobRse.extractData(rs);
verify(rs).clearWarnings();
}
@Test
public void testAbstractLobStreamingResultSetExtractorMultipleRows()
throws SQLException {
ResultSet rset = mock();
given(rset.next()).willReturn(true, true, false);
public void testAbstractLobStreamingResultSetExtractorMultipleRows() throws SQLException {
ResultSet rs = mock();
given(rs.next()).willReturn(true, true, false);
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(false);
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class).isThrownBy(() ->
lobRse.extractData(rset));
verify(rset).clearWarnings();
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class)
.isThrownBy(() -> lobRse.extractData(rs));
verify(rs).clearWarnings();
}
@Test
public void testAbstractLobStreamingResultSetExtractorCorrectException()
throws SQLException {
ResultSet rset = mock();
given(rset.next()).willReturn(true);
public void testAbstractLobStreamingResultSetExtractorCorrectException() throws SQLException {
ResultSet rs = mock();
given(rs.next()).willReturn(true);
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(true);
assertThatExceptionOfType(LobRetrievalFailureException.class).isThrownBy(() ->
lobRse.extractData(rset));
assertThatExceptionOfType(LobRetrievalFailureException.class)
.isThrownBy(() -> lobRse.extractData(rs));
}
private AbstractLobStreamingResultSetExtractor<Void> getResultSetExtractor(final boolean ex) {
AbstractLobStreamingResultSetExtractor<Void> lobRse = new AbstractLobStreamingResultSetExtractor<>() {
@Override
protected void streamData(ResultSet rs) throws SQLException, IOException {
if (ex) {
@ -125,4 +119,5 @@ public class LobSupportTests { @@ -125,4 +119,5 @@ public class LobSupportTests {
};
return lobRse;
}
}

Loading…
Cancel
Save