Browse Source

Polishing

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

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

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

Loading…
Cancel
Save