You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2018/05/06 16:20:21 UTC
[2/4] commons-dbutils git commit: Add final modifier to method
parameters.
http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41e682d6/src/main/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java b/src/main/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java
index ff54f68..4ef433e 100644
--- a/src/main/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java
+++ b/src/main/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java
@@ -109,7 +109,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
* @param rs The <code>ResultSet</code> to wrap.
* @return wrapped ResultSet
*/
- public static ResultSet wrap(ResultSet rs) {
+ public static ResultSet wrap(final ResultSet rs) {
return factory.createResultSet(new SqlNullCheckedResultSet(rs));
}
@@ -146,7 +146,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
* to wrap the specified <code>ResultSet</code>.
* @param rs ResultSet to wrap
*/
- public SqlNullCheckedResultSet(ResultSet rs) {
+ public SqlNullCheckedResultSet(final ResultSet rs) {
super();
this.rs = rs;
}
@@ -379,7 +379,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
* @throws Throwable error
*/
@Override
- public Object invoke(Object proxy, Method method, Object[] args)
+ public Object invoke(final Object proxy, final Method method, final Object[] args)
throws Throwable {
Object result = method.invoke(this.rs, args);
@@ -399,7 +399,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullAsciiStream the value
*/
- public void setNullAsciiStream(InputStream nullAsciiStream) {
+ public void setNullAsciiStream(final InputStream nullAsciiStream) {
this.nullAsciiStream = nullAsciiStream;
}
@@ -409,7 +409,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullBigDecimal the value
*/
- public void setNullBigDecimal(BigDecimal nullBigDecimal) {
+ public void setNullBigDecimal(final BigDecimal nullBigDecimal) {
this.nullBigDecimal = nullBigDecimal;
}
@@ -419,7 +419,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullBinaryStream the value
*/
- public void setNullBinaryStream(InputStream nullBinaryStream) {
+ public void setNullBinaryStream(final InputStream nullBinaryStream) {
this.nullBinaryStream = nullBinaryStream;
}
@@ -429,7 +429,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullBlob the value
*/
- public void setNullBlob(Blob nullBlob) {
+ public void setNullBlob(final Blob nullBlob) {
this.nullBlob = nullBlob;
}
@@ -439,7 +439,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullBoolean the value
*/
- public void setNullBoolean(boolean nullBoolean) {
+ public void setNullBoolean(final boolean nullBoolean) {
this.nullBoolean = nullBoolean;
}
@@ -449,7 +449,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullByte the value
*/
- public void setNullByte(byte nullByte) {
+ public void setNullByte(final byte nullByte) {
this.nullByte = nullByte;
}
@@ -459,7 +459,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullBytes the value
*/
- public void setNullBytes(byte[] nullBytes) {
+ public void setNullBytes(final byte[] nullBytes) {
byte[] copy = new byte[nullBytes.length];
System.arraycopy(nullBytes, 0, copy, 0, nullBytes.length);
this.nullBytes = copy;
@@ -471,7 +471,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullCharacterStream the value
*/
- public void setNullCharacterStream(Reader nullCharacterStream) {
+ public void setNullCharacterStream(final Reader nullCharacterStream) {
this.nullCharacterStream = nullCharacterStream;
}
@@ -481,7 +481,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullClob the value
*/
- public void setNullClob(Clob nullClob) {
+ public void setNullClob(final Clob nullClob) {
this.nullClob = nullClob;
}
@@ -491,7 +491,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullDate the value
*/
- public void setNullDate(Date nullDate) {
+ public void setNullDate(final Date nullDate) {
this.nullDate = nullDate != null ? new Date(nullDate.getTime()) : null;
}
@@ -501,7 +501,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullDouble the value
*/
- public void setNullDouble(double nullDouble) {
+ public void setNullDouble(final double nullDouble) {
this.nullDouble = nullDouble;
}
@@ -511,7 +511,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullFloat the value
*/
- public void setNullFloat(float nullFloat) {
+ public void setNullFloat(final float nullFloat) {
this.nullFloat = nullFloat;
}
@@ -521,7 +521,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullInt the value
*/
- public void setNullInt(int nullInt) {
+ public void setNullInt(final int nullInt) {
this.nullInt = nullInt;
}
@@ -531,7 +531,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullLong the value
*/
- public void setNullLong(long nullLong) {
+ public void setNullLong(final long nullLong) {
this.nullLong = nullLong;
}
@@ -541,7 +541,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullObject the value
*/
- public void setNullObject(Object nullObject) {
+ public void setNullObject(final Object nullObject) {
this.nullObject = nullObject;
}
@@ -551,7 +551,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullRef the value
*/
- public void setNullRef(Ref nullRef) {
+ public void setNullRef(final Ref nullRef) {
this.nullRef = nullRef;
}
@@ -561,7 +561,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullShort the value
*/
- public void setNullShort(short nullShort) {
+ public void setNullShort(final short nullShort) {
this.nullShort = nullShort;
}
@@ -571,7 +571,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullString the value
*/
- public void setNullString(String nullString) {
+ public void setNullString(final String nullString) {
this.nullString = nullString;
}
@@ -581,7 +581,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullTime the value
*/
- public void setNullTime(Time nullTime) {
+ public void setNullTime(final Time nullTime) {
this.nullTime = nullTime;
}
@@ -591,7 +591,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullTimestamp the value
*/
- public void setNullTimestamp(Timestamp nullTimestamp) {
+ public void setNullTimestamp(final Timestamp nullTimestamp) {
this.nullTimestamp = nullTimestamp != null ? new Timestamp(nullTimestamp.getTime()) : null;
}
@@ -601,7 +601,7 @@ public class SqlNullCheckedResultSet implements InvocationHandler {
*
* @param nullURL the value
*/
- public void setNullURL(URL nullURL) {
+ public void setNullURL(final URL nullURL) {
this.nullURL = nullURL;
}
http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41e682d6/src/main/java/org/apache/commons/dbutils/wrappers/StringTrimmedResultSet.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbutils/wrappers/StringTrimmedResultSet.java b/src/main/java/org/apache/commons/dbutils/wrappers/StringTrimmedResultSet.java
index 830ef72..11c6fb3 100644
--- a/src/main/java/org/apache/commons/dbutils/wrappers/StringTrimmedResultSet.java
+++ b/src/main/java/org/apache/commons/dbutils/wrappers/StringTrimmedResultSet.java
@@ -60,7 +60,7 @@ public class StringTrimmedResultSet implements InvocationHandler {
* @param rs The <code>ResultSet</code> to wrap.
* @return wrapped ResultSet
*/
- public static ResultSet wrap(ResultSet rs) {
+ public static ResultSet wrap(final ResultSet rs) {
return factory.createResultSet(new StringTrimmedResultSet(rs));
}
@@ -74,7 +74,7 @@ public class StringTrimmedResultSet implements InvocationHandler {
* to wrap the specified <code>ResultSet</code>.
* @param rs ResultSet to wrap
*/
- public StringTrimmedResultSet(ResultSet rs) {
+ public StringTrimmedResultSet(final ResultSet rs) {
super();
this.rs = rs;
}
@@ -92,7 +92,7 @@ public class StringTrimmedResultSet implements InvocationHandler {
* @throws Throwable error
*/
@Override
- public Object invoke(Object proxy, Method method, Object[] args)
+ public Object invoke(final Object proxy, final Method method, final Object[] args)
throws Throwable {
Object result = method.invoke(this.rs, args);
http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41e682d6/src/test/java/org/apache/commons/dbutils/AsyncQueryRunnerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/dbutils/AsyncQueryRunnerTest.java b/src/test/java/org/apache/commons/dbutils/AsyncQueryRunnerTest.java
index 3a00aa9..6c0a769 100644
--- a/src/test/java/org/apache/commons/dbutils/AsyncQueryRunnerTest.java
+++ b/src/test/java/org/apache/commons/dbutils/AsyncQueryRunnerTest.java
@@ -1,496 +1,496 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.dbutils;
-
-import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.sql.Connection;
-import java.sql.ParameterMetaData;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-
-import javax.sql.DataSource;
-
-import org.apache.commons.dbutils.handlers.ArrayHandler;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-@SuppressWarnings("boxing") // test code
-public class AsyncQueryRunnerTest {
- AsyncQueryRunner runner;
- ArrayHandler handler;
-
- @Mock DataSource dataSource;
- @Mock Connection conn;
- @Mock PreparedStatement stmt;
- @Mock ParameterMetaData meta;
- @Mock ResultSet results;
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
-
- when(dataSource.getConnection()).thenReturn(conn);
- when(conn.prepareStatement(any(String.class))).thenReturn(stmt);
- when(stmt.getParameterMetaData()).thenReturn(meta);
- when(stmt.getResultSet()).thenReturn(results);
- when(stmt.executeQuery()).thenReturn(results);
- when(results.next()).thenReturn(false);
-
- handler = new ArrayHandler();
- runner = new AsyncQueryRunner(Executors.newFixedThreadPool(1), new QueryRunner(dataSource));
- }
-
- //
- // Batch test cases
- //
- private void callGoodBatch(Connection conn, Object[][] params) throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
- Future<int[]> future = runner.batch(conn, "select * from blah where ? = ?", params);
-
- future.get();
-
- verify(stmt, times(2)).addBatch();
- verify(stmt, times(1)).executeBatch();
- verify(stmt, times(1)).close(); // make sure we closed the statement
- verify(conn, times(0)).close(); // make sure we closed the connection
- }
-
- private void callGoodBatch(Object[][] params) throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
- Future<int[]> future = runner.batch("select * from blah where ? = ?", params);
-
- future.get();
-
- verify(stmt, times(2)).addBatch();
- verify(stmt, times(1)).executeBatch();
- verify(stmt, times(1)).close(); // make sure we closed the statement
- verify(conn, times(1)).close(); // make sure we closed the connection
- }
-
- @Test
- public void testGoodBatch() throws Exception {
- String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
-
- callGoodBatch(params);
- }
-
- @SuppressWarnings("deprecation") // deliberate test of deprecated code
- @Test
- public void testGoodBatchPmdTrue() throws Exception {
- runner = new AsyncQueryRunner(dataSource, true, Executors.newFixedThreadPool(1));
- String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
-
- callGoodBatch(params);
- }
-
- @Test
- public void testGoodBatchDefaultConstructor() throws Exception {
- runner = new AsyncQueryRunner(Executors.newFixedThreadPool(1));
- String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
-
- callGoodBatch(conn, params);
- }
-
- @Test
- public void testNullParamsBatch() throws Exception {
- String[][] params = new String[][] { { null, "unit" }, { "test", null } };
-
- callGoodBatch(params);
- }
-
-
-
- // helper method for calling batch when an exception is expected
- private void callBatchWithException(String sql, Object[][] params) throws Exception {
- Future<int[]> future = null;
- boolean caught = false;
-
- try {
- future = runner.batch(sql, params);
-
- future.get();
-
- verify(stmt, times(2)).addBatch();
- verify(stmt, times(1)).executeBatch();
- verify(stmt, times(1)).close(); // make sure the statement is closed
- verify(conn, times(1)).close(); // make sure the connection is closed
- } catch(Exception e) {
- caught = true;
- }
-
- if(!caught) {
- fail("Exception never thrown, but expected");
- }
- }
-
- @Test
- public void testTooFewParamsBatch() throws Exception {
- String[][] params = new String[][] { { "unit" }, { "test" } };
-
- callBatchWithException("select * from blah where ? = ?", params);
- }
-
- @Test
- public void testTooManyParamsBatch() throws Exception {
- String[][] params = new String[][] { { "unit", "unit", "unit" }, { "test", "test", "test" } };
-
- callBatchWithException("select * from blah where ? = ?", params);
- }
-
- @Test(expected=ExecutionException.class)
- public void testNullConnectionBatch() throws Exception {
- 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();
- }
-
- @Test(expected=ExecutionException.class)
- public void testNullSqlBatch() throws Exception {
- 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();
- }
-
- @Test
- public void testAddBatchException() throws Exception {
- String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
-
- doThrow(new SQLException()).when(stmt).addBatch();
-
- callBatchWithException("select * from blah where ? = ?", params);
- }
-
- @Test
- public void testExecuteBatchException() throws Exception {
- String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
-
- doThrow(new SQLException()).when(stmt).executeBatch();
-
- callBatchWithException("select * from blah where ? = ?", params);
- }
-
-
- //
- // Query test cases
- //
- private void callGoodQuery(Connection conn) throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
- runner.query(conn, "select * from blah where ? = ?", handler, "unit", "test").get();
-
- verify(stmt, times(1)).executeQuery();
- verify(results, times(1)).close();
- verify(stmt, times(1)).close(); // make sure we closed the statement
- verify(conn, times(0)).close(); // make sure we closed the connection
-
- // call the other variation of query
- when(meta.getParameterCount()).thenReturn(0);
- runner.query(conn, "select * from blah", handler).get();
-
- verify(stmt, times(2)).executeQuery();
- verify(results, times(2)).close();
- verify(stmt, times(2)).close(); // make sure we closed the statement
- verify(conn, times(0)).close(); // make sure we closed the connection
- }
-
- private void callGoodQuery() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
- runner.query("select * from blah where ? = ?", handler, "unit", "test").get();
-
- verify(stmt, times(1)).executeQuery();
- verify(results, times(1)).close();
- verify(stmt, times(1)).close(); // make sure we closed the statement
- verify(conn, times(1)).close(); // make sure we closed the connection
-
- // call the other variation of query
- when(meta.getParameterCount()).thenReturn(0);
- runner.query("select * from blah", handler).get();
-
- verify(stmt, times(2)).executeQuery();
- verify(results, times(2)).close();
- verify(stmt, times(2)).close(); // make sure we closed the statement
- verify(conn, times(2)).close(); // make sure we closed the connection
- }
-
- @Test
- public void testGoodQuery() throws Exception {
- callGoodQuery();
- }
-
- @SuppressWarnings("deprecation") // deliberate test of deprecated code
- @Test
- public void testGoodQueryPmdTrue() throws Exception {
- runner = new AsyncQueryRunner(true, Executors.newFixedThreadPool(1));
- callGoodQuery(conn);
- }
-
- @Test
- public void testGoodQueryDefaultConstructor() throws Exception {
- runner = new AsyncQueryRunner(Executors.newFixedThreadPool(1));
- callGoodQuery(conn);
- }
-
-
- // helper method for calling batch when an exception is expected
- private void callQueryWithException(Object... params) throws Exception {
- boolean caught = false;
-
- try {
- when(meta.getParameterCount()).thenReturn(2);
- runner.query("select * from blah where ? = ?", handler, params).get();
-
- verify(stmt, times(1)).executeQuery();
- verify(results, times(1)).close();
- verify(stmt, times(1)).close(); // make sure we closed the statement
- verify(conn, times(1)).close(); // make sure we closed the connection
- } catch(Exception e) {
- caught = true;
- }
-
- if(!caught) {
- fail("Exception never thrown, but expected");
- }
- }
-
- @Test
- public void testNoParamsQuery() throws Exception {
- callQueryWithException();
- }
-
- @Test
- public void testTooFewParamsQuery() throws Exception {
- callQueryWithException("unit");
- }
-
- @Test
- public void testTooManyParamsQuery() throws Exception {
- callQueryWithException("unit", "test", "fail");
- }
-
- @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();
- }
-
- @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(stmt).executeQuery();
-
- callQueryWithException(handler, "unit", "test");
- }
-
-
- //
- // Update test cases
- //
- private void callGoodUpdate(Connection conn) throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
- runner.update(conn, "update blah set ? = ?", "unit", "test").get();
-
- verify(stmt, times(1)).executeUpdate();
- verify(stmt, times(1)).close(); // make sure we closed the statement
- verify(conn, times(0)).close(); // make sure we closed the connection
-
- // call the other variation
- when(meta.getParameterCount()).thenReturn(0);
- runner.update(conn, "update blah set unit = test").get();
-
- verify(stmt, times(2)).executeUpdate();
- verify(stmt, times(2)).close(); // make sure we closed the statement
- verify(conn, times(0)).close(); // make sure we closed the connection
-
- // call the other variation
- when(meta.getParameterCount()).thenReturn(1);
- runner.update(conn, "update blah set unit = ?", "test").get();
-
- verify(stmt, times(3)).executeUpdate();
- verify(stmt, times(3)).close(); // make sure we closed the statement
- verify(conn, times(0)).close(); // make sure we closed the connection
- }
-
- private void callGoodUpdate() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
- runner.update("update blah set ? = ?", "unit", "test").get();
-
- verify(stmt, times(1)).executeUpdate();
- verify(stmt, times(1)).close(); // make sure we closed the statement
- verify(conn, times(1)).close(); // make sure we closed the connection
-
- // call the other variation
- when(meta.getParameterCount()).thenReturn(0);
- runner.update("update blah set unit = test").get();
-
- verify(stmt, times(2)).executeUpdate();
- verify(stmt, times(2)).close(); // make sure we closed the statement
- verify(conn, times(2)).close(); // make sure we closed the connection
-
- // call the other variation
- when(meta.getParameterCount()).thenReturn(1);
- runner.update("update blah set unit = ?", "test").get();
-
- verify(stmt, times(3)).executeUpdate();
- verify(stmt, times(3)).close(); // make sure we closed the statement
- verify(conn, times(3)).close(); // make sure we closed the connection
- }
-
- @Test
- public void testGoodUpdate() throws Exception {
- callGoodUpdate();
- }
-
- @SuppressWarnings("deprecation") // deliberate test of deprecated code
- @Test
- public void testGoodUpdatePmdTrue() throws Exception {
- runner = new AsyncQueryRunner(true, Executors.newFixedThreadPool(1));
- callGoodUpdate(conn);
- }
-
- @Test
- public void testGoodUpdateDefaultConstructor() throws Exception {
- runner = new AsyncQueryRunner(Executors.newFixedThreadPool(1));
- callGoodUpdate(conn);
- }
-
- // helper method for calling batch when an exception is expected
- private void callUpdateWithException(Object... params) throws Exception {
- boolean caught = false;
-
- try {
- when(meta.getParameterCount()).thenReturn(2);
- runner.update("select * from blah where ? = ?", params).get();
-
- verify(stmt, times(1)).executeUpdate();
- verify(stmt, times(1)).close(); // make sure we closed the statement
- verify(conn, times(1)).close(); // make sure we closed the connection
- } catch(Exception e) {
- caught = true;
- }
-
- if(!caught) {
- fail("Exception never thrown, but expected");
- }
- }
-
- @Test
- public void testNoParamsUpdate() throws Exception {
- callUpdateWithException();
- }
-
- @Test
- public void testTooFewParamsUpdate() throws Exception {
- callUpdateWithException("unit");
- }
-
- @Test
- public void testTooManyParamsUpdate() throws Exception {
- callUpdateWithException("unit", "test", "fail");
- }
-
- @Test
- public void testInsertUsesGivenQueryRunner() throws Exception {
- QueryRunner mockQueryRunner = mock(QueryRunner.class
- , org.mockito.Mockito.withSettings().verboseLogging() // debug for Continuum
- );
- runner = new AsyncQueryRunner(Executors.newSingleThreadExecutor(), mockQueryRunner);
-
- runner.insert("1", handler);
- runner.insert("2", handler, "param1");
- runner.insert(conn, "3", handler);
- runner.insert(conn, "4", handler, "param1");
-
- // give the Executor time to submit all insert statements. Otherwise the following verify statements will fail from time to time.
- TimeUnit.MILLISECONDS.sleep(50);
-
- verify(mockQueryRunner).insert("1", handler);
- verify(mockQueryRunner).insert("2", handler, "param1");
- verify(mockQueryRunner).insert(conn, "3", handler);
- verify(mockQueryRunner).insert(conn, "4", handler, "param1");
- }
-
- @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();
- }
-
- @Test(expected=ExecutionException.class)
- public void testNullSqlUpdate() throws Exception {
- when(meta.getParameterCount()).thenReturn(2);
-
- runner.update(null).get();
- }
-
- @Test
- public void testExecuteUpdateException() throws Exception {
- doThrow(new SQLException()).when(stmt).executeUpdate();
-
- callUpdateWithException("unit", "test");
- }
-
- //
- // Random tests
- //
- @Test(expected=ExecutionException.class)
- public void testBadPrepareConnection() throws Exception {
- runner = new AsyncQueryRunner(Executors.newFixedThreadPool(1));
- runner.update("update blah set unit = test").get();
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.dbutils;
+
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.sql.Connection;
+import java.sql.ParameterMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import javax.sql.DataSource;
+
+import org.apache.commons.dbutils.handlers.ArrayHandler;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+@SuppressWarnings("boxing") // test code
+public class AsyncQueryRunnerTest {
+ AsyncQueryRunner runner;
+ ArrayHandler handler;
+
+ @Mock DataSource dataSource;
+ @Mock Connection conn;
+ @Mock PreparedStatement stmt;
+ @Mock ParameterMetaData meta;
+ @Mock ResultSet results;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ when(dataSource.getConnection()).thenReturn(conn);
+ when(conn.prepareStatement(any(String.class))).thenReturn(stmt);
+ when(stmt.getParameterMetaData()).thenReturn(meta);
+ when(stmt.getResultSet()).thenReturn(results);
+ when(stmt.executeQuery()).thenReturn(results);
+ when(results.next()).thenReturn(false);
+
+ handler = new ArrayHandler();
+ runner = new AsyncQueryRunner(Executors.newFixedThreadPool(1), new QueryRunner(dataSource));
+ }
+
+ //
+ // Batch test cases
+ //
+ private void callGoodBatch(final Connection conn, final Object[][] params) throws Exception {
+ when(meta.getParameterCount()).thenReturn(2);
+ Future<int[]> future = runner.batch(conn, "select * from blah where ? = ?", params);
+
+ future.get();
+
+ verify(stmt, times(2)).addBatch();
+ verify(stmt, times(1)).executeBatch();
+ verify(stmt, times(1)).close(); // make sure we closed the statement
+ verify(conn, times(0)).close(); // make sure we closed the connection
+ }
+
+ private void callGoodBatch(final Object[][] params) throws Exception {
+ when(meta.getParameterCount()).thenReturn(2);
+ Future<int[]> future = runner.batch("select * from blah where ? = ?", params);
+
+ future.get();
+
+ verify(stmt, times(2)).addBatch();
+ verify(stmt, times(1)).executeBatch();
+ verify(stmt, times(1)).close(); // make sure we closed the statement
+ verify(conn, times(1)).close(); // make sure we closed the connection
+ }
+
+ @Test
+ public void testGoodBatch() throws Exception {
+ String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
+
+ callGoodBatch(params);
+ }
+
+ @SuppressWarnings("deprecation") // deliberate test of deprecated code
+ @Test
+ public void testGoodBatchPmdTrue() throws Exception {
+ runner = new AsyncQueryRunner(dataSource, true, Executors.newFixedThreadPool(1));
+ String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
+
+ callGoodBatch(params);
+ }
+
+ @Test
+ public void testGoodBatchDefaultConstructor() throws Exception {
+ runner = new AsyncQueryRunner(Executors.newFixedThreadPool(1));
+ String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
+
+ callGoodBatch(conn, params);
+ }
+
+ @Test
+ public void testNullParamsBatch() throws Exception {
+ String[][] params = new String[][] { { null, "unit" }, { "test", null } };
+
+ callGoodBatch(params);
+ }
+
+
+
+ // helper method for calling batch when an exception is expected
+ private void callBatchWithException(final String sql, final Object[][] params) throws Exception {
+ Future<int[]> future = null;
+ boolean caught = false;
+
+ try {
+ future = runner.batch(sql, params);
+
+ future.get();
+
+ verify(stmt, times(2)).addBatch();
+ verify(stmt, times(1)).executeBatch();
+ verify(stmt, times(1)).close(); // make sure the statement is closed
+ verify(conn, times(1)).close(); // make sure the connection is closed
+ } catch(Exception e) {
+ caught = true;
+ }
+
+ if(!caught) {
+ fail("Exception never thrown, but expected");
+ }
+ }
+
+ @Test
+ public void testTooFewParamsBatch() throws Exception {
+ String[][] params = new String[][] { { "unit" }, { "test" } };
+
+ callBatchWithException("select * from blah where ? = ?", params);
+ }
+
+ @Test
+ public void testTooManyParamsBatch() throws Exception {
+ String[][] params = new String[][] { { "unit", "unit", "unit" }, { "test", "test", "test" } };
+
+ callBatchWithException("select * from blah where ? = ?", params);
+ }
+
+ @Test(expected=ExecutionException.class)
+ public void testNullConnectionBatch() throws Exception {
+ 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();
+ }
+
+ @Test(expected=ExecutionException.class)
+ public void testNullSqlBatch() throws Exception {
+ 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();
+ }
+
+ @Test
+ public void testAddBatchException() throws Exception {
+ String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
+
+ doThrow(new SQLException()).when(stmt).addBatch();
+
+ callBatchWithException("select * from blah where ? = ?", params);
+ }
+
+ @Test
+ public void testExecuteBatchException() throws Exception {
+ String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
+
+ doThrow(new SQLException()).when(stmt).executeBatch();
+
+ callBatchWithException("select * from blah where ? = ?", params);
+ }
+
+
+ //
+ // Query test cases
+ //
+ private void callGoodQuery(final Connection conn) throws Exception {
+ when(meta.getParameterCount()).thenReturn(2);
+ runner.query(conn, "select * from blah where ? = ?", handler, "unit", "test").get();
+
+ verify(stmt, times(1)).executeQuery();
+ verify(results, times(1)).close();
+ verify(stmt, times(1)).close(); // make sure we closed the statement
+ verify(conn, times(0)).close(); // make sure we closed the connection
+
+ // call the other variation of query
+ when(meta.getParameterCount()).thenReturn(0);
+ runner.query(conn, "select * from blah", handler).get();
+
+ verify(stmt, times(2)).executeQuery();
+ verify(results, times(2)).close();
+ verify(stmt, times(2)).close(); // make sure we closed the statement
+ verify(conn, times(0)).close(); // make sure we closed the connection
+ }
+
+ private void callGoodQuery() throws Exception {
+ when(meta.getParameterCount()).thenReturn(2);
+ runner.query("select * from blah where ? = ?", handler, "unit", "test").get();
+
+ verify(stmt, times(1)).executeQuery();
+ verify(results, times(1)).close();
+ verify(stmt, times(1)).close(); // make sure we closed the statement
+ verify(conn, times(1)).close(); // make sure we closed the connection
+
+ // call the other variation of query
+ when(meta.getParameterCount()).thenReturn(0);
+ runner.query("select * from blah", handler).get();
+
+ verify(stmt, times(2)).executeQuery();
+ verify(results, times(2)).close();
+ verify(stmt, times(2)).close(); // make sure we closed the statement
+ verify(conn, times(2)).close(); // make sure we closed the connection
+ }
+
+ @Test
+ public void testGoodQuery() throws Exception {
+ callGoodQuery();
+ }
+
+ @SuppressWarnings("deprecation") // deliberate test of deprecated code
+ @Test
+ public void testGoodQueryPmdTrue() throws Exception {
+ runner = new AsyncQueryRunner(true, Executors.newFixedThreadPool(1));
+ callGoodQuery(conn);
+ }
+
+ @Test
+ public void testGoodQueryDefaultConstructor() throws Exception {
+ runner = new AsyncQueryRunner(Executors.newFixedThreadPool(1));
+ callGoodQuery(conn);
+ }
+
+
+ // helper method for calling batch when an exception is expected
+ private void callQueryWithException(final Object... params) throws Exception {
+ boolean caught = false;
+
+ try {
+ when(meta.getParameterCount()).thenReturn(2);
+ runner.query("select * from blah where ? = ?", handler, params).get();
+
+ verify(stmt, times(1)).executeQuery();
+ verify(results, times(1)).close();
+ verify(stmt, times(1)).close(); // make sure we closed the statement
+ verify(conn, times(1)).close(); // make sure we closed the connection
+ } catch(Exception e) {
+ caught = true;
+ }
+
+ if(!caught) {
+ fail("Exception never thrown, but expected");
+ }
+ }
+
+ @Test
+ public void testNoParamsQuery() throws Exception {
+ callQueryWithException();
+ }
+
+ @Test
+ public void testTooFewParamsQuery() throws Exception {
+ callQueryWithException("unit");
+ }
+
+ @Test
+ public void testTooManyParamsQuery() throws Exception {
+ callQueryWithException("unit", "test", "fail");
+ }
+
+ @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();
+ }
+
+ @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(stmt).executeQuery();
+
+ callQueryWithException(handler, "unit", "test");
+ }
+
+
+ //
+ // Update test cases
+ //
+ private void callGoodUpdate(final Connection conn) throws Exception {
+ when(meta.getParameterCount()).thenReturn(2);
+ runner.update(conn, "update blah set ? = ?", "unit", "test").get();
+
+ verify(stmt, times(1)).executeUpdate();
+ verify(stmt, times(1)).close(); // make sure we closed the statement
+ verify(conn, times(0)).close(); // make sure we closed the connection
+
+ // call the other variation
+ when(meta.getParameterCount()).thenReturn(0);
+ runner.update(conn, "update blah set unit = test").get();
+
+ verify(stmt, times(2)).executeUpdate();
+ verify(stmt, times(2)).close(); // make sure we closed the statement
+ verify(conn, times(0)).close(); // make sure we closed the connection
+
+ // call the other variation
+ when(meta.getParameterCount()).thenReturn(1);
+ runner.update(conn, "update blah set unit = ?", "test").get();
+
+ verify(stmt, times(3)).executeUpdate();
+ verify(stmt, times(3)).close(); // make sure we closed the statement
+ verify(conn, times(0)).close(); // make sure we closed the connection
+ }
+
+ private void callGoodUpdate() throws Exception {
+ when(meta.getParameterCount()).thenReturn(2);
+ runner.update("update blah set ? = ?", "unit", "test").get();
+
+ verify(stmt, times(1)).executeUpdate();
+ verify(stmt, times(1)).close(); // make sure we closed the statement
+ verify(conn, times(1)).close(); // make sure we closed the connection
+
+ // call the other variation
+ when(meta.getParameterCount()).thenReturn(0);
+ runner.update("update blah set unit = test").get();
+
+ verify(stmt, times(2)).executeUpdate();
+ verify(stmt, times(2)).close(); // make sure we closed the statement
+ verify(conn, times(2)).close(); // make sure we closed the connection
+
+ // call the other variation
+ when(meta.getParameterCount()).thenReturn(1);
+ runner.update("update blah set unit = ?", "test").get();
+
+ verify(stmt, times(3)).executeUpdate();
+ verify(stmt, times(3)).close(); // make sure we closed the statement
+ verify(conn, times(3)).close(); // make sure we closed the connection
+ }
+
+ @Test
+ public void testGoodUpdate() throws Exception {
+ callGoodUpdate();
+ }
+
+ @SuppressWarnings("deprecation") // deliberate test of deprecated code
+ @Test
+ public void testGoodUpdatePmdTrue() throws Exception {
+ runner = new AsyncQueryRunner(true, Executors.newFixedThreadPool(1));
+ callGoodUpdate(conn);
+ }
+
+ @Test
+ public void testGoodUpdateDefaultConstructor() throws Exception {
+ runner = new AsyncQueryRunner(Executors.newFixedThreadPool(1));
+ callGoodUpdate(conn);
+ }
+
+ // helper method for calling batch when an exception is expected
+ private void callUpdateWithException(final Object... params) throws Exception {
+ boolean caught = false;
+
+ try {
+ when(meta.getParameterCount()).thenReturn(2);
+ runner.update("select * from blah where ? = ?", params).get();
+
+ verify(stmt, times(1)).executeUpdate();
+ verify(stmt, times(1)).close(); // make sure we closed the statement
+ verify(conn, times(1)).close(); // make sure we closed the connection
+ } catch(Exception e) {
+ caught = true;
+ }
+
+ if(!caught) {
+ fail("Exception never thrown, but expected");
+ }
+ }
+
+ @Test
+ public void testNoParamsUpdate() throws Exception {
+ callUpdateWithException();
+ }
+
+ @Test
+ public void testTooFewParamsUpdate() throws Exception {
+ callUpdateWithException("unit");
+ }
+
+ @Test
+ public void testTooManyParamsUpdate() throws Exception {
+ callUpdateWithException("unit", "test", "fail");
+ }
+
+ @Test
+ public void testInsertUsesGivenQueryRunner() throws Exception {
+ QueryRunner mockQueryRunner = mock(QueryRunner.class
+ , org.mockito.Mockito.withSettings().verboseLogging() // debug for Continuum
+ );
+ runner = new AsyncQueryRunner(Executors.newSingleThreadExecutor(), mockQueryRunner);
+
+ runner.insert("1", handler);
+ runner.insert("2", handler, "param1");
+ runner.insert(conn, "3", handler);
+ runner.insert(conn, "4", handler, "param1");
+
+ // give the Executor time to submit all insert statements. Otherwise the following verify statements will fail from time to time.
+ TimeUnit.MILLISECONDS.sleep(50);
+
+ verify(mockQueryRunner).insert("1", handler);
+ verify(mockQueryRunner).insert("2", handler, "param1");
+ verify(mockQueryRunner).insert(conn, "3", handler);
+ verify(mockQueryRunner).insert(conn, "4", handler, "param1");
+ }
+
+ @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();
+ }
+
+ @Test(expected=ExecutionException.class)
+ public void testNullSqlUpdate() throws Exception {
+ when(meta.getParameterCount()).thenReturn(2);
+
+ runner.update(null).get();
+ }
+
+ @Test
+ public void testExecuteUpdateException() throws Exception {
+ doThrow(new SQLException()).when(stmt).executeUpdate();
+
+ callUpdateWithException("unit", "test");
+ }
+
+ //
+ // Random tests
+ //
+ @Test(expected=ExecutionException.class)
+ public void testBadPrepareConnection() throws Exception {
+ runner = new AsyncQueryRunner(Executors.newFixedThreadPool(1));
+ runner.update("update blah set unit = test").get();
+ }
+}
http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41e682d6/src/test/java/org/apache/commons/dbutils/BeanProcessorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/dbutils/BeanProcessorTest.java b/src/test/java/org/apache/commons/dbutils/BeanProcessorTest.java
index cb591a2..e1606e4 100644
--- a/src/test/java/org/apache/commons/dbutils/BeanProcessorTest.java
+++ b/src/test/java/org/apache/commons/dbutils/BeanProcessorTest.java
@@ -71,7 +71,7 @@ public class BeanProcessorTest extends BaseTestCase {
return one;
}
- public void setOne(String one) {
+ public void setOne(final String one) {
this.one = one;
}
@@ -79,7 +79,7 @@ public class BeanProcessorTest extends BaseTestCase {
return two;
}
- public void setTwo(String two) {
+ public void setTwo(final String two) {
this.two = two;
}
@@ -87,7 +87,7 @@ public class BeanProcessorTest extends BaseTestCase {
return three;
}
- public void setThree(String three) {
+ public void setThree(final String three) {
this.three = three;
}
@@ -95,7 +95,7 @@ public class BeanProcessorTest extends BaseTestCase {
return four;
}
- public void setFour(String four) {
+ public void setFour(final String four) {
this.four = four;
}
}
http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41e682d6/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java b/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java
index 2013627..24a5639 100644
--- a/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java
+++ b/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java
@@ -1,156 +1,156 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.dbutils;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-import java.beans.PropertyDescriptor;
-import java.sql.ResultSetMetaData;
-
-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();
- @Mock ResultSetMetaData metaData;
- PropertyDescriptor[] propDescriptors;
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
-
- propDescriptors = new PropertyDescriptor[3];
-
- propDescriptors[0] = new PropertyDescriptor("one", TestBean.class);
- propDescriptors[1] = new PropertyDescriptor("two", TestBean.class);
- propDescriptors[2] = new PropertyDescriptor("three", TestBean.class);
- }
-
- @SuppressWarnings("boxing") // test code
- @Test
- public void testMapColumnsToPropertiesWithOutUnderscores() throws Exception {
- when(metaData.getColumnCount()).thenReturn(3);
-
- when(metaData.getColumnLabel(1)).thenReturn("three");
- when(metaData.getColumnLabel(2)).thenReturn("one");
- when(metaData.getColumnLabel(3)).thenReturn("two");
-
- 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 testMapColumnsToPropertiesMixedCase() throws Exception {
- when(metaData.getColumnCount()).thenReturn(3);
-
- when(metaData.getColumnLabel(1)).thenReturn("tHree");
- when(metaData.getColumnLabel(2)).thenReturn("One");
- when(metaData.getColumnLabel(3)).thenReturn("tWO");
-
- 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 testMapColumnsToPropertiesWithUnderscores() throws Exception {
- when(metaData.getColumnCount()).thenReturn(3);
-
- when(metaData.getColumnLabel(1)).thenReturn("t_h_r_e_e");
- when(metaData.getColumnLabel(2)).thenReturn("o_n_e");
- when(metaData.getColumnLabel(3)).thenReturn("t_w_o");
-
- 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");
-
- int[] ret = processor.mapColumnsToProperties(metaData, propDescriptors);
-
- assertNotNull(ret);
- assertEquals(2, ret.length);
- assertEquals(-1, ret[0]);
- assertEquals(-1, ret[1]);
- assertEquals(-1, ret[1]);
- assertEquals(-1, ret[1]);
- }
-
- static class TestBean {
- private String one;
- private int two;
- private long three;
-
- public String getOne() {
- return one;
- }
-
- public void setOne(String one) {
- this.one = one;
- }
-
- public int getTwo() {
- return two;
- }
-
- public void setTwo(int two) {
- this.two = two;
- }
-
- public long getThree() {
- return three;
- }
-
- public void setThree(long three) {
- this.three = three;
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.dbutils;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.beans.PropertyDescriptor;
+import java.sql.ResultSetMetaData;
+
+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();
+ @Mock ResultSetMetaData metaData;
+ PropertyDescriptor[] propDescriptors;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ propDescriptors = new PropertyDescriptor[3];
+
+ propDescriptors[0] = new PropertyDescriptor("one", TestBean.class);
+ propDescriptors[1] = new PropertyDescriptor("two", TestBean.class);
+ propDescriptors[2] = new PropertyDescriptor("three", TestBean.class);
+ }
+
+ @SuppressWarnings("boxing") // test code
+ @Test
+ public void testMapColumnsToPropertiesWithOutUnderscores() throws Exception {
+ when(metaData.getColumnCount()).thenReturn(3);
+
+ when(metaData.getColumnLabel(1)).thenReturn("three");
+ when(metaData.getColumnLabel(2)).thenReturn("one");
+ when(metaData.getColumnLabel(3)).thenReturn("two");
+
+ 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 testMapColumnsToPropertiesMixedCase() throws Exception {
+ when(metaData.getColumnCount()).thenReturn(3);
+
+ when(metaData.getColumnLabel(1)).thenReturn("tHree");
+ when(metaData.getColumnLabel(2)).thenReturn("One");
+ when(metaData.getColumnLabel(3)).thenReturn("tWO");
+
+ 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 testMapColumnsToPropertiesWithUnderscores() throws Exception {
+ when(metaData.getColumnCount()).thenReturn(3);
+
+ when(metaData.getColumnLabel(1)).thenReturn("t_h_r_e_e");
+ when(metaData.getColumnLabel(2)).thenReturn("o_n_e");
+ when(metaData.getColumnLabel(3)).thenReturn("t_w_o");
+
+ 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");
+
+ int[] ret = processor.mapColumnsToProperties(metaData, propDescriptors);
+
+ assertNotNull(ret);
+ assertEquals(2, ret.length);
+ assertEquals(-1, ret[0]);
+ assertEquals(-1, ret[1]);
+ assertEquals(-1, ret[1]);
+ assertEquals(-1, ret[1]);
+ }
+
+ static class TestBean {
+ private String one;
+ private int two;
+ private long three;
+
+ public String getOne() {
+ return one;
+ }
+
+ public void setOne(final String one) {
+ this.one = one;
+ }
+
+ public int getTwo() {
+ return two;
+ }
+
+ public void setTwo(final int two) {
+ this.two = two;
+ }
+
+ public long getThree() {
+ return three;
+ }
+
+ public void setThree(final long three) {
+ this.three = three;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41e682d6/src/test/java/org/apache/commons/dbutils/MockResultSet.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/dbutils/MockResultSet.java b/src/test/java/org/apache/commons/dbutils/MockResultSet.java
index e1d2e49..c89b5bd 100644
--- a/src/test/java/org/apache/commons/dbutils/MockResultSet.java
+++ b/src/test/java/org/apache/commons/dbutils/MockResultSet.java
@@ -40,8 +40,8 @@ public class MockResultSet implements InvocationHandler {
* @param metaData
* @param rows A null value indicates an empty <code>ResultSet</code>.
*/
- public static ResultSet create(ResultSetMetaData metaData,
- Object[][] rows) {
+ public static ResultSet create(final ResultSetMetaData metaData,
+ final Object[][] rows) {
return ProxyFactory.instance().createResultSet(
new MockResultSet(metaData, rows));
}
@@ -59,7 +59,7 @@ public class MockResultSet implements InvocationHandler {
* @param metaData
* @param rows A null value indicates an empty <code>ResultSet</code>.
*/
- public MockResultSet(ResultSetMetaData metaData, Object[][] rows) {
+ public MockResultSet(final ResultSetMetaData metaData, final Object[][] rows) {
super();
this.metaData = metaData;
if (rows == null) {
@@ -78,7 +78,7 @@ public class MockResultSet implements InvocationHandler {
* @return A column index.
* @throws SQLException if a database access error occurs
*/
- private int columnIndex(Object[] args) throws SQLException {
+ private int columnIndex(final Object[] args) throws SQLException {
if (args[0] instanceof Integer) {
return ((Integer) args[0]).intValue();
@@ -96,7 +96,7 @@ public class MockResultSet implements InvocationHandler {
* @return A 1 based index
* @throws SQLException if the column name is invalid
*/
- private int columnNameToIndex(String columnName) throws SQLException {
+ private int columnNameToIndex(final String columnName) throws SQLException {
for (int i = 0; i < this.currentRow.length; i++) {
int c = i + 1;
if (this.metaData.getColumnName(c).equalsIgnoreCase(columnName)) {
@@ -112,7 +112,7 @@ public class MockResultSet implements InvocationHandler {
* @param columnIndex A 1 based index.
* @throws SQLException if a database access error occurs
*/
- protected Object getBoolean(int columnIndex) throws SQLException {
+ protected Object getBoolean(final int columnIndex) throws SQLException {
Object obj = this.currentRow[columnIndex - 1];
this.setWasNull(obj);
@@ -131,7 +131,7 @@ public class MockResultSet implements InvocationHandler {
* @param columnIndex A 1 based index.
* @throws SQLException if a database access error occurs
*/
- protected Object getByte(int columnIndex) throws SQLException {
+ protected Object getByte(final int columnIndex) throws SQLException {
Object obj = this.currentRow[columnIndex - 1];
this.setWasNull(obj);
@@ -150,7 +150,7 @@ public class MockResultSet implements InvocationHandler {
* @param columnIndex A 1 based index.
* @throws SQLException if a database access error occurs
*/
- protected Object getDouble(int columnIndex) throws SQLException {
+ protected Object getDouble(final int columnIndex) throws SQLException {
Object obj = this.currentRow[columnIndex - 1];
this.setWasNull(obj);
@@ -169,7 +169,7 @@ public class MockResultSet implements InvocationHandler {
* @param columnIndex A 1 based index.
* @throws SQLException if a database access error occurs
*/
- protected Object getFloat(int columnIndex) throws SQLException {
+ protected Object getFloat(final int columnIndex) throws SQLException {
Object obj = this.currentRow[columnIndex - 1];
this.setWasNull(obj);
@@ -186,7 +186,7 @@ public class MockResultSet implements InvocationHandler {
* @param columnIndex A 1 based index.
* @throws SQLException if a database access error occurs
*/
- protected Object getInt(int columnIndex) throws SQLException {
+ protected Object getInt(final int columnIndex) throws SQLException {
Object obj = this.currentRow[columnIndex - 1];
this.setWasNull(obj);
@@ -205,7 +205,7 @@ public class MockResultSet implements InvocationHandler {
* @param columnIndex A 1 based index.
* @throws SQLException if a database access error occurs
*/
- protected Object getLong(int columnIndex) throws SQLException {
+ protected Object getLong(final int columnIndex) throws SQLException {
Object obj = this.currentRow[columnIndex - 1];
this.setWasNull(obj);
@@ -229,7 +229,7 @@ public class MockResultSet implements InvocationHandler {
* @param columnIndex A 1 based index.
* @throws SQLException if a database access error occurs
*/
- protected Object getObject(int columnIndex) throws SQLException {
+ protected Object getObject(final int columnIndex) throws SQLException {
Object obj = this.currentRow[columnIndex - 1];
this.setWasNull(obj);
return obj;
@@ -240,7 +240,7 @@ public class MockResultSet implements InvocationHandler {
* @param columnIndex A 1 based index.
* @throws SQLException if a database access error occurs
*/
- protected Object getShort(int columnIndex) throws SQLException {
+ protected Object getShort(final int columnIndex) throws SQLException {
Object obj = this.currentRow[columnIndex - 1];
this.setWasNull(obj);
@@ -259,14 +259,14 @@ public class MockResultSet implements InvocationHandler {
* @param columnIndex A 1 based index.
* @throws SQLException if a database access error occurs
*/
- protected String getString(int columnIndex) throws SQLException {
+ protected String getString(final int columnIndex) throws SQLException {
Object obj = this.getObject(columnIndex);
this.setWasNull(obj);
return (obj == null) ? null : obj.toString();
}
@Override
- public Object invoke(Object proxy, Method method, Object[] args)
+ public Object invoke(final Object proxy, final Method method, final Object[] args)
throws Throwable {
String methodName = method.getName();
@@ -350,7 +350,7 @@ public class MockResultSet implements InvocationHandler {
* Assigns this.wasNull a Boolean value based on the object passed in.
* @param isNull
*/
- private void setWasNull(Object isNull) {
+ private void setWasNull(final Object isNull) {
this.wasNull = (isNull == null) ? Boolean.TRUE : Boolean.FALSE;
}
http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41e682d6/src/test/java/org/apache/commons/dbutils/MockResultSetMetaData.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/dbutils/MockResultSetMetaData.java b/src/test/java/org/apache/commons/dbutils/MockResultSetMetaData.java
index 2e02807..92e4f29 100644
--- a/src/test/java/org/apache/commons/dbutils/MockResultSetMetaData.java
+++ b/src/test/java/org/apache/commons/dbutils/MockResultSetMetaData.java
@@ -39,19 +39,19 @@ public class MockResultSetMetaData implements InvocationHandler {
* @param columnNames
* @return the proxy object
*/
- public static ResultSetMetaData create(String[] columnNames) {
+ public static ResultSetMetaData create(final String[] columnNames) {
return ProxyFactory.instance().createResultSetMetaData(
new MockResultSetMetaData(columnNames));
}
- public MockResultSetMetaData(String[] columnNames) {
+ public MockResultSetMetaData(final String[] columnNames) {
super();
this.columnNames = columnNames;
this.columnLabels = new String[columnNames.length];
}
- public MockResultSetMetaData(String[] columnNames, String[] columnLabels) {
+ public MockResultSetMetaData(final String[] columnNames, final String[] columnLabels) {
super();
this.columnNames = columnNames;
this.columnLabels = columnLabels;
@@ -59,7 +59,7 @@ public class MockResultSetMetaData implements InvocationHandler {
}
@Override
- public Object invoke(Object proxy, Method method, Object[] args)
+ public Object invoke(final Object proxy, final Method method, final Object[] args)
throws Throwable {
String methodName = method.getName();
http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41e682d6/src/test/java/org/apache/commons/dbutils/ProxyFactoryTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/dbutils/ProxyFactoryTest.java b/src/test/java/org/apache/commons/dbutils/ProxyFactoryTest.java
index 9466e2f..ac91392 100644
--- a/src/test/java/org/apache/commons/dbutils/ProxyFactoryTest.java
+++ b/src/test/java/org/apache/commons/dbutils/ProxyFactoryTest.java
@@ -28,7 +28,7 @@ public class ProxyFactoryTest extends BaseTestCase {
private static final InvocationHandler stub = new InvocationHandler() {
@Override
- public Object invoke(Object proxy, Method method, Object[] args)
+ public Object invoke(final Object proxy, final Method method, final Object[] args)
throws Throwable {
return null;
http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41e682d6/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java b/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
index ec8778c..f95ac95 100644
--- a/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
+++ b/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
@@ -86,7 +86,7 @@ public class QueryRunnerTest {
// Batch test cases
//
- private void callGoodBatch(Connection conn, Object[][] params) throws Exception {
+ private void callGoodBatch(final Connection conn, final Object[][] params) throws Exception {
when(meta.getParameterCount()).thenReturn(2);
runner.batch(conn, "select * from blah where ? = ?", params);
@@ -96,7 +96,7 @@ public class QueryRunnerTest {
verify(conn, times(0)).close(); // make sure we do not close the connection, since QueryRunner.batch(Connection, String, Object[][]) does not close connections
}
- private void callGoodBatch(Object[][] params) throws Exception {
+ private void callGoodBatch(final Object[][] params) throws Exception {
when(meta.getParameterCount()).thenReturn(2);
runner.batch("select * from blah where ? = ?", params);
@@ -139,7 +139,7 @@ public class QueryRunnerTest {
// helper method for calling batch when an exception is expected
- private void callBatchWithException(String sql, Object[][] params) throws Exception {
+ private void callBatchWithException(final String sql, final Object[][] params) throws Exception {
boolean caught = false;
try {
@@ -220,7 +220,7 @@ public class QueryRunnerTest {
//
// Query test cases
//
- private void callGoodQuery(Connection conn) throws Exception {
+ private void callGoodQuery(final Connection conn) throws Exception {
when(meta.getParameterCount()).thenReturn(2);
runner.query(conn, "select * from blah where ? = ?", handler, "unit", "test");
@@ -277,7 +277,7 @@ public class QueryRunnerTest {
// helper method for calling batch when an exception is expected
- private void callQueryWithException(Object... params) throws Exception {
+ private void callQueryWithException(final Object... params) throws Exception {
boolean caught = false;
try {
@@ -346,7 +346,7 @@ public class QueryRunnerTest {
//
// Update test cases
//
- private void callGoodUpdate(Connection conn) throws Exception {
+ private void callGoodUpdate(final Connection conn) throws Exception {
when(meta.getParameterCount()).thenReturn(2);
runner.update(conn, "update blah set ? = ?", "unit", "test");
@@ -447,7 +447,7 @@ public class QueryRunnerTest {
ResultSetHandler<List<Object>> handler = new ResultSetHandler<List<Object>>()
{
@Override
- public List<Object> handle(ResultSet rs) throws SQLException
+ public List<Object> handle(final ResultSet rs) throws SQLException
{
List<Object> objects = new ArrayList<>();
while (rs.next())
@@ -475,7 +475,7 @@ public class QueryRunnerTest {
}
// helper method for calling batch when an exception is expected
- private void callUpdateWithException(Object... params) throws Exception {
+ private void callUpdateWithException(final Object... params) throws Exception {
boolean caught = false;
try {
@@ -547,7 +547,7 @@ public class QueryRunnerTest {
//
// Execute tests
//
- private void callGoodExecute(Connection conn) throws Exception {
+ private void callGoodExecute(final Connection conn) throws Exception {
when(call.execute()).thenReturn(false);
when(call.getUpdateCount()).thenReturn(3);
@@ -701,7 +701,7 @@ public class QueryRunnerTest {
}
// helper method for calling execute when an exception is expected
- private void callExecuteWithException(Object... params) throws Exception {
+ private void callExecuteWithException(final Object... params) throws Exception {
boolean caught = false;
try {
@@ -773,7 +773,7 @@ public class QueryRunnerTest {
{
int count = 1;
@Override
- public Boolean answer(InvocationOnMock invocation)
+ public Boolean answer(final InvocationOnMock invocation)
{
return ++count <= 3;
}
@@ -789,7 +789,7 @@ public class QueryRunnerTest {
}
- private void callGoodExecuteWithResultSet(Connection conn) throws Exception {
+ private void callGoodExecuteWithResultSet(final Connection conn) throws Exception {
when(call.execute()).thenReturn(true);
when(meta.getParameterCount()).thenReturn(2);
@@ -937,7 +937,7 @@ public class QueryRunnerTest {
}
// helper method for calling execute when an exception is expected
- private void callExecuteWithResultSetWithException(Object... params) throws Exception {
+ private void callExecuteWithResultSetWithException(final Object... params) throws Exception {
boolean caught = false;
try {
@@ -1007,11 +1007,11 @@ public class QueryRunnerTest {
private String c;
public int getA() { return a; }
- public void setA(int a) { this.a = a; }
+ public void setA(final int a) { this.a = a; }
public double getB() { return b; }
- public void setB(double b) { this.b = b; }
+ public void setB(final double b) { this.b = b; }
public String getC() { return c; }
- public void setC(String c) { this.c = c; }
+ public void setC(final String c) { this.c = c; }
}
@Test
http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41e682d6/src/test/java/org/apache/commons/dbutils/TestBean.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/dbutils/TestBean.java b/src/test/java/org/apache/commons/dbutils/TestBean.java
index 3372ddf..406994e 100644
--- a/src/test/java/org/apache/commons/dbutils/TestBean.java
+++ b/src/test/java/org/apache/commons/dbutils/TestBean.java
@@ -1,156 +1,156 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.dbutils;
-
-/**
- * A bean to use in testing toBean() and toBeanList().
- */
-public class TestBean {
-
- public enum Ordinal {
-
- THREE, SIX;
-
- }
-
- private String one = null;
-
- private String two = null;
-
- private Ordinal three = null;
-
- private int intTest = 0;
-
- private Integer integerTest = Integer.valueOf(0);
-
- // UNUSED private Timestamp timestamp = null;
-
- private String doNotSet = "not set";
-
- /**
- * toBean() should set primitive fields to their defaults (ie. 0) when
- * null is returned from the ResultSet.
- */
- private int nullPrimitiveTest = 7;
-
- /**
- * toBean() should set Object fields to null when null is returned from the
- * ResultSet
- */
- private Object nullObjectTest = "overwrite";
-
- /**
- * A Date will be returned from the ResultSet but the property is a String.
- * BeanProcessor should create a String from the Date and set this property.
- */
- private String notDate = "not a date";
-
- /**
- * The ResultSet will have a BigDecimal in this column and the
- * BasicColumnProcessor should convert that to a double and store the value
- * in this property.
- */
- private double columnProcessorDoubleTest = -1;
-
- /**
- * Constructor for TestBean.
- */
- public TestBean() {
- super();
- }
-
- public String getOne() {
- return one;
- }
-
- public Ordinal getThree() {
- return three;
- }
-
- public String getTwo() {
- return two;
- }
-
- public void setOne(String string) {
- one = string;
- }
-
- public void setThree(Ordinal ordinal) {
- three = ordinal;
- }
-
- public void setTwo(String string) {
- two = string;
- }
-
- public String getDoNotSet() {
- return doNotSet;
- }
-
- public void setDoNotSet(String string) {
- doNotSet = string;
- }
-
- public Integer getIntegerTest() {
- return integerTest;
- }
-
- public int getIntTest() {
- return intTest;
- }
-
- public void setIntegerTest(Integer integer) {
- integerTest = integer;
- }
-
- public void setIntTest(int i) {
- intTest = i;
- }
-
- public Object getNullObjectTest() {
- return nullObjectTest;
- }
-
- public int getNullPrimitiveTest() {
- return nullPrimitiveTest;
- }
-
- public void setNullObjectTest(Object object) {
- nullObjectTest = object;
- }
-
- public void setNullPrimitiveTest(int i) {
- nullPrimitiveTest = i;
- }
-
- public String getNotDate() {
- return notDate;
- }
-
- public void setNotDate(String string) {
- notDate = string;
- }
-
- public double getColumnProcessorDoubleTest() {
- return columnProcessorDoubleTest;
- }
-
- public void setColumnProcessorDoubleTest(double d) {
- columnProcessorDoubleTest = d;
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.dbutils;
+
+/**
+ * A bean to use in testing toBean() and toBeanList().
+ */
+public class TestBean {
+
+ public enum Ordinal {
+
+ THREE, SIX;
+
+ }
+
+ private String one = null;
+
+ private String two = null;
+
+ private Ordinal three = null;
+
+ private int intTest = 0;
+
+ private Integer integerTest = Integer.valueOf(0);
+
+ // UNUSED private Timestamp timestamp = null;
+
+ private String doNotSet = "not set";
+
+ /**
+ * toBean() should set primitive fields to their defaults (ie. 0) when
+ * null is returned from the ResultSet.
+ */
+ private int nullPrimitiveTest = 7;
+
+ /**
+ * toBean() should set Object fields to null when null is returned from the
+ * ResultSet
+ */
+ private Object nullObjectTest = "overwrite";
+
+ /**
+ * A Date will be returned from the ResultSet but the property is a String.
+ * BeanProcessor should create a String from the Date and set this property.
+ */
+ private String notDate = "not a date";
+
+ /**
+ * The ResultSet will have a BigDecimal in this column and the
+ * BasicColumnProcessor should convert that to a double and store the value
+ * in this property.
+ */
+ private double columnProcessorDoubleTest = -1;
+
+ /**
+ * Constructor for TestBean.
+ */
+ public TestBean() {
+ super();
+ }
+
+ public String getOne() {
+ return one;
+ }
+
+ public Ordinal getThree() {
+ return three;
+ }
+
+ public String getTwo() {
+ return two;
+ }
+
+ public void setOne(final String string) {
+ one = string;
+ }
+
+ public void setThree(final Ordinal ordinal) {
+ three = ordinal;
+ }
+
+ public void setTwo(final String string) {
+ two = string;
+ }
+
+ public String getDoNotSet() {
+ return doNotSet;
+ }
+
+ public void setDoNotSet(final String string) {
+ doNotSet = string;
+ }
+
+ public Integer getIntegerTest() {
+ return integerTest;
+ }
+
+ public int getIntTest() {
+ return intTest;
+ }
+
+ public void setIntegerTest(final Integer integer) {
+ integerTest = integer;
+ }
+
+ public void setIntTest(final int i) {
+ intTest = i;
+ }
+
+ public Object getNullObjectTest() {
+ return nullObjectTest;
+ }
+
+ public int getNullPrimitiveTest() {
+ return nullPrimitiveTest;
+ }
+
+ public void setNullObjectTest(final Object object) {
+ nullObjectTest = object;
+ }
+
+ public void setNullPrimitiveTest(final int i) {
+ nullPrimitiveTest = i;
+ }
+
+ public String getNotDate() {
+ return notDate;
+ }
+
+ public void setNotDate(final String string) {
+ notDate = string;
+ }
+
+ public double getColumnProcessorDoubleTest() {
+ return columnProcessorDoubleTest;
+ }
+
+ public void setColumnProcessorDoubleTest(final double d) {
+ columnProcessorDoubleTest = d;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41e682d6/src/test/java/org/apache/commons/dbutils/handlers/columns/ColumnHandlerTestBase.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/dbutils/handlers/columns/ColumnHandlerTestBase.java b/src/test/java/org/apache/commons/dbutils/handlers/columns/ColumnHandlerTestBase.java
index 35b6f10..378eade 100644
--- a/src/test/java/org/apache/commons/dbutils/handlers/columns/ColumnHandlerTestBase.java
+++ b/src/test/java/org/apache/commons/dbutils/handlers/columns/ColumnHandlerTestBase.java
@@ -32,7 +32,7 @@ public abstract class ColumnHandlerTestBase {
protected final ColumnHandler handler;
protected final Class<?> matchingType;
- public ColumnHandlerTestBase(ColumnHandler handler, Class<?> matchingType) {
+ public ColumnHandlerTestBase(final ColumnHandler handler, final Class<?> matchingType) {
this.handler = handler;
this.matchingType = matchingType;
}
http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41e682d6/src/test/java/org/apache/commons/dbutils/handlers/columns/TestColumnHandler.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/dbutils/handlers/columns/TestColumnHandler.java b/src/test/java/org/apache/commons/dbutils/handlers/columns/TestColumnHandler.java
index f36d0a0..db4e69d 100644
--- a/src/test/java/org/apache/commons/dbutils/handlers/columns/TestColumnHandler.java
+++ b/src/test/java/org/apache/commons/dbutils/handlers/columns/TestColumnHandler.java
@@ -24,12 +24,12 @@ import org.apache.commons.dbutils.ColumnHandler;
public class TestColumnHandler implements ColumnHandler {
@Override
- public boolean match(Class<?> propType) {
+ public boolean match(final Class<?> propType) {
return false;
}
@Override
- public Object apply(ResultSet rs, int columnIndex) throws SQLException {
+ public Object apply(final ResultSet rs, final int columnIndex) throws SQLException {
return null;
}
}
http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41e682d6/src/test/java/org/apache/commons/dbutils/handlers/properties/TestPropertyHandler.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/dbutils/handlers/properties/TestPropertyHandler.java b/src/test/java/org/apache/commons/dbutils/handlers/properties/TestPropertyHandler.java
index c6344b3..99a0d27 100644
--- a/src/test/java/org/apache/commons/dbutils/handlers/properties/TestPropertyHandler.java
+++ b/src/test/java/org/apache/commons/dbutils/handlers/properties/TestPropertyHandler.java
@@ -21,12 +21,12 @@ import org.apache.commons.dbutils.PropertyHandler;
public class TestPropertyHandler implements PropertyHandler {
@Override
- public boolean match(Class<?> parameter, Object value) {
+ public boolean match(final Class<?> parameter, final Object value) {
return false;
}
@Override
- public Object apply(Class<?> parameter, Object value) {
+ public Object apply(final Class<?> parameter, final Object value) {
return null;
}
}