commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thecarlh...@apache.org
Subject [commons-dbutils] 04/04: Rotate checks in an 'and' conditional to perform cheapest first. Add behavioral test to verify that custom row processor is used.
Date Sat, 02 Nov 2019 19:56:34 GMT
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 6f2d6d9e5e6d29d57b137061c3fc5675d0832a9e
Author: Carl Hall <thecarlhall@apache.org>
AuthorDate: Sat Nov 2 12:55:57 2019 -0700

    Rotate checks in an 'and' conditional to perform cheapest first.
    Add behavioral test to verify that custom row processor is used.
---
 .../dbutils/wrappers/StringTrimmedResultSet.java    |  6 +++---
 .../commons/dbutils/handlers/KeyedHandlerTest.java  | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)

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 11c6fb3..929dbb3 100644
--- a/src/main/java/org/apache/commons/dbutils/wrappers/StringTrimmedResultSet.java
+++ b/src/main/java/org/apache/commons/dbutils/wrappers/StringTrimmedResultSet.java
@@ -97,9 +97,9 @@ public class StringTrimmedResultSet implements InvocationHandler {
 
         Object result = method.invoke(this.rs, args);
 
-        if ((method.getName().equals("getObject")
-            || method.getName().equals("getString"))
-                && result instanceof String) {
+        if (result instanceof String
+                && (method.getName().equals("getObject")
+                || method.getName().equals("getString"))) {
             result = ((String) result).trim();
         }
 
diff --git a/src/test/java/org/apache/commons/dbutils/handlers/KeyedHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/KeyedHandlerTest.java
index b81c076..717529c 100644
--- a/src/test/java/org/apache/commons/dbutils/handlers/KeyedHandlerTest.java
+++ b/src/test/java/org/apache/commons/dbutils/handlers/KeyedHandlerTest.java
@@ -22,9 +22,30 @@ import java.util.Map.Entry;
 
 import org.apache.commons.dbutils.BaseTestCase;
 import org.apache.commons.dbutils.ResultSetHandler;
+import org.apache.commons.dbutils.RowProcessor;
+
+import static org.mockito.Mockito.mock;
 
 public class KeyedHandlerTest extends BaseTestCase {
 
+    public void testInjectedRowProcess() throws Exception {
+        RowProcessor mockProc = mock(RowProcessor.class);
+        final ResultSetHandler<Map<String,Map<String,Object>>> h = new
KeyedHandler<>(mockProc);
+        final Map<String,Map<String,Object>> results = h.handle(this.rs);
+
+        assertNotNull(results);
+        assertEquals(ROWS, results.size());
+
+        Map<String,Object> row = null;
+        for(final Entry<String, Map<String, Object>> entry : results.entrySet())
+        {
+            row = entry.getValue();
+            assertNotNull(row);
+            assertTrue(row.isEmpty());
+            assertEquals(0, row.keySet().size());
+        }
+    }
+
     public void testHandle() throws SQLException {
         final ResultSetHandler<Map<String,Map<String,Object>>> h = new
KeyedHandler<>();
 


Mime
View raw message