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:09 UTC

[commons-dbutils] branch master updated (f0cbf2f -> 66c836e)

This is an automated email from the ASF dual-hosted git repository.

thecarlhall pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbutils.git


    from f0cbf2f  Correct Checkstyle version
     new 9870e52  Format code with comments, update tests
     new 339976e  DBUTILS-148 Replace deprecated Mockito.initMocks with @RunWith(MockitoJUnitRunner.class)
     new 66c836e  DBUTILS-148 Remove unused mockings

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../commons/dbutils/GenerousBeanProcessor.java     |  4 +-
 .../commons/dbutils/AsyncQueryRunnerTest.java      | 28 ++------------
 .../commons/dbutils/GenerousBeanProcessorTest.java | 31 ++++++++++-----
 .../apache/commons/dbutils/OutParameterTest.java   |  6 +--
 .../apache/commons/dbutils/QueryRunnerTest.java    | 45 ++--------------------
 .../dbutils/handlers/BeanMapHandlerTest.java       |  5 ++-
 6 files changed, 37 insertions(+), 82 deletions(-)


[commons-dbutils] 01/03: Format code with comments, update tests

Posted by th...@apache.org.
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 9870e520ddd76f93c743b1a6b63ea65592b2b504
Author: Carl Hall <th...@apache.org>
AuthorDate: Sun Dec 4 10:30:17 2022 -0500

    Format code with comments, update tests
    
    Added comments to string replacements to give context of each.
    Updated unit tests to cover removing spaces in column names.
---
 .../commons/dbutils/GenerousBeanProcessor.java     |  4 +++-
 .../commons/dbutils/GenerousBeanProcessorTest.java | 25 ++++++++++++++++------
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbutils/GenerousBeanProcessor.java b/src/main/java/org/apache/commons/dbutils/GenerousBeanProcessor.java
index 404b84c..c9e3615 100644
--- a/src/main/java/org/apache/commons/dbutils/GenerousBeanProcessor.java
+++ b/src/main/java/org/apache/commons/dbutils/GenerousBeanProcessor.java
@@ -52,7 +52,9 @@ public class GenerousBeanProcessor extends BeanProcessor {
                 columnName = rsmd.getColumnName(col);
             }
 
-            final String generousColumnName = columnName.replace("_", "").replace(" ", "");
+            final String generousColumnName = columnName
+                    .replace("_", "")   // more idiomatic to Java
+                    .replace(" ", "");  // can't have spaces in property names
 
             for (int i = 0; i < props.length; i++) {
                 final String propName = props[i].getName();
diff --git a/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java b/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java
index 95cf5a4..bb68468 100644
--- a/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java
+++ b/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java
@@ -28,7 +28,6 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.mockito.Mockito.when;
 
-
 public class GenerousBeanProcessorTest {
 
     GenerousBeanProcessor processor = new GenerousBeanProcessor();
@@ -103,15 +102,31 @@ public class GenerousBeanProcessorTest {
         assertEquals(1, ret[3]);
     }
 
+    @SuppressWarnings("boxing") // test code
+    @Test
+    public void testMapColumnsToPropertiesWithSpaces() throws Exception {
+        when(metaData.getColumnCount()).thenReturn(3);
+
+        when(metaData.getColumnLabel(1)).thenReturn("th ree");
+        when(metaData.getColumnLabel(2)).thenReturn("o n e");
+        when(metaData.getColumnLabel(3)).thenReturn("t wo");
+
+        final int[] ret = processor.mapColumnsToProperties(metaData, propDescriptors);
+
+        assertNotNull(ret);
+        assertEquals(4, ret.length);
+        assertEquals(-1, ret[0]);
+        assertEquals(2, ret[1]);
+        assertEquals(0, ret[2]);
+        assertEquals(1, ret[3]);
+    }
+
     @SuppressWarnings("boxing") // test code
     @Test
     public void testMapColumnsToPropertiesColumnLabelIsNull() throws Exception {
         when(metaData.getColumnCount()).thenReturn(1);
         when(metaData.getColumnName(1)).thenReturn("juhu");
-
         when(metaData.getColumnLabel(1)).thenReturn(null);
-        when(metaData.getColumnLabel(2)).thenReturn("One");
-        when(metaData.getColumnLabel(3)).thenReturn("tWO");
 
         final int[] ret = processor.mapColumnsToProperties(metaData, propDescriptors);
 
@@ -119,8 +134,6 @@ public class GenerousBeanProcessorTest {
         assertEquals(2, ret.length);
         assertEquals(-1, ret[0]);
         assertEquals(-1, ret[1]);
-        assertEquals(-1, ret[1]);
-        assertEquals(-1, ret[1]);
     }
 
     static class TestBean {


[commons-dbutils] 03/03: DBUTILS-148 Remove unused mockings

Posted by th...@apache.org.
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);
     }
 


[commons-dbutils] 02/03: DBUTILS-148 Replace deprecated Mockito.initMocks with @RunWith(MockitoJUnitRunner.class)

Posted by th...@apache.org.
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 339976ed05ca4b77c6e87042e288e0ae963ba58a
Author: Carl Hall <th...@apache.org>
AuthorDate: Mon Dec 5 21:14:51 2022 -0500

    DBUTILS-148 Replace deprecated Mockito.initMocks with @RunWith(MockitoJUnitRunner.class)
---
 src/test/java/org/apache/commons/dbutils/AsyncQueryRunnerTest.java  | 5 +++--
 .../java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java  | 6 +++---
 src/test/java/org/apache/commons/dbutils/OutParameterTest.java      | 6 +++---
 src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java       | 5 +++--
 .../org/apache/commons/dbutils/handlers/BeanMapHandlerTest.java     | 5 +++--
 5 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/src/test/java/org/apache/commons/dbutils/AsyncQueryRunnerTest.java b/src/test/java/org/apache/commons/dbutils/AsyncQueryRunnerTest.java
index 456e24f..782c72e 100644
--- a/src/test/java/org/apache/commons/dbutils/AsyncQueryRunnerTest.java
+++ b/src/test/java/org/apache/commons/dbutils/AsyncQueryRunnerTest.java
@@ -40,10 +40,13 @@ import javax.sql.DataSource;
 import org.apache.commons.dbutils.handlers.ArrayHandler;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 
 @SuppressWarnings("boxing") // test code
+@RunWith(MockitoJUnitRunner.class)
 public class AsyncQueryRunnerTest {
     AsyncQueryRunner runner;
     ArrayHandler handler;
@@ -57,8 +60,6 @@ public class AsyncQueryRunnerTest {
 
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
-
         when(dataSource.getConnection()).thenReturn(conn);
 
         when(conn.prepareStatement(any(String.class))).thenReturn(prepStmt);
diff --git a/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java b/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java
index bb68468..eb4e9a1 100644
--- a/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java
+++ b/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java
@@ -18,8 +18,9 @@ package org.apache.commons.dbutils;
 
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 
 import java.beans.PropertyDescriptor;
 import java.sql.ResultSetMetaData;
@@ -28,6 +29,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.mockito.Mockito.when;
 
+@RunWith(MockitoJUnitRunner.class)
 public class GenerousBeanProcessorTest {
 
     GenerousBeanProcessor processor = new GenerousBeanProcessor();
@@ -36,8 +38,6 @@ public class GenerousBeanProcessorTest {
 
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
-
         propDescriptors = new PropertyDescriptor[3];
 
         propDescriptors[0] = new PropertyDescriptor("one", TestBean.class);
diff --git a/src/test/java/org/apache/commons/dbutils/OutParameterTest.java b/src/test/java/org/apache/commons/dbutils/OutParameterTest.java
index ce173d8..6282285 100644
--- a/src/test/java/org/apache/commons/dbutils/OutParameterTest.java
+++ b/src/test/java/org/apache/commons/dbutils/OutParameterTest.java
@@ -28,9 +28,11 @@ import java.sql.CallableStatement;
 import java.sql.Types;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 
+@RunWith(MockitoJUnitRunner.class)
 public class OutParameterTest {
     private static final int INDEX = 2;
     private static final int VALUE = 42;
@@ -41,8 +43,6 @@ public class OutParameterTest {
 
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);    // init the mocks
-
         parameter = new OutParameter<>(Types.INTEGER, Number.class);
     }
 
diff --git a/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java b/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
index eb01b23..7105559 100644
--- a/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
+++ b/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
@@ -45,12 +45,15 @@ import org.apache.commons.dbutils.handlers.ScalarHandler;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.mockito.invocation.InvocationOnMock;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.mockito.stubbing.Answer;
 
 @SuppressWarnings("boxing") // test code
+@RunWith(MockitoJUnitRunner.class)
 public class QueryRunnerTest {
     QueryRunner runner;
     ArrayHandler handler;
@@ -66,8 +69,6 @@ public class QueryRunnerTest {
 
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);    // init the mocks
-
         when(dataSource.getConnection()).thenReturn(conn);
 
         when(conn.prepareStatement(any(String.class))).thenReturn(prepStmt);
diff --git a/src/test/java/org/apache/commons/dbutils/handlers/BeanMapHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/BeanMapHandlerTest.java
index 60d505a..3a2662a 100644
--- a/src/test/java/org/apache/commons/dbutils/handlers/BeanMapHandlerTest.java
+++ b/src/test/java/org/apache/commons/dbutils/handlers/BeanMapHandlerTest.java
@@ -27,9 +27,12 @@ import org.apache.commons.dbutils.RowProcessor;
 import org.apache.commons.dbutils.TestBean;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 
+@RunWith(MockitoJUnitRunner.class)
 public class BeanMapHandlerTest {
 
     private BeanMapHandler<Long, TestBean> bmh;
@@ -40,8 +43,6 @@ public class BeanMapHandlerTest {
 
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
-
         when(Boolean.valueOf(rs.next())).thenReturn(Boolean.TRUE, Boolean.FALSE);
         when(rs.getObject(1)).thenReturn(Long.valueOf(23L));
         when(rs.getObject(2)).thenReturn(Long.valueOf(23L));