You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by th...@apache.org on 2022/12/06 02:51:12 UTC
[commons-dbutils] 03/03: DBUTILS-148 Remove unused mockings
This is an automated email from the ASF dual-hosted git repository.
thecarlhall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbutils.git
commit 66c836ec73b036bc343d5267cf9f062c7175d21c
Author: Carl Hall <th...@apache.org>
AuthorDate: Mon Dec 5 21:49:10 2022 -0500
DBUTILS-148 Remove unused mockings
---
.../commons/dbutils/AsyncQueryRunnerTest.java | 23 -------------
.../apache/commons/dbutils/QueryRunnerTest.java | 40 ----------------------
2 files changed, 63 deletions(-)
diff --git a/src/test/java/org/apache/commons/dbutils/AsyncQueryRunnerTest.java b/src/test/java/org/apache/commons/dbutils/AsyncQueryRunnerTest.java
index 782c72e..3272ceb 100644
--- a/src/test/java/org/apache/commons/dbutils/AsyncQueryRunnerTest.java
+++ b/src/test/java/org/apache/commons/dbutils/AsyncQueryRunnerTest.java
@@ -64,11 +64,9 @@ public class AsyncQueryRunnerTest {
when(conn.prepareStatement(any(String.class))).thenReturn(prepStmt);
when(prepStmt.getParameterMetaData()).thenReturn(meta);
- when(prepStmt.getResultSet()).thenReturn(results);
when(prepStmt.executeQuery()).thenReturn(results);
when(conn.createStatement()).thenReturn(stmt);
- when(stmt.getResultSet()).thenReturn(results);
when(stmt.executeQuery(any(String.class))).thenReturn(results);
when(results.next()).thenReturn(false);
@@ -178,7 +176,6 @@ public class AsyncQueryRunnerTest {
public void testNullConnectionBatch() throws Exception {
final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
- when(meta.getParameterCount()).thenReturn(2);
when(dataSource.getConnection()).thenReturn(null);
runner.batch("select * from blah where ? = ?", params).get();
@@ -188,15 +185,11 @@ public class AsyncQueryRunnerTest {
public void testNullSqlBatch() throws Exception {
final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
- when(meta.getParameterCount()).thenReturn(2);
-
runner.batch(null, params).get();
}
@Test(expected=ExecutionException.class)
public void testNullParamsArgBatch() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
-
runner.batch("select * from blah where ? = ?", null).get();
}
@@ -204,8 +197,6 @@ public class AsyncQueryRunnerTest {
public void testAddBatchException() throws Exception {
final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
- doThrow(new SQLException()).when(prepStmt).addBatch();
-
callBatchWithException("select * from blah where ? = ?", params);
}
@@ -213,8 +204,6 @@ public class AsyncQueryRunnerTest {
public void testExecuteBatchException() throws Exception {
final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
- doThrow(new SQLException()).when(prepStmt).executeBatch();
-
callBatchWithException("select * from blah where ? = ?", params);
}
@@ -233,7 +222,6 @@ public class AsyncQueryRunnerTest {
verify(conn, times(0)).close(); // make sure we closed the connection
// call the other variation of query
- when(meta.getParameterCount()).thenReturn(0);
sql = "select * from blah";
runner.query(conn, sql, handler).get();
@@ -254,7 +242,6 @@ public class AsyncQueryRunnerTest {
verify(conn, times(1)).close(); // make sure we closed the connection
// call the other variation of query
- when(meta.getParameterCount()).thenReturn(0);
sql = "select * from blah";
runner.query(sql, handler).get();
@@ -321,7 +308,6 @@ public class AsyncQueryRunnerTest {
@Test(expected=ExecutionException.class)
public void testNullConnectionQuery() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
when(dataSource.getConnection()).thenReturn(null);
runner.query("select * from blah where ? = ?", handler, "unit", "test").get();
@@ -329,22 +315,16 @@ public class AsyncQueryRunnerTest {
@Test(expected=ExecutionException.class)
public void testNullSqlQuery() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
-
runner.query(null, handler).get();
}
@Test(expected=ExecutionException.class)
public void testNullHandlerQuery() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
-
runner.query("select * from blah where ? = ?", null).get();
}
@Test
public void testExecuteQueryException() throws Exception {
- doThrow(new SQLException()).when(prepStmt).executeQuery();
-
callQueryWithException(handler, "unit", "test");
}
@@ -483,7 +463,6 @@ public class AsyncQueryRunnerTest {
@Test(expected=ExecutionException.class)
public void testNullConnectionUpdate() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
when(dataSource.getConnection()).thenReturn(null);
runner.update("select * from blah where ? = ?", "unit", "test").get();
@@ -491,8 +470,6 @@ public class AsyncQueryRunnerTest {
@Test(expected=ExecutionException.class)
public void testNullSqlUpdate() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
-
runner.update(null).get();
}
diff --git a/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java b/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
index 7105559..e1746c9 100644
--- a/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
+++ b/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
@@ -73,11 +73,9 @@ public class QueryRunnerTest {
when(conn.prepareStatement(any(String.class))).thenReturn(prepStmt);
when(prepStmt.getParameterMetaData()).thenReturn(meta);
- when(prepStmt.getResultSet()).thenReturn(results);
when(prepStmt.executeQuery()).thenReturn(results);
when(conn.createStatement()).thenReturn(stmt);
- when(stmt.getResultSet()).thenReturn(results);
when(stmt.executeQuery(any(String.class))).thenReturn(results);
when(conn.prepareCall(any(String.class))).thenReturn(call);
@@ -185,7 +183,6 @@ public class QueryRunnerTest {
public void testNullConnectionBatch() throws Exception {
final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
- when(meta.getParameterCount()).thenReturn(2);
when(dataSource.getConnection()).thenReturn(null);
runner.batch("select * from blah where ? = ?", params);
@@ -195,15 +192,11 @@ public class QueryRunnerTest {
public void testNullSqlBatch() throws Exception {
final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
- when(meta.getParameterCount()).thenReturn(2);
-
runner.batch(null, params);
}
@Test(expected=SQLException.class)
public void testNullParamsArgBatch() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
-
runner.batch("select * from blah where ? = ?", null);
}
@@ -211,8 +204,6 @@ public class QueryRunnerTest {
public void testAddBatchException() throws Exception {
final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
- doThrow(new SQLException()).when(prepStmt).addBatch();
-
callBatchWithException("select * from blah where ? = ?", params);
}
@@ -220,8 +211,6 @@ public class QueryRunnerTest {
public void testExecuteBatchException() throws Exception {
final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
- doThrow(new SQLException()).when(prepStmt).executeBatch();
-
callBatchWithException("select * from blah where ? = ?", params);
}
@@ -240,7 +229,6 @@ public class QueryRunnerTest {
verify(conn, times(0)).close(); // make sure we do not close the connection, since QueryRunner.query(Connection, String, ResultSetHandler<T>, Object...) does not close connections
// call the other variation of query
- when(meta.getParameterCount()).thenReturn(0);
sql = "select * from blah";
runner.query(conn, sql, handler);
@@ -261,7 +249,6 @@ public class QueryRunnerTest {
verify(conn, times(1)).close(); // make sure we closed the connection
// call the other variation of query
- when(meta.getParameterCount()).thenReturn(0);
sql = "select * from blah";
runner.query(sql, handler);
@@ -329,7 +316,6 @@ public class QueryRunnerTest {
@Test(expected=SQLException.class)
public void testNullConnectionQuery() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
when(dataSource.getConnection()).thenReturn(null);
runner.query("select * from blah where ? = ?", handler, "unit", "test");
@@ -337,22 +323,16 @@ public class QueryRunnerTest {
@Test(expected=SQLException.class)
public void testNullSqlQuery() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
-
runner.query(null, handler);
}
@Test(expected=SQLException.class)
public void testNullHandlerQuery() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
-
runner.query("select * from blah where ? = ?", null);
}
@Test
public void testExecuteQueryException() throws Exception {
- doThrow(new SQLException()).when(prepStmt).executeQuery();
-
callQueryWithException(handler, "unit", "test");
}
@@ -459,8 +439,6 @@ public class QueryRunnerTest {
when(conn.prepareStatement(any(String.class), eq(Statement.RETURN_GENERATED_KEYS))).thenReturn(prepStmt);
when(prepStmt.getGeneratedKeys()).thenReturn(results);
when(results.next()).thenReturn(true).thenReturn(true).thenReturn(false);
- when(results.getMetaData()).thenReturn(resultsMeta);
- when(resultsMeta.getColumnCount()).thenReturn(1);
final ResultSetHandler<List<Object>> handler = new ResultSetHandler<List<Object>>()
{
@@ -530,7 +508,6 @@ public class QueryRunnerTest {
@Test(expected=SQLException.class)
public void testNullConnectionUpdate() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
when(dataSource.getConnection()).thenReturn(null);
runner.update("select * from blah where ? = ?", "unit", "test");
@@ -538,8 +515,6 @@ public class QueryRunnerTest {
@Test(expected=SQLException.class)
public void testNullSqlUpdate() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
-
runner.update(null);
}
@@ -724,7 +699,6 @@ public class QueryRunnerTest {
boolean caught = false;
try {
- when(call.execute()).thenReturn(false);
when(meta.getParameterCount()).thenReturn(2);
runner.query("{call my_proc(?, ?)}", handler, params);
@@ -754,7 +728,6 @@ public class QueryRunnerTest {
@Test(expected=SQLException.class)
public void testNullConnectionExecute() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
when(dataSource.getConnection()).thenReturn(null);
runner.execute("{call my_proc(?, ?)}", "unit", "test");
@@ -762,8 +735,6 @@ public class QueryRunnerTest {
@Test(expected=SQLException.class)
public void testNullSqlExecute() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
-
runner.execute(null);
}
@@ -776,8 +747,6 @@ public class QueryRunnerTest {
@Test
public void testExecuteException() throws Exception {
- doThrow(new SQLException()).when(prepStmt).execute();
-
callExecuteWithException(handler, "unit", "test");
}
@@ -960,7 +929,6 @@ public class QueryRunnerTest {
boolean caught = false;
try {
- when(call.execute()).thenReturn(true);
when(meta.getParameterCount()).thenReturn(2);
runner.execute("{call my_proc(?, ?)}", handler, params);
@@ -990,7 +958,6 @@ public class QueryRunnerTest {
@Test(expected=SQLException.class)
public void testNullConnectionExecuteWithResultSet() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
when(dataSource.getConnection()).thenReturn(null);
runner.execute("{call my_proc(?, ?)}", handler, "unit", "test");
@@ -998,22 +965,16 @@ public class QueryRunnerTest {
@Test(expected=SQLException.class)
public void testNullSqlExecuteWithResultSet() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
-
runner.execute(null, handler);
}
@Test(expected=SQLException.class)
public void testNullHandlerExecuteWithResultSet() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
-
runner.execute("{call my_proc(?, ?)}", (ResultSetHandler)null);
}
@Test
public void testExecuteWithResultSetException() throws Exception {
- doThrow(new SQLException()).when(prepStmt).execute();
-
callExecuteWithResultSetWithException(handler, "unit", "test");
}
@@ -1043,7 +1004,6 @@ public class QueryRunnerTest {
@Test(expected=NullPointerException.class)
public void testFillStatementWithBeanNullNames() throws Exception {
final MyBean bean = new MyBean();
- when(meta.getParameterCount()).thenReturn(3);
runner.fillStatementWithBean(prepStmt, bean, "a", "b", null);
}