Migrate to Mockito.mock(T...) where feasible
This commit is contained in:
@@ -120,27 +120,23 @@ public abstract class AbstractRowMapperTests {
|
||||
|
||||
protected static class Mock {
|
||||
|
||||
private Connection connection;
|
||||
private Connection connection = mock();
|
||||
|
||||
private ResultSetMetaData resultSetMetaData;
|
||||
private ResultSetMetaData resultSetMetaData = mock();
|
||||
|
||||
private ResultSet resultSet;
|
||||
private ResultSet resultSet = mock();
|
||||
|
||||
private Statement statement;
|
||||
private Statement statement = mock();
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
|
||||
public Mock() throws Exception {
|
||||
this(MockType.ONE);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Mock(MockType type) throws Exception {
|
||||
connection = mock(Connection.class);
|
||||
statement = mock(Statement.class);
|
||||
resultSet = mock(ResultSet.class);
|
||||
resultSetMetaData = mock(ResultSetMetaData.class);
|
||||
|
||||
given(connection.createStatement()).willReturn(statement);
|
||||
given(statement.executeQuery(anyString())).willReturn(resultSet);
|
||||
given(resultSet.getMetaData()).willReturn(resultSetMetaData);
|
||||
|
||||
@@ -50,30 +50,23 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class JdbcTemplateQueryTests {
|
||||
|
||||
private Connection connection;
|
||||
private Connection connection = mock();
|
||||
|
||||
private DataSource dataSource;
|
||||
private DataSource dataSource = mock();
|
||||
|
||||
private Statement statement;
|
||||
private Statement statement = mock();
|
||||
|
||||
private PreparedStatement preparedStatement;
|
||||
private PreparedStatement preparedStatement = mock();
|
||||
|
||||
private ResultSet resultSet;
|
||||
private ResultSet resultSet = mock();
|
||||
|
||||
private ResultSetMetaData resultSetMetaData;
|
||||
private ResultSetMetaData resultSetMetaData = mock();
|
||||
|
||||
private JdbcTemplate template;
|
||||
private JdbcTemplate template = new JdbcTemplate(this.dataSource);
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
this.connection = mock(Connection.class);
|
||||
this.dataSource = mock(DataSource.class);
|
||||
this.statement = mock(Statement.class);
|
||||
this.preparedStatement = mock(PreparedStatement.class);
|
||||
this.resultSet = mock(ResultSet.class);
|
||||
this.resultSetMetaData = mock(ResultSetMetaData.class);
|
||||
this.template = new JdbcTemplate(this.dataSource);
|
||||
given(this.dataSource.getConnection()).willReturn(this.connection);
|
||||
given(this.resultSet.getMetaData()).willReturn(this.resultSetMetaData);
|
||||
given(this.resultSetMetaData.getColumnCount()).willReturn(1);
|
||||
|
||||
@@ -75,30 +75,23 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class JdbcTemplateTests {
|
||||
|
||||
private Connection connection;
|
||||
private Connection connection = mock();
|
||||
|
||||
private DataSource dataSource;
|
||||
private DataSource dataSource = mock();
|
||||
|
||||
private PreparedStatement preparedStatement;
|
||||
private Statement statement = mock();
|
||||
|
||||
private Statement statement;
|
||||
private PreparedStatement preparedStatement = mock();
|
||||
|
||||
private ResultSet resultSet;
|
||||
private ResultSet resultSet = mock();
|
||||
|
||||
private JdbcTemplate template;
|
||||
private CallableStatement callableStatement = mock();
|
||||
|
||||
private CallableStatement callableStatement;
|
||||
private JdbcTemplate template = new JdbcTemplate(this.dataSource);
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
this.connection = mock(Connection.class);
|
||||
this.dataSource = mock(DataSource.class);
|
||||
this.preparedStatement = mock(PreparedStatement.class);
|
||||
this.statement = mock(Statement.class);
|
||||
this.resultSet = mock(ResultSet.class);
|
||||
this.template = new JdbcTemplate(this.dataSource);
|
||||
this.callableStatement = mock(CallableStatement.class);
|
||||
given(this.dataSource.getConnection()).willReturn(this.connection);
|
||||
given(this.connection.prepareStatement(anyString())).willReturn(this.preparedStatement);
|
||||
given(this.preparedStatement.executeQuery()).willReturn(this.resultSet);
|
||||
@@ -779,7 +772,6 @@ public class JdbcTemplateTests {
|
||||
@Test
|
||||
public void testCouldNotGetConnectionForOperationOrExceptionTranslator() throws SQLException {
|
||||
SQLException sqlException = new SQLException("foo", "07xxx");
|
||||
this.dataSource = mock(DataSource.class);
|
||||
given(this.dataSource.getConnection()).willThrow(sqlException);
|
||||
JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
|
||||
RowCountCallbackHandler rcch = new RowCountCallbackHandler();
|
||||
@@ -792,7 +784,6 @@ public class JdbcTemplateTests {
|
||||
@Test
|
||||
public void testCouldNotGetConnectionForOperationWithLazyExceptionTranslator() throws SQLException {
|
||||
SQLException sqlException = new SQLException("foo", "07xxx");
|
||||
this.dataSource = mock(DataSource.class);
|
||||
given(this.dataSource.getConnection()).willThrow(sqlException);
|
||||
this.template = new JdbcTemplate();
|
||||
this.template.setDataSource(this.dataSource);
|
||||
@@ -826,7 +817,6 @@ public class JdbcTemplateTests {
|
||||
throws SQLException {
|
||||
|
||||
SQLException sqlException = new SQLException("foo", "07xxx");
|
||||
this.dataSource = mock(DataSource.class);
|
||||
given(this.dataSource.getConnection()).willThrow(sqlException);
|
||||
this.template = new JdbcTemplate();
|
||||
this.template.setDataSource(this.dataSource);
|
||||
@@ -1008,7 +998,7 @@ public class JdbcTemplateTests {
|
||||
|
||||
@Test
|
||||
public void testStaticResultSetClosed() throws Exception {
|
||||
ResultSet resultSet2 = mock(ResultSet.class);
|
||||
ResultSet resultSet2 = mock();
|
||||
reset(this.preparedStatement);
|
||||
given(this.preparedStatement.executeQuery()).willReturn(resultSet2);
|
||||
given(this.connection.createStatement()).willReturn(this.statement);
|
||||
@@ -1071,7 +1061,7 @@ public class JdbcTemplateTests {
|
||||
public void testEquallyNamedColumn() throws SQLException {
|
||||
given(this.connection.createStatement()).willReturn(this.statement);
|
||||
|
||||
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
|
||||
ResultSetMetaData metaData = mock();
|
||||
given(metaData.getColumnCount()).willReturn(2);
|
||||
given(metaData.getColumnLabel(1)).willReturn("x");
|
||||
given(metaData.getColumnLabel(2)).willReturn("X");
|
||||
@@ -1088,7 +1078,7 @@ public class JdbcTemplateTests {
|
||||
|
||||
|
||||
private void mockDatabaseMetaData(boolean supportsBatchUpdates) throws SQLException {
|
||||
DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
|
||||
DatabaseMetaData databaseMetaData = mock();
|
||||
given(databaseMetaData.getDatabaseProductName()).willReturn("MySQL");
|
||||
given(databaseMetaData.supportsBatchUpdates()).willReturn(supportsBatchUpdates);
|
||||
given(this.connection.getMetaData()).willReturn(databaseMetaData);
|
||||
|
||||
@@ -45,13 +45,13 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class RowMapperTests {
|
||||
|
||||
private final Connection connection = mock(Connection.class);
|
||||
private final Connection connection = mock();
|
||||
|
||||
private final Statement statement = mock(Statement.class);
|
||||
private final Statement statement = mock();
|
||||
|
||||
private final PreparedStatement preparedStatement = mock(PreparedStatement.class);
|
||||
private final PreparedStatement preparedStatement = mock();
|
||||
|
||||
private final ResultSet resultSet = mock(ResultSet.class);
|
||||
private final ResultSet resultSet = mock();
|
||||
|
||||
private final JdbcTemplate template = new JdbcTemplate();
|
||||
|
||||
|
||||
@@ -47,8 +47,8 @@ public class SingleColumnRowMapperTests {
|
||||
|
||||
SingleColumnRowMapper<LocalDateTime> rowMapper = SingleColumnRowMapper.newInstance(LocalDateTime.class);
|
||||
|
||||
ResultSet resultSet = mock(ResultSet.class);
|
||||
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
|
||||
ResultSet resultSet = mock();
|
||||
ResultSetMetaData metaData = mock();
|
||||
given(metaData.getColumnCount()).willReturn(1);
|
||||
given(resultSet.getMetaData()).willReturn(metaData);
|
||||
given(resultSet.getObject(1, LocalDateTime.class))
|
||||
@@ -70,8 +70,8 @@ public class SingleColumnRowMapperTests {
|
||||
SingleColumnRowMapper<MyLocalDateTime> rowMapper =
|
||||
SingleColumnRowMapper.newInstance(MyLocalDateTime.class, myConversionService);
|
||||
|
||||
ResultSet resultSet = mock(ResultSet.class);
|
||||
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
|
||||
ResultSet resultSet = mock();
|
||||
ResultSetMetaData metaData = mock();
|
||||
given(metaData.getColumnCount()).willReturn(1);
|
||||
given(resultSet.getMetaData()).willReturn(metaData);
|
||||
given(resultSet.getObject(1, MyLocalDateTime.class))
|
||||
@@ -89,8 +89,8 @@ public class SingleColumnRowMapperTests {
|
||||
SingleColumnRowMapper<LocalDateTime> rowMapper =
|
||||
SingleColumnRowMapper.newInstance(LocalDateTime.class, null);
|
||||
|
||||
ResultSet resultSet = mock(ResultSet.class);
|
||||
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
|
||||
ResultSet resultSet = mock();
|
||||
ResultSetMetaData metaData = mock();
|
||||
given(metaData.getColumnCount()).willReturn(1);
|
||||
given(resultSet.getMetaData()).willReturn(metaData);
|
||||
given(resultSet.getObject(1, LocalDateTime.class))
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -38,13 +37,7 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class StatementCreatorUtilsTests {
|
||||
|
||||
private PreparedStatement preparedStatement;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
preparedStatement = mock(PreparedStatement.class);
|
||||
}
|
||||
private PreparedStatement preparedStatement = mock();
|
||||
|
||||
|
||||
@Test
|
||||
@@ -62,8 +55,8 @@ public class StatementCreatorUtilsTests {
|
||||
@Test
|
||||
public void testSetParameterValueWithNullAndUnknownType() throws SQLException {
|
||||
StatementCreatorUtils.shouldIgnoreGetParameterType = true;
|
||||
Connection con = mock(Connection.class);
|
||||
DatabaseMetaData dbmd = mock(DatabaseMetaData.class);
|
||||
Connection con = mock();
|
||||
DatabaseMetaData dbmd = mock();
|
||||
given(preparedStatement.getConnection()).willReturn(con);
|
||||
given(dbmd.getDatabaseProductName()).willReturn("Oracle");
|
||||
given(dbmd.getDriverName()).willReturn("Oracle Driver");
|
||||
@@ -76,8 +69,8 @@ public class StatementCreatorUtilsTests {
|
||||
@Test
|
||||
public void testSetParameterValueWithNullAndUnknownTypeOnInformix() throws SQLException {
|
||||
StatementCreatorUtils.shouldIgnoreGetParameterType = true;
|
||||
Connection con = mock(Connection.class);
|
||||
DatabaseMetaData dbmd = mock(DatabaseMetaData.class);
|
||||
Connection con = mock();
|
||||
DatabaseMetaData dbmd = mock();
|
||||
given(preparedStatement.getConnection()).willReturn(con);
|
||||
given(con.getMetaData()).willReturn(dbmd);
|
||||
given(dbmd.getDatabaseProductName()).willReturn("Informix Dynamic Server");
|
||||
@@ -92,8 +85,8 @@ public class StatementCreatorUtilsTests {
|
||||
@Test
|
||||
public void testSetParameterValueWithNullAndUnknownTypeOnDerbyEmbedded() throws SQLException {
|
||||
StatementCreatorUtils.shouldIgnoreGetParameterType = true;
|
||||
Connection con = mock(Connection.class);
|
||||
DatabaseMetaData dbmd = mock(DatabaseMetaData.class);
|
||||
Connection con = mock();
|
||||
DatabaseMetaData dbmd = mock();
|
||||
given(preparedStatement.getConnection()).willReturn(con);
|
||||
given(con.getMetaData()).willReturn(dbmd);
|
||||
given(dbmd.getDatabaseProductName()).willReturn("Apache Derby");
|
||||
@@ -107,7 +100,7 @@ public class StatementCreatorUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testSetParameterValueWithNullAndGetParameterTypeWorking() throws SQLException {
|
||||
ParameterMetaData pmd = mock(ParameterMetaData.class);
|
||||
ParameterMetaData pmd = mock();
|
||||
given(preparedStatement.getParameterMetaData()).willReturn(pmd);
|
||||
given(pmd.getParameterType(1)).willReturn(Types.SMALLINT);
|
||||
StatementCreatorUtils.setParameterValue(preparedStatement, 1, SqlTypeValue.TYPE_UNKNOWN, null, null);
|
||||
@@ -212,8 +205,8 @@ public class StatementCreatorUtilsTests {
|
||||
|
||||
@Test // SPR-8571
|
||||
public void testSetParameterValueWithStringAndVendorSpecificType() throws SQLException {
|
||||
Connection con = mock(Connection.class);
|
||||
DatabaseMetaData dbmd = mock(DatabaseMetaData.class);
|
||||
Connection con = mock();
|
||||
DatabaseMetaData dbmd = mock();
|
||||
given(preparedStatement.getConnection()).willReturn(con);
|
||||
given(dbmd.getDatabaseProductName()).willReturn("Oracle");
|
||||
given(con.getMetaData()).willReturn(dbmd);
|
||||
@@ -224,8 +217,8 @@ public class StatementCreatorUtilsTests {
|
||||
@Test // SPR-8571
|
||||
public void testSetParameterValueWithNullAndVendorSpecificType() throws SQLException {
|
||||
StatementCreatorUtils.shouldIgnoreGetParameterType = true;
|
||||
Connection con = mock(Connection.class);
|
||||
DatabaseMetaData dbmd = mock(DatabaseMetaData.class);
|
||||
Connection con = mock();
|
||||
DatabaseMetaData dbmd = mock();
|
||||
given(preparedStatement.getConnection()).willReturn(con);
|
||||
given(dbmd.getDatabaseProductName()).willReturn("Oracle");
|
||||
given(dbmd.getDriverName()).willReturn("Oracle Driver");
|
||||
|
||||
@@ -83,29 +83,23 @@ public class NamedParameterJdbcTemplateTests {
|
||||
private static final String[] COLUMN_NAMES = new String[] {"id", "forename"};
|
||||
|
||||
|
||||
private Connection connection;
|
||||
private Connection connection = mock();
|
||||
|
||||
private DataSource dataSource;
|
||||
private DataSource dataSource = mock();
|
||||
|
||||
private PreparedStatement preparedStatement;
|
||||
private PreparedStatement preparedStatement = mock();
|
||||
|
||||
private ResultSet resultSet;
|
||||
private ResultSet resultSet = mock();
|
||||
|
||||
private DatabaseMetaData databaseMetaData;
|
||||
private DatabaseMetaData databaseMetaData = mock();
|
||||
|
||||
private NamedParameterJdbcTemplate namedParameterTemplate = new NamedParameterJdbcTemplate(dataSource);
|
||||
|
||||
private Map<String, Object> params = new HashMap<>();
|
||||
|
||||
private NamedParameterJdbcTemplate namedParameterTemplate;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
connection = mock(Connection.class);
|
||||
dataSource = mock(DataSource.class);
|
||||
preparedStatement = mock(PreparedStatement.class);
|
||||
resultSet = mock(ResultSet.class);
|
||||
namedParameterTemplate = new NamedParameterJdbcTemplate(dataSource);
|
||||
databaseMetaData = mock(DatabaseMetaData.class);
|
||||
given(dataSource.getConnection()).willReturn(connection);
|
||||
given(connection.prepareStatement(anyString())).willReturn(preparedStatement);
|
||||
given(preparedStatement.getConnection()).willReturn(connection);
|
||||
|
||||
@@ -48,27 +48,21 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class NamedParameterQueryTests {
|
||||
|
||||
private DataSource dataSource;
|
||||
private Connection connection = mock();
|
||||
|
||||
private Connection connection;
|
||||
private DataSource dataSource = mock();
|
||||
|
||||
private PreparedStatement preparedStatement;
|
||||
private PreparedStatement preparedStatement = mock();
|
||||
|
||||
private ResultSet resultSet;
|
||||
private ResultSet resultSet = mock();
|
||||
|
||||
private ResultSetMetaData resultSetMetaData;
|
||||
private ResultSetMetaData resultSetMetaData = mock();
|
||||
|
||||
private NamedParameterJdbcTemplate template;
|
||||
private NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dataSource);
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
connection = mock(Connection.class);
|
||||
dataSource = mock(DataSource.class);
|
||||
preparedStatement = mock(PreparedStatement.class);
|
||||
resultSet = mock(ResultSet.class);
|
||||
resultSetMetaData = mock(ResultSetMetaData.class);
|
||||
template = new NamedParameterJdbcTemplate(dataSource);
|
||||
given(dataSource.getConnection()).willReturn(connection);
|
||||
given(resultSetMetaData.getColumnCount()).willReturn(1);
|
||||
given(resultSetMetaData.getColumnLabel(1)).willReturn("age");
|
||||
|
||||
@@ -47,21 +47,18 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class CallMetaDataContextTests {
|
||||
|
||||
private DataSource dataSource;
|
||||
private DataSource dataSource = mock();
|
||||
|
||||
private Connection connection;
|
||||
private Connection connection = mock();
|
||||
|
||||
private DatabaseMetaData databaseMetaData;
|
||||
private DatabaseMetaData databaseMetaData = mock();
|
||||
|
||||
private CallMetaDataContext context = new CallMetaDataContext();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
connection = mock(Connection.class);
|
||||
databaseMetaData = mock(DatabaseMetaData.class);
|
||||
given(connection.getMetaData()).willReturn(databaseMetaData);
|
||||
dataSource = mock(DataSource.class);
|
||||
given(dataSource.getConnection()).willReturn(connection);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,13 +50,13 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
class SimpleJdbcCallTests {
|
||||
|
||||
private final Connection connection = mock(Connection.class);
|
||||
private final Connection connection = mock();
|
||||
|
||||
private final DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
|
||||
private final DatabaseMetaData databaseMetaData = mock();
|
||||
|
||||
private final DataSource dataSource = mock(DataSource.class);
|
||||
private final DataSource dataSource = mock();
|
||||
|
||||
private final CallableStatement callableStatement = mock(CallableStatement.class);
|
||||
private final CallableStatement callableStatement = mock();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -233,8 +233,8 @@ class SimpleJdbcCallTests {
|
||||
*/
|
||||
@Test // gh-26486
|
||||
void exceptionThrownWhileRetrievingColumnNamesFromMetadata() throws Exception {
|
||||
ResultSet proceduresResultSet = mock(ResultSet.class);
|
||||
ResultSet procedureColumnsResultSet = mock(ResultSet.class);
|
||||
ResultSet proceduresResultSet = mock();
|
||||
ResultSet procedureColumnsResultSet = mock();
|
||||
|
||||
given(databaseMetaData.getDatabaseProductName()).willReturn("Oracle");
|
||||
given(databaseMetaData.getUserName()).willReturn("ME");
|
||||
@@ -301,8 +301,8 @@ class SimpleJdbcCallTests {
|
||||
}
|
||||
|
||||
private void initializeAddInvoiceWithMetaData(boolean isFunction) throws SQLException {
|
||||
ResultSet proceduresResultSet = mock(ResultSet.class);
|
||||
ResultSet procedureColumnsResultSet = mock(ResultSet.class);
|
||||
ResultSet proceduresResultSet = mock();
|
||||
ResultSet procedureColumnsResultSet = mock();
|
||||
given(databaseMetaData.getDatabaseProductName()).willReturn("Oracle");
|
||||
given(databaseMetaData.getUserName()).willReturn("ME");
|
||||
given(databaseMetaData.storesUpperCaseIdentifiers()).willReturn(true);
|
||||
|
||||
@@ -45,11 +45,11 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
class SimpleJdbcInsertTests {
|
||||
|
||||
private final Connection connection = mock(Connection.class);
|
||||
private final Connection connection = mock();
|
||||
|
||||
private final DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
|
||||
private final DatabaseMetaData databaseMetaData = mock();
|
||||
|
||||
private final DataSource dataSource = mock(DataSource.class);
|
||||
private final DataSource dataSource = mock();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -66,7 +66,7 @@ class SimpleJdbcInsertTests {
|
||||
|
||||
@Test
|
||||
void noSuchTable() throws Exception {
|
||||
ResultSet resultSet = mock(ResultSet.class);
|
||||
ResultSet resultSet = mock();
|
||||
given(resultSet.next()).willReturn(false);
|
||||
|
||||
given(databaseMetaData.getDatabaseProductName()).willReturn("MyDB");
|
||||
@@ -86,13 +86,13 @@ class SimpleJdbcInsertTests {
|
||||
|
||||
@Test // gh-26486
|
||||
void retrieveColumnNamesFromMetadata() throws Exception {
|
||||
ResultSet tableResultSet = mock(ResultSet.class);
|
||||
ResultSet tableResultSet = mock();
|
||||
given(tableResultSet.next()).willReturn(true, false);
|
||||
|
||||
given(databaseMetaData.getUserName()).willReturn("me");
|
||||
given(databaseMetaData.getTables(null, null, "me", null)).willReturn(tableResultSet);
|
||||
|
||||
ResultSet columnResultSet = mock(ResultSet.class);
|
||||
ResultSet columnResultSet = mock();
|
||||
given(databaseMetaData.getColumns(null, "me", null, null)).willReturn(columnResultSet);
|
||||
given(columnResultSet.next()).willReturn(true, true, false);
|
||||
given(columnResultSet.getString("COLUMN_NAME")).willReturn("col1", "col2");
|
||||
@@ -109,13 +109,13 @@ class SimpleJdbcInsertTests {
|
||||
|
||||
@Test // gh-26486
|
||||
void exceptionThrownWhileRetrievingColumnNamesFromMetadata() throws Exception {
|
||||
ResultSet tableResultSet = mock(ResultSet.class);
|
||||
ResultSet tableResultSet = mock();
|
||||
given(tableResultSet.next()).willReturn(true, false);
|
||||
|
||||
given(databaseMetaData.getUserName()).willReturn("me");
|
||||
given(databaseMetaData.getTables(null, null, "me", null)).willReturn(tableResultSet);
|
||||
|
||||
ResultSet columnResultSet = mock(ResultSet.class);
|
||||
ResultSet columnResultSet = mock();
|
||||
given(databaseMetaData.getColumns(null, "me", null, null)).willReturn(columnResultSet);
|
||||
// true, true, false --> simulates processing of two columns
|
||||
given(columnResultSet.next()).willReturn(true, true, false);
|
||||
|
||||
@@ -44,22 +44,19 @@ import static org.mockito.Mockito.verify;
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
*/
|
||||
public class TableMetaDataContextTests {
|
||||
public class TableMetaDataContextTests {
|
||||
|
||||
private Connection connection;
|
||||
private DataSource dataSource = mock();
|
||||
|
||||
private DataSource dataSource;
|
||||
private Connection connection = mock();
|
||||
|
||||
private DatabaseMetaData databaseMetaData;
|
||||
private DatabaseMetaData databaseMetaData = mock();
|
||||
|
||||
private TableMetaDataContext context = new TableMetaDataContext();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
connection = mock(Connection.class);
|
||||
dataSource = mock(DataSource.class);
|
||||
databaseMetaData = mock(DatabaseMetaData.class);
|
||||
given(connection.getMetaData()).willReturn(databaseMetaData);
|
||||
given(dataSource.getConnection()).willReturn(connection);
|
||||
}
|
||||
@@ -70,13 +67,13 @@ public class TableMetaDataContextTests {
|
||||
final String TABLE = "customers";
|
||||
final String USER = "me";
|
||||
|
||||
ResultSet metaDataResultSet = mock(ResultSet.class);
|
||||
ResultSet metaDataResultSet = mock();
|
||||
given(metaDataResultSet.next()).willReturn(true, false);
|
||||
given(metaDataResultSet.getString("TABLE_SCHEM")).willReturn(USER);
|
||||
given(metaDataResultSet.getString("TABLE_NAME")).willReturn(TABLE);
|
||||
given(metaDataResultSet.getString("TABLE_TYPE")).willReturn("TABLE");
|
||||
|
||||
ResultSet columnsResultSet = mock(ResultSet.class);
|
||||
ResultSet columnsResultSet = mock();
|
||||
given(columnsResultSet.next()).willReturn(
|
||||
true, true, true, true, false);
|
||||
given(columnsResultSet.getString("COLUMN_NAME")).willReturn(
|
||||
@@ -126,13 +123,13 @@ public class TableMetaDataContextTests {
|
||||
final String TABLE = "customers";
|
||||
final String USER = "me";
|
||||
|
||||
ResultSet metaDataResultSet = mock(ResultSet.class);
|
||||
ResultSet metaDataResultSet = mock();
|
||||
given(metaDataResultSet.next()).willReturn(true, false);
|
||||
given(metaDataResultSet.getString("TABLE_SCHEM")).willReturn(USER);
|
||||
given(metaDataResultSet.getString("TABLE_NAME")).willReturn(TABLE);
|
||||
given(metaDataResultSet.getString("TABLE_TYPE")).willReturn("TABLE");
|
||||
|
||||
ResultSet columnsResultSet = mock(ResultSet.class);
|
||||
ResultSet columnsResultSet = mock();
|
||||
given(columnsResultSet.next()).willReturn(true, false);
|
||||
given(columnsResultSet.getString("COLUMN_NAME")).willReturn("id");
|
||||
given(columnsResultSet.getInt("DATA_TYPE")).willReturn(Types.INTEGER);
|
||||
|
||||
@@ -42,17 +42,17 @@ class JdbcBeanDefinitionReaderTests {
|
||||
void readBeanDefinitionFromMockedDataSource() throws Exception {
|
||||
String sql = "SELECT NAME AS NAME, PROPERTY AS PROPERTY, VALUE AS VALUE FROM T";
|
||||
|
||||
Connection connection = mock(Connection.class);
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
Connection connection = mock();
|
||||
DataSource dataSource = mock();
|
||||
given(dataSource.getConnection()).willReturn(connection);
|
||||
|
||||
ResultSet resultSet = mock(ResultSet.class);
|
||||
ResultSet resultSet = mock();
|
||||
given(resultSet.next()).willReturn(true, true, false);
|
||||
given(resultSet.getString(1)).willReturn("one", "one");
|
||||
given(resultSet.getString(2)).willReturn("(class)", "age");
|
||||
given(resultSet.getString(3)).willReturn("org.springframework.beans.testfixture.beans.TestBean", "53");
|
||||
|
||||
Statement statement = mock(Statement.class);
|
||||
Statement statement = mock();
|
||||
given(statement.executeQuery(sql)).willReturn(resultSet);
|
||||
given(connection.createStatement()).willReturn(statement);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public class JdbcDaoSupportTests {
|
||||
|
||||
@Test
|
||||
public void testJdbcDaoSupportWithDataSource() throws Exception {
|
||||
DataSource ds = mock(DataSource.class);
|
||||
DataSource ds = mock();
|
||||
final List<String> test = new ArrayList<>();
|
||||
JdbcDaoSupport dao = new JdbcDaoSupport() {
|
||||
@Override
|
||||
|
||||
@@ -42,9 +42,9 @@ public class LobSupportTests {
|
||||
|
||||
@Test
|
||||
public void testCreatingPreparedStatementCallback() throws SQLException {
|
||||
LobHandler handler = mock(LobHandler.class);
|
||||
LobCreator creator = mock(LobCreator.class);
|
||||
PreparedStatement ps = mock(PreparedStatement.class);
|
||||
LobHandler handler = mock();
|
||||
LobCreator creator = mock();
|
||||
PreparedStatement ps = mock();
|
||||
|
||||
given(handler.getLobCreator()).willReturn(creator);
|
||||
given(ps.executeUpdate()).willReturn(3);
|
||||
@@ -73,7 +73,7 @@ public class LobSupportTests {
|
||||
|
||||
@Test
|
||||
public void testAbstractLobStreamingResultSetExtractorNoRows() throws SQLException {
|
||||
ResultSet rset = mock(ResultSet.class);
|
||||
ResultSet rset = mock();
|
||||
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(false);
|
||||
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class).isThrownBy(() ->
|
||||
lobRse.extractData(rset));
|
||||
@@ -82,7 +82,7 @@ public class LobSupportTests {
|
||||
|
||||
@Test
|
||||
public void testAbstractLobStreamingResultSetExtractorOneRow() throws SQLException {
|
||||
ResultSet rset = mock(ResultSet.class);
|
||||
ResultSet rset = mock();
|
||||
given(rset.next()).willReturn(true, false);
|
||||
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(false);
|
||||
lobRse.extractData(rset);
|
||||
@@ -92,7 +92,7 @@ public class LobSupportTests {
|
||||
@Test
|
||||
public void testAbstractLobStreamingResultSetExtractorMultipleRows()
|
||||
throws SQLException {
|
||||
ResultSet rset = mock(ResultSet.class);
|
||||
ResultSet rset = mock();
|
||||
given(rset.next()).willReturn(true, true, false);
|
||||
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(false);
|
||||
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class).isThrownBy(() ->
|
||||
@@ -103,7 +103,7 @@ public class LobSupportTests {
|
||||
@Test
|
||||
public void testAbstractLobStreamingResultSetExtractorCorrectException()
|
||||
throws SQLException {
|
||||
ResultSet rset = mock(ResultSet.class);
|
||||
ResultSet rset = mock();
|
||||
given(rset.next()).willReturn(true);
|
||||
AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(true);
|
||||
assertThatExceptionOfType(LobRetrievalFailureException.class).isThrownBy(() ->
|
||||
|
||||
@@ -63,19 +63,18 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class DataSourceJtaTransactionTests {
|
||||
|
||||
private Connection connection;
|
||||
private DataSource dataSource;
|
||||
private UserTransaction userTransaction;
|
||||
private TransactionManager transactionManager;
|
||||
private Transaction transaction;
|
||||
private DataSource dataSource = mock();
|
||||
|
||||
private Connection connection = mock();
|
||||
|
||||
private UserTransaction userTransaction = mock();
|
||||
|
||||
private TransactionManager transactionManager = mock();
|
||||
|
||||
private Transaction transaction = mock();
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
connection =mock(Connection.class);
|
||||
dataSource = mock(DataSource.class);
|
||||
userTransaction = mock(UserTransaction.class);
|
||||
transactionManager = mock(TransactionManager.class);
|
||||
transaction = mock(Transaction.class);
|
||||
given(dataSource.getConnection()).willReturn(connection);
|
||||
}
|
||||
|
||||
@@ -365,9 +364,9 @@ public class DataSourceJtaTransactionTests {
|
||||
Status.STATUS_ACTIVE);
|
||||
}
|
||||
|
||||
final DataSource dataSource = mock(DataSource.class);
|
||||
final Connection connection1 = mock(Connection.class);
|
||||
final Connection connection2 = mock(Connection.class);
|
||||
final DataSource dataSource = mock();
|
||||
final Connection connection1 = mock();
|
||||
final Connection connection2 = mock();
|
||||
given(dataSource.getConnection()).willReturn(connection1, connection2);
|
||||
|
||||
final JtaTransactionManager ptm = new JtaTransactionManager(userTransaction, transactionManager);
|
||||
@@ -686,14 +685,15 @@ public class DataSourceJtaTransactionTests {
|
||||
}
|
||||
|
||||
private void doTestJtaTransactionWithIsolationLevelDataSourceRouter(boolean dataSourceLookup) throws Exception {
|
||||
given( userTransaction.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE, Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
|
||||
given(userTransaction.getStatus())
|
||||
.willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE, Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
|
||||
|
||||
final DataSource dataSource1 = mock(DataSource.class);
|
||||
final Connection connection1 = mock(Connection.class);
|
||||
final DataSource dataSource1 = mock();
|
||||
final Connection connection1 = mock();
|
||||
given(dataSource1.getConnection()).willReturn(connection1);
|
||||
|
||||
final DataSource dataSource2 = mock(DataSource.class);
|
||||
final Connection connection2 = mock(Connection.class);
|
||||
final DataSource dataSource2 = mock();
|
||||
final Connection connection2 = mock();
|
||||
given(dataSource2.getConnection()).willReturn(connection2);
|
||||
|
||||
final IsolationLevelDataSourceRouter dsToUse = new IsolationLevelDataSourceRouter();
|
||||
|
||||
@@ -67,21 +67,18 @@ import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING;
|
||||
* @since 04.07.2003
|
||||
* @see org.springframework.jdbc.support.JdbcTransactionManagerTests
|
||||
*/
|
||||
public class DataSourceTransactionManagerTests {
|
||||
public class DataSourceTransactionManagerTests {
|
||||
|
||||
private DataSource ds;
|
||||
private DataSource ds = mock();
|
||||
|
||||
private Connection con;
|
||||
private Connection con = mock();
|
||||
|
||||
private DataSourceTransactionManager tm;
|
||||
private DataSourceTransactionManager tm = new DataSourceTransactionManager(ds);
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
ds = mock(DataSource.class);
|
||||
con = mock(Connection.class);
|
||||
given(ds.getConnection()).willReturn(con);
|
||||
tm = new DataSourceTransactionManager(ds);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@@ -515,8 +512,8 @@ public class DataSourceTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testParticipatingTransactionWithDifferentConnectionObtainedFromSynch() throws Exception {
|
||||
DataSource ds2 = mock(DataSource.class);
|
||||
final Connection con2 = mock(Connection.class);
|
||||
DataSource ds2 = mock();
|
||||
final Connection con2 = mock();
|
||||
given(ds2.getConnection()).willReturn(con2);
|
||||
|
||||
boolean condition2 = !TransactionSynchronizationManager.hasResource(ds);
|
||||
@@ -651,8 +648,8 @@ public class DataSourceTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testPropagationRequiresNewWithExistingTransactionAndUnrelatedDataSource() throws Exception {
|
||||
Connection con2 = mock(Connection.class);
|
||||
final DataSource ds2 = mock(DataSource.class);
|
||||
Connection con2 = mock();
|
||||
final DataSource ds2 = mock();
|
||||
given(ds2.getConnection()).willReturn(con2);
|
||||
|
||||
final TransactionTemplate tt = new TransactionTemplate(tm);
|
||||
@@ -705,7 +702,7 @@ public class DataSourceTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testPropagationRequiresNewWithExistingTransactionAndUnrelatedFailingDataSource() throws Exception {
|
||||
final DataSource ds2 = mock(DataSource.class);
|
||||
final DataSource ds2 = mock();
|
||||
SQLException failure = new SQLException();
|
||||
given(ds2.getConnection()).willThrow(failure);
|
||||
|
||||
@@ -857,8 +854,8 @@ public class DataSourceTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testPropagationSupportsAndRequiresNewWithEarlyAccess() throws Exception {
|
||||
final Connection con1 = mock(Connection.class);
|
||||
final Connection con2 = mock(Connection.class);
|
||||
final Connection con1 = mock();
|
||||
final Connection con2 = mock();
|
||||
given(ds.getConnection()).willReturn(con1, con2);
|
||||
|
||||
final
|
||||
@@ -936,7 +933,7 @@ public class DataSourceTransactionManagerTests {
|
||||
tm.setEnforceReadOnly(true);
|
||||
|
||||
given(con.getAutoCommit()).willReturn(true);
|
||||
Statement stmt = mock(Statement.class);
|
||||
Statement stmt = mock();
|
||||
given(con.createStatement()).willReturn(stmt);
|
||||
|
||||
TransactionTemplate tt = new TransactionTemplate(tm);
|
||||
@@ -970,7 +967,7 @@ public class DataSourceTransactionManagerTests {
|
||||
@ValueSource(ints = {1, 10})
|
||||
@EnabledForTestGroups(LONG_RUNNING)
|
||||
public void transactionWithTimeout(int timeout) throws Exception {
|
||||
PreparedStatement ps = mock(PreparedStatement.class);
|
||||
PreparedStatement ps = mock();
|
||||
given(con.getAutoCommit()).willReturn(true);
|
||||
given(con.prepareStatement("some SQL statement")).willReturn(ps);
|
||||
|
||||
@@ -1342,8 +1339,8 @@ public class DataSourceTransactionManagerTests {
|
||||
}
|
||||
|
||||
private void doTestExistingTransactionWithPropagationNested(final int count) throws Exception {
|
||||
DatabaseMetaData md = mock(DatabaseMetaData.class);
|
||||
Savepoint sp = mock(Savepoint.class);
|
||||
DatabaseMetaData md = mock();
|
||||
Savepoint sp = mock();
|
||||
|
||||
given(md.supportsSavepoints()).willReturn(true);
|
||||
given(con.getMetaData()).willReturn(md);
|
||||
@@ -1391,8 +1388,8 @@ public class DataSourceTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testExistingTransactionWithPropagationNestedAndRollback() throws Exception {
|
||||
DatabaseMetaData md = mock(DatabaseMetaData.class);
|
||||
Savepoint sp = mock(Savepoint.class);
|
||||
DatabaseMetaData md = mock();
|
||||
Savepoint sp = mock();
|
||||
|
||||
given(md.supportsSavepoints()).willReturn(true);
|
||||
given(con.getMetaData()).willReturn(md);
|
||||
@@ -1438,8 +1435,8 @@ public class DataSourceTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testExistingTransactionWithPropagationNestedAndRequiredRollback() throws Exception {
|
||||
DatabaseMetaData md = mock(DatabaseMetaData.class);
|
||||
Savepoint sp = mock(Savepoint.class);
|
||||
DatabaseMetaData md = mock();
|
||||
Savepoint sp = mock();
|
||||
|
||||
given(md.supportsSavepoints()).willReturn(true);
|
||||
given(con.getMetaData()).willReturn(md);
|
||||
@@ -1498,8 +1495,8 @@ public class DataSourceTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testExistingTransactionWithPropagationNestedAndRequiredRollbackOnly() throws Exception {
|
||||
DatabaseMetaData md = mock(DatabaseMetaData.class);
|
||||
Savepoint sp = mock(Savepoint.class);
|
||||
DatabaseMetaData md = mock();
|
||||
Savepoint sp = mock();
|
||||
|
||||
given(md.supportsSavepoints()).willReturn(true);
|
||||
given(con.getMetaData()).willReturn(md);
|
||||
@@ -1558,8 +1555,8 @@ public class DataSourceTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testExistingTransactionWithManualSavepoint() throws Exception {
|
||||
DatabaseMetaData md = mock(DatabaseMetaData.class);
|
||||
Savepoint sp = mock(Savepoint.class);
|
||||
DatabaseMetaData md = mock();
|
||||
Savepoint sp = mock();
|
||||
|
||||
given(md.supportsSavepoints()).willReturn(true);
|
||||
given(con.getMetaData()).willReturn(md);
|
||||
@@ -1592,8 +1589,8 @@ public class DataSourceTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testExistingTransactionWithManualSavepointAndRollback() throws Exception {
|
||||
DatabaseMetaData md = mock(DatabaseMetaData.class);
|
||||
Savepoint sp = mock(Savepoint.class);
|
||||
DatabaseMetaData md = mock();
|
||||
Savepoint sp = mock();
|
||||
|
||||
given(md.supportsSavepoints()).willReturn(true);
|
||||
given(con.getMetaData()).willReturn(md);
|
||||
|
||||
@@ -38,7 +38,7 @@ class DataSourceUtilsTests {
|
||||
|
||||
@Test
|
||||
void testConnectionNotAcquiredExceptionIsPropagated() throws SQLException {
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
DataSource dataSource = mock();
|
||||
when(dataSource.getConnection()).thenReturn(null);
|
||||
assertThatThrownBy(() -> DataSourceUtils.getConnection(dataSource))
|
||||
.isInstanceOf(CannotGetJdbcConnectionException.class)
|
||||
@@ -48,7 +48,7 @@ class DataSourceUtilsTests {
|
||||
|
||||
@Test
|
||||
void testConnectionSQLExceptionIsPropagated() throws SQLException {
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
DataSource dataSource = mock();
|
||||
when(dataSource.getConnection()).thenThrow(new SQLException("my dummy exception"));
|
||||
assertThatThrownBy(() -> DataSourceUtils.getConnection(dataSource))
|
||||
.isInstanceOf(CannotGetJdbcConnectionException.class)
|
||||
|
||||
@@ -36,20 +36,20 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class DelegatingDataSourceTests {
|
||||
|
||||
private final DataSource delegate = mock(DataSource.class);
|
||||
private final DataSource delegate = mock();
|
||||
|
||||
private DelegatingDataSource dataSource = new DelegatingDataSource(delegate);
|
||||
|
||||
@Test
|
||||
public void shouldDelegateGetConnection() throws Exception {
|
||||
Connection connection = mock(Connection.class);
|
||||
Connection connection = mock();
|
||||
given(delegate.getConnection()).willReturn(connection);
|
||||
assertThat(dataSource.getConnection()).isEqualTo(connection);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDelegateGetConnectionWithUsernameAndPassword() throws Exception {
|
||||
Connection connection = mock(Connection.class);
|
||||
Connection connection = mock();
|
||||
String username = "username";
|
||||
String password = "password";
|
||||
given(delegate.getConnection(username, password)).willReturn(connection);
|
||||
@@ -86,7 +86,7 @@ public class DelegatingDataSourceTests {
|
||||
|
||||
@Test
|
||||
public void shouldDelegateUnwrapWithoutImplementing() throws Exception {
|
||||
ExampleWrapper wrapper = mock(ExampleWrapper.class);
|
||||
ExampleWrapper wrapper = mock();
|
||||
given(delegate.unwrap(ExampleWrapper.class)).willReturn(wrapper);
|
||||
assertThat(dataSource.unwrap(ExampleWrapper.class)).isEqualTo(wrapper);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class DriverManagerDataSourceTests {
|
||||
|
||||
private Connection connection = mock(Connection.class);
|
||||
private Connection connection = mock();
|
||||
|
||||
@Test
|
||||
public void testStandardUsage() throws Exception {
|
||||
|
||||
@@ -35,8 +35,8 @@ public class UserCredentialsDataSourceAdapterTests {
|
||||
|
||||
@Test
|
||||
public void testStaticCredentials() throws SQLException {
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
Connection connection = mock(Connection.class);
|
||||
DataSource dataSource = mock();
|
||||
Connection connection = mock();
|
||||
given(dataSource.getConnection("user", "pw")).willReturn(connection);
|
||||
|
||||
UserCredentialsDataSourceAdapter adapter = new UserCredentialsDataSourceAdapter();
|
||||
@@ -48,8 +48,8 @@ public class UserCredentialsDataSourceAdapterTests {
|
||||
|
||||
@Test
|
||||
public void testNoCredentials() throws SQLException {
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
Connection connection = mock(Connection.class);
|
||||
DataSource dataSource = mock();
|
||||
Connection connection = mock();
|
||||
given(dataSource.getConnection()).willReturn(connection);
|
||||
UserCredentialsDataSourceAdapter adapter = new UserCredentialsDataSourceAdapter();
|
||||
adapter.setTargetDataSource(dataSource);
|
||||
@@ -58,8 +58,8 @@ public class UserCredentialsDataSourceAdapterTests {
|
||||
|
||||
@Test
|
||||
public void testThreadBoundCredentials() throws SQLException {
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
Connection connection = mock(Connection.class);
|
||||
DataSource dataSource = mock();
|
||||
Connection connection = mock();
|
||||
given(dataSource.getConnection("user", "pw")).willReturn(connection);
|
||||
|
||||
UserCredentialsDataSourceAdapter adapter = new UserCredentialsDataSourceAdapter();
|
||||
|
||||
@@ -169,7 +169,7 @@ abstract class AbstractDatabasePopulatorTests extends AbstractDatabaseInitializa
|
||||
void usesBoundConnectionIfAvailable() throws SQLException {
|
||||
TransactionSynchronizationManager.initSynchronization();
|
||||
Connection connection = DataSourceUtils.getConnection(db);
|
||||
DatabasePopulator populator = mock(DatabasePopulator.class);
|
||||
DatabasePopulator populator = mock();
|
||||
DatabasePopulatorUtils.execute(populator, db);
|
||||
verify(populator).populate(connection);
|
||||
}
|
||||
|
||||
@@ -36,11 +36,11 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
class CompositeDatabasePopulatorTests {
|
||||
|
||||
private final Connection mockedConnection = mock(Connection.class);
|
||||
private final Connection mockedConnection = mock();
|
||||
|
||||
private final DatabasePopulator mockedDatabasePopulator1 = mock(DatabasePopulator.class);
|
||||
private final DatabasePopulator mockedDatabasePopulator1 = mock();
|
||||
|
||||
private final DatabasePopulator mockedDatabasePopulator2 = mock(DatabasePopulator.class);
|
||||
private final DatabasePopulator mockedDatabasePopulator2 = mock();
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
@@ -33,9 +33,9 @@ import static org.mockito.BDDMockito.mock;
|
||||
*/
|
||||
class ResourceDatabasePopulatorUnitTests {
|
||||
|
||||
private static final Resource script1 = mock(Resource.class);
|
||||
private static final Resource script2 = mock(Resource.class);
|
||||
private static final Resource script3 = mock(Resource.class);
|
||||
private static final Resource script1 = mock();
|
||||
private static final Resource script2 = mock();
|
||||
private static final Resource script3 = mock();
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
@@ -41,7 +41,7 @@ public class BeanFactoryDataSourceLookupTests {
|
||||
|
||||
@Test
|
||||
public void testLookupSunnyDay() {
|
||||
BeanFactory beanFactory = mock(BeanFactory.class);
|
||||
BeanFactory beanFactory = mock();
|
||||
|
||||
StubDataSource expectedDataSource = new StubDataSource();
|
||||
given(beanFactory.getBean(DATASOURCE_BEAN_NAME, DataSource.class)).willReturn(expectedDataSource);
|
||||
@@ -56,7 +56,7 @@ public class BeanFactoryDataSourceLookupTests {
|
||||
|
||||
@Test
|
||||
public void testLookupWhereBeanFactoryYieldsNonDataSourceType() throws Exception {
|
||||
final BeanFactory beanFactory = mock(BeanFactory.class);
|
||||
final BeanFactory beanFactory = mock();
|
||||
|
||||
given(beanFactory.getBean(DATASOURCE_BEAN_NAME, DataSource.class)).willThrow(
|
||||
new BeanNotOfRequiredTypeException(DATASOURCE_BEAN_NAME,
|
||||
|
||||
@@ -54,14 +54,14 @@ public class BatchSqlUpdateTests {
|
||||
final int[] ids = new int[] { 100, 200 };
|
||||
final int[] rowsAffected = new int[] { 1, 2 };
|
||||
|
||||
Connection connection = mock(Connection.class);
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
Connection connection = mock();
|
||||
DataSource dataSource = mock();
|
||||
given(dataSource.getConnection()).willReturn(connection);
|
||||
PreparedStatement preparedStatement = mock(PreparedStatement.class);
|
||||
PreparedStatement preparedStatement = mock();
|
||||
given(preparedStatement.getConnection()).willReturn(connection);
|
||||
given(preparedStatement.executeBatch()).willReturn(rowsAffected);
|
||||
|
||||
DatabaseMetaData mockDatabaseMetaData = mock(DatabaseMetaData.class);
|
||||
DatabaseMetaData mockDatabaseMetaData = mock();
|
||||
given(mockDatabaseMetaData.supportsBatchUpdates()).willReturn(true);
|
||||
given(connection.prepareStatement(sql)).willReturn(preparedStatement);
|
||||
given(connection.getMetaData()).willReturn(mockDatabaseMetaData);
|
||||
|
||||
@@ -50,24 +50,21 @@ public class GenericSqlQueryTests {
|
||||
private static final String SELECT_ID_FORENAME_NAMED_PARAMETERS_PARSED =
|
||||
"select id, forename from custmr where id = ? and country = ?";
|
||||
|
||||
private DefaultListableBeanFactory beanFactory;
|
||||
|
||||
private Connection connection;
|
||||
private DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
|
||||
private PreparedStatement preparedStatement;
|
||||
private Connection connection = mock();
|
||||
|
||||
private ResultSet resultSet;
|
||||
private PreparedStatement preparedStatement = mock();
|
||||
|
||||
private ResultSet resultSet = mock();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
this.beanFactory = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
|
||||
new ClassPathResource("org/springframework/jdbc/object/GenericSqlQueryTests-context.xml"));
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
this.connection = mock(Connection.class);
|
||||
this.preparedStatement = mock(PreparedStatement.class);
|
||||
this.resultSet = mock(ResultSet.class);
|
||||
DataSource dataSource = mock();
|
||||
given(dataSource.getConnection()).willReturn(connection);
|
||||
TestDataSourceWrapper testDataSource = (TestDataSourceWrapper) beanFactory.getBean("dataSource");
|
||||
testDataSource.setTarget(dataSource);
|
||||
|
||||
@@ -46,10 +46,10 @@ public class GenericStoredProcedureTests {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
new ClassPathResource("org/springframework/jdbc/object/GenericStoredProcedureTests-context.xml"));
|
||||
Connection connection = mock(Connection.class);
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
Connection connection = mock();
|
||||
DataSource dataSource = mock();
|
||||
given(dataSource.getConnection()).willReturn(connection);
|
||||
CallableStatement callableStatement = mock(CallableStatement.class);
|
||||
CallableStatement callableStatement = mock();
|
||||
TestDataSourceWrapper testDataSource = (TestDataSourceWrapper) bf.getBean("dataSource");
|
||||
testDataSource.setTarget(dataSource);
|
||||
|
||||
|
||||
@@ -85,18 +85,18 @@ public class SqlQueryTests {
|
||||
private static final String[] COLUMN_NAMES = new String[] {"id", "forename"};
|
||||
private static final int[] COLUMN_TYPES = new int[] {Types.INTEGER, Types.VARCHAR};
|
||||
|
||||
private Connection connection;
|
||||
private DataSource dataSource;
|
||||
private PreparedStatement preparedStatement;
|
||||
private ResultSet resultSet;
|
||||
|
||||
private Connection connection = mock();
|
||||
|
||||
private DataSource dataSource = mock();
|
||||
|
||||
private PreparedStatement preparedStatement = mock();
|
||||
|
||||
private ResultSet resultSet = mock();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
this.connection = mock(Connection.class);
|
||||
this.dataSource = mock(DataSource.class);
|
||||
this.preparedStatement = mock(PreparedStatement.class);
|
||||
this.resultSet = mock(ResultSet.class);
|
||||
given(this.dataSource.getConnection()).willReturn(this.connection);
|
||||
given(this.connection.prepareStatement(anyString())).willReturn(this.preparedStatement);
|
||||
given(preparedStatement.executeQuery()).willReturn(resultSet);
|
||||
@@ -273,8 +273,8 @@ public class SqlQueryTests {
|
||||
@Test
|
||||
public void testFindCustomerMixed() throws SQLException {
|
||||
reset(connection);
|
||||
PreparedStatement preparedStatement2 = mock(PreparedStatement.class);
|
||||
ResultSet resultSet2 = mock(ResultSet.class);
|
||||
PreparedStatement preparedStatement2 = mock();
|
||||
ResultSet resultSet2 = mock();
|
||||
given(preparedStatement2.executeQuery()).willReturn(resultSet2);
|
||||
given(resultSet.next()).willReturn(true, false);
|
||||
given(resultSet.getInt("id")).willReturn(1);
|
||||
|
||||
@@ -70,24 +70,20 @@ public class SqlUpdateTests {
|
||||
private static final String INSERT_GENERATE_KEYS =
|
||||
"insert into show (name) values(?)";
|
||||
|
||||
private DataSource dataSource;
|
||||
|
||||
private Connection connection;
|
||||
private Connection connection = mock();
|
||||
|
||||
private PreparedStatement preparedStatement;
|
||||
private DataSource dataSource = mock();
|
||||
|
||||
private ResultSet resultSet;
|
||||
private PreparedStatement preparedStatement = mock();
|
||||
|
||||
private ResultSetMetaData resultSetMetaData;
|
||||
private ResultSet resultSet = mock();
|
||||
|
||||
private ResultSetMetaData resultSetMetaData = mock();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
dataSource = mock(DataSource.class);
|
||||
connection = mock(Connection.class);
|
||||
preparedStatement = mock(PreparedStatement.class);
|
||||
resultSet = mock(ResultSet.class);
|
||||
resultSetMetaData = mock(ResultSetMetaData.class);
|
||||
given(dataSource.getConnection()).willReturn(connection);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,17 +66,17 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class StoredProcedureTests {
|
||||
|
||||
private DataSource dataSource;
|
||||
private Connection connection;
|
||||
private CallableStatement callableStatement;
|
||||
private Connection connection = mock();
|
||||
|
||||
private DataSource dataSource = mock();
|
||||
|
||||
private CallableStatement callableStatement = mock();
|
||||
|
||||
private boolean verifyClosedAfter = true;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
dataSource = mock(DataSource.class);
|
||||
connection = mock(Connection.class);
|
||||
callableStatement = mock(CallableStatement.class);
|
||||
given(dataSource.getConnection()).willReturn(connection);
|
||||
given(callableStatement.getConnection()).willReturn(connection);
|
||||
}
|
||||
@@ -251,7 +251,7 @@ public class StoredProcedureTests {
|
||||
|
||||
@Test
|
||||
public void testStoredProcedureWithResultSet() throws Exception {
|
||||
ResultSet resultSet = mock(ResultSet.class);
|
||||
ResultSet resultSet = mock();
|
||||
given(resultSet.next()).willReturn(true, true, false);
|
||||
given(callableStatement.execute()).willReturn(true);
|
||||
given(callableStatement.getUpdateCount()).willReturn(-1);
|
||||
@@ -267,7 +267,7 @@ public class StoredProcedureTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testStoredProcedureWithResultSetMapped() throws Exception {
|
||||
ResultSet resultSet = mock(ResultSet.class);
|
||||
ResultSet resultSet = mock();
|
||||
given(resultSet.next()).willReturn(true, true, false);
|
||||
given(resultSet.getString(2)).willReturn("Foo", "Bar");
|
||||
given(callableStatement.execute()).willReturn(true);
|
||||
@@ -286,16 +286,16 @@ public class StoredProcedureTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testStoredProcedureWithUndeclaredResults() throws Exception {
|
||||
ResultSet resultSet1 = mock(ResultSet.class);
|
||||
ResultSet resultSet1 = mock();
|
||||
given(resultSet1.next()).willReturn(true, true, false);
|
||||
given(resultSet1.getString(2)).willReturn("Foo", "Bar");
|
||||
|
||||
ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
|
||||
ResultSetMetaData resultSetMetaData = mock();
|
||||
given(resultSetMetaData.getColumnCount()).willReturn(2);
|
||||
given(resultSetMetaData.getColumnLabel(1)).willReturn("spam");
|
||||
given(resultSetMetaData.getColumnLabel(2)).willReturn("eggs");
|
||||
|
||||
ResultSet resultSet2 = mock(ResultSet.class);
|
||||
ResultSet resultSet2 = mock();
|
||||
given(resultSet2.getMetaData()).willReturn(resultSetMetaData);
|
||||
given(resultSet2.next()).willReturn(true, false);
|
||||
given(resultSet2.getObject(1)).willReturn("Spam");
|
||||
@@ -345,7 +345,7 @@ public class StoredProcedureTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testStoredProcedureSkippingUndeclaredResults() throws Exception {
|
||||
ResultSet resultSet = mock(ResultSet.class);
|
||||
ResultSet resultSet = mock();
|
||||
given(resultSet.next()).willReturn(true, true, false);
|
||||
given(resultSet.getString(2)).willReturn("Foo", "Bar");
|
||||
given(callableStatement.execute()).willReturn(true);
|
||||
|
||||
@@ -41,9 +41,9 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
class DatabaseStartupValidatorTests {
|
||||
|
||||
private final DataSource dataSource = mock(DataSource.class);
|
||||
private final DataSource dataSource = mock();
|
||||
|
||||
private final Connection connection = mock(Connection.class);
|
||||
private final Connection connection = mock();
|
||||
|
||||
private final DatabaseStartupValidator validator = new DatabaseStartupValidator();
|
||||
|
||||
@@ -103,7 +103,7 @@ class DatabaseStartupValidatorTests {
|
||||
@SuppressWarnings("deprecation")
|
||||
void useValidationQueryInsteadOfIsValid() throws Exception {
|
||||
String validationQuery = "SELECT NOW() FROM DUAL";
|
||||
Statement statement = mock(Statement.class);
|
||||
Statement statement = mock();
|
||||
given(connection.createStatement()).willReturn(statement);
|
||||
given(statement.execute(validationQuery)).willReturn(true);
|
||||
|
||||
@@ -120,7 +120,7 @@ class DatabaseStartupValidatorTests {
|
||||
@SuppressWarnings("deprecation")
|
||||
void shouldExecuteValidationTwiceOnError() throws Exception {
|
||||
String validationQuery = "SELECT NOW() FROM DUAL";
|
||||
Statement statement = mock(Statement.class);
|
||||
Statement statement = mock();
|
||||
given(connection.createStatement()).willReturn(statement);
|
||||
given(statement.execute(validationQuery))
|
||||
.willThrow(new SQLException("Test"))
|
||||
|
||||
@@ -40,9 +40,9 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class DefaultLobHandlerTests {
|
||||
|
||||
private ResultSet rs = mock(ResultSet.class);
|
||||
private ResultSet rs = mock();
|
||||
|
||||
private PreparedStatement ps = mock(PreparedStatement.class);
|
||||
private PreparedStatement ps = mock();
|
||||
|
||||
private LobHandler lobHandler = new DefaultLobHandler();
|
||||
|
||||
|
||||
@@ -75,19 +75,16 @@ import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING;
|
||||
*/
|
||||
public class JdbcTransactionManagerTests {
|
||||
|
||||
private DataSource ds;
|
||||
private DataSource ds = mock();
|
||||
|
||||
private Connection con;
|
||||
private Connection con = mock();
|
||||
|
||||
private JdbcTransactionManager tm;
|
||||
private JdbcTransactionManager tm = new JdbcTransactionManager(ds);
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
ds = mock(DataSource.class);
|
||||
con = mock(Connection.class);
|
||||
given(ds.getConnection()).willReturn(con);
|
||||
tm = new JdbcTransactionManager(ds);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@@ -491,8 +488,8 @@ public class JdbcTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testParticipatingTransactionWithDifferentConnectionObtainedFromSynch() throws Exception {
|
||||
DataSource ds2 = mock(DataSource.class);
|
||||
final Connection con2 = mock(Connection.class);
|
||||
DataSource ds2 = mock();
|
||||
final Connection con2 = mock();
|
||||
given(ds2.getConnection()).willReturn(con2);
|
||||
|
||||
assertThat(!TransactionSynchronizationManager.hasResource(ds)).as("Hasn't thread connection").isTrue();
|
||||
@@ -615,8 +612,8 @@ public class JdbcTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testPropagationRequiresNewWithExistingTransactionAndUnrelatedDataSource() throws Exception {
|
||||
Connection con2 = mock(Connection.class);
|
||||
final DataSource ds2 = mock(DataSource.class);
|
||||
Connection con2 = mock();
|
||||
final DataSource ds2 = mock();
|
||||
given(ds2.getConnection()).willReturn(con2);
|
||||
|
||||
final TransactionTemplate tt = new TransactionTemplate(tm);
|
||||
@@ -664,7 +661,7 @@ public class JdbcTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testPropagationRequiresNewWithExistingTransactionAndUnrelatedFailingDataSource() throws Exception {
|
||||
final DataSource ds2 = mock(DataSource.class);
|
||||
final DataSource ds2 = mock();
|
||||
SQLException failure = new SQLException();
|
||||
given(ds2.getConnection()).willThrow(failure);
|
||||
|
||||
@@ -800,8 +797,8 @@ public class JdbcTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testPropagationSupportsAndRequiresNewWithEarlyAccess() throws Exception {
|
||||
final Connection con1 = mock(Connection.class);
|
||||
final Connection con2 = mock(Connection.class);
|
||||
final Connection con1 = mock();
|
||||
final Connection con2 = mock();
|
||||
given(ds.getConnection()).willReturn(con1, con2);
|
||||
|
||||
final
|
||||
@@ -874,7 +871,7 @@ public class JdbcTransactionManagerTests {
|
||||
tm.setEnforceReadOnly(true);
|
||||
|
||||
given(con.getAutoCommit()).willReturn(true);
|
||||
Statement stmt = mock(Statement.class);
|
||||
Statement stmt = mock();
|
||||
given(con.createStatement()).willReturn(stmt);
|
||||
|
||||
TransactionTemplate tt = new TransactionTemplate(tm);
|
||||
@@ -906,7 +903,7 @@ public class JdbcTransactionManagerTests {
|
||||
@ValueSource(ints = {1, 10})
|
||||
@EnabledForTestGroups(LONG_RUNNING)
|
||||
public void transactionWithTimeout(int timeout) throws Exception {
|
||||
PreparedStatement ps = mock(PreparedStatement.class);
|
||||
PreparedStatement ps = mock();
|
||||
given(con.getAutoCommit()).willReturn(true);
|
||||
given(con.prepareStatement("some SQL statement")).willReturn(ps);
|
||||
|
||||
@@ -1334,8 +1331,8 @@ public class JdbcTransactionManagerTests {
|
||||
}
|
||||
|
||||
private void doTestExistingTransactionWithPropagationNested(final int count) throws Exception {
|
||||
DatabaseMetaData md = mock(DatabaseMetaData.class);
|
||||
Savepoint sp = mock(Savepoint.class);
|
||||
DatabaseMetaData md = mock();
|
||||
Savepoint sp = mock();
|
||||
|
||||
given(md.supportsSavepoints()).willReturn(true);
|
||||
given(con.getMetaData()).willReturn(md);
|
||||
@@ -1377,8 +1374,8 @@ public class JdbcTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testExistingTransactionWithPropagationNestedAndRollback() throws Exception {
|
||||
DatabaseMetaData md = mock(DatabaseMetaData.class);
|
||||
Savepoint sp = mock(Savepoint.class);
|
||||
DatabaseMetaData md = mock();
|
||||
Savepoint sp = mock();
|
||||
|
||||
given(md.supportsSavepoints()).willReturn(true);
|
||||
given(con.getMetaData()).willReturn(md);
|
||||
@@ -1418,8 +1415,8 @@ public class JdbcTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testExistingTransactionWithPropagationNestedAndRequiredRollback() throws Exception {
|
||||
DatabaseMetaData md = mock(DatabaseMetaData.class);
|
||||
Savepoint sp = mock(Savepoint.class);
|
||||
DatabaseMetaData md = mock();
|
||||
Savepoint sp = mock();
|
||||
|
||||
given(md.supportsSavepoints()).willReturn(true);
|
||||
given(con.getMetaData()).willReturn(md);
|
||||
@@ -1470,8 +1467,8 @@ public class JdbcTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testExistingTransactionWithPropagationNestedAndRequiredRollbackOnly() throws Exception {
|
||||
DatabaseMetaData md = mock(DatabaseMetaData.class);
|
||||
Savepoint sp = mock(Savepoint.class);
|
||||
DatabaseMetaData md = mock();
|
||||
Savepoint sp = mock();
|
||||
|
||||
given(md.supportsSavepoints()).willReturn(true);
|
||||
given(con.getMetaData()).willReturn(md);
|
||||
@@ -1522,8 +1519,8 @@ public class JdbcTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testExistingTransactionWithManualSavepoint() throws Exception {
|
||||
DatabaseMetaData md = mock(DatabaseMetaData.class);
|
||||
Savepoint sp = mock(Savepoint.class);
|
||||
DatabaseMetaData md = mock();
|
||||
Savepoint sp = mock();
|
||||
|
||||
given(md.supportsSavepoints()).willReturn(true);
|
||||
given(con.getMetaData()).willReturn(md);
|
||||
@@ -1553,8 +1550,8 @@ public class JdbcTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testExistingTransactionWithManualSavepointAndRollback() throws Exception {
|
||||
DatabaseMetaData md = mock(DatabaseMetaData.class);
|
||||
Savepoint sp = mock(Savepoint.class);
|
||||
DatabaseMetaData md = mock();
|
||||
Savepoint sp = mock();
|
||||
|
||||
given(md.supportsSavepoints()).willReturn(true);
|
||||
given(con.getMetaData()).willReturn(md);
|
||||
|
||||
@@ -189,16 +189,16 @@ public class SQLErrorCodeSQLExceptionTranslatorTests {
|
||||
SQLException connectionException = new SQLException();
|
||||
SQLException duplicateKeyException = new SQLException("test", "", 1);
|
||||
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
DataSource dataSource = mock();
|
||||
given(dataSource.getConnection()).willThrow(connectionException);
|
||||
|
||||
SQLErrorCodeSQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(dataSource);
|
||||
assertThat(sext.translate("test", null, duplicateKeyException)).isNull();
|
||||
|
||||
DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
|
||||
DatabaseMetaData databaseMetaData = mock();
|
||||
given(databaseMetaData.getDatabaseProductName()).willReturn("Oracle");
|
||||
|
||||
Connection connection = mock(Connection.class);
|
||||
Connection connection = mock();
|
||||
given(connection.getMetaData()).willReturn(databaseMetaData);
|
||||
|
||||
Mockito.reset(dataSource);
|
||||
|
||||
@@ -235,8 +235,8 @@ public class SQLErrorCodesFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testDataSourceWithNullMetadata() throws Exception {
|
||||
Connection connection = mock(Connection.class);
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
Connection connection = mock();
|
||||
DataSource dataSource = mock();
|
||||
given(dataSource.getConnection()).willReturn(connection);
|
||||
|
||||
SQLErrorCodes sec = SQLErrorCodesFactory.getInstance().getErrorCodes(dataSource);
|
||||
@@ -253,7 +253,7 @@ public class SQLErrorCodesFactoryTests {
|
||||
public void testGetFromDataSourceWithSQLException() throws Exception {
|
||||
SQLException expectedSQLException = new SQLException();
|
||||
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
DataSource dataSource = mock();
|
||||
given(dataSource.getConnection()).willThrow(expectedSQLException);
|
||||
|
||||
SQLErrorCodes sec = SQLErrorCodesFactory.getInstance().getErrorCodes(dataSource);
|
||||
@@ -264,13 +264,13 @@ public class SQLErrorCodesFactoryTests {
|
||||
}
|
||||
|
||||
private SQLErrorCodes getErrorCodesFromDataSource(String productName, SQLErrorCodesFactory factory) throws Exception {
|
||||
DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
|
||||
DatabaseMetaData databaseMetaData = mock();
|
||||
given(databaseMetaData.getDatabaseProductName()).willReturn(productName);
|
||||
|
||||
Connection connection = mock(Connection.class);
|
||||
Connection connection = mock();
|
||||
given(connection.getMetaData()).willReturn(databaseMetaData);
|
||||
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
DataSource dataSource = mock();
|
||||
given(dataSource.getConnection()).willReturn(connection);
|
||||
|
||||
SQLErrorCodesFactory secf = (factory != null ? factory : SQLErrorCodesFactory.getInstance());
|
||||
|
||||
@@ -41,13 +41,13 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
class DataFieldMaxValueIncrementerTests {
|
||||
|
||||
private final DataSource dataSource = mock(DataSource.class);
|
||||
private final DataSource dataSource = mock();
|
||||
|
||||
private final Connection connection = mock(Connection.class);
|
||||
private final Connection connection = mock();
|
||||
|
||||
private final Statement statement = mock(Statement.class);
|
||||
private final Statement statement = mock();
|
||||
|
||||
private final ResultSet resultSet = mock(ResultSet.class);
|
||||
private final ResultSet resultSet = mock();
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.sql.SQLException;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.jdbc.InvalidResultSetAccessException;
|
||||
@@ -40,16 +39,9 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class ResultSetWrappingRowSetTests {
|
||||
|
||||
private ResultSet resultSet;
|
||||
private ResultSet resultSet = mock();
|
||||
|
||||
private ResultSetWrappingSqlRowSet rowSet;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
resultSet = mock(ResultSet.class);
|
||||
rowSet = new ResultSetWrappingSqlRowSet(resultSet);
|
||||
}
|
||||
private ResultSetWrappingSqlRowSet rowSet = new ResultSetWrappingSqlRowSet(resultSet);
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user