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 2019/11/02 19:56:30 UTC

[commons-dbutils] branch master updated (e97220e -> 6f2d6d9)

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 e97220e  Dedupe property name logic
     new 324fef1  Simplify logic to only convert to Timestamp if not already a timestamp.
     new 2b47fc9  Add coverage for proxied methods in DriverProxy
     new 46466ed  Configure jacoco using the parent pom Replace usage of cobertura with jacoco Upgrade Mockito to latest
     new 6f2d6d9  Rotate checks in an 'and' conditional to perform cheapest first. Add behavioral test to verify that custom row processor is used.

The 4 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:
 pom.xml                                            | 40 ++------------------
 .../java/org/apache/commons/dbutils/DbUtils.java   |  2 +-
 .../handlers/properties/DatePropertyHandler.java   | 20 +++++-----
 .../dbutils/wrappers/StringTrimmedResultSet.java   |  6 +--
 .../{profile.cobertura => profile.jacoco}          |  0
 .../org/apache/commons/dbutils/DbUtilsTest.java    | 44 +++++++++++++++++++++-
 .../commons/dbutils/handlers/KeyedHandlerTest.java | 21 +++++++++++
 .../properties/DatePropertyHandlerTest.java        | 34 ++++++++++-------
 8 files changed, 103 insertions(+), 64 deletions(-)
 rename src/site/resources/{profile.cobertura => profile.jacoco} (100%)


[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.

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 6f2d6d9e5e6d29d57b137061c3fc5675d0832a9e
Author: Carl Hall <th...@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<>();
 


[commons-dbutils] 02/04: Add coverage for proxied methods in DriverProxy

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 2b47fc924e31e674707fbfd60c0dd692179ff137
Author: Carl Hall <th...@apache.org>
AuthorDate: Sat Nov 2 11:37:00 2019 -0700

    Add coverage for proxied methods in DriverProxy
---
 .../java/org/apache/commons/dbutils/DbUtils.java   |  2 +-
 .../org/apache/commons/dbutils/DbUtilsTest.java    | 44 +++++++++++++++++++++-
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbutils/DbUtils.java b/src/main/java/org/apache/commons/dbutils/DbUtils.java
index 99d2c88..0ce654a 100644
--- a/src/main/java/org/apache/commons/dbutils/DbUtils.java
+++ b/src/main/java/org/apache/commons/dbutils/DbUtils.java
@@ -337,7 +337,7 @@ public final class DbUtils {
      *
      * @since 1.6
      */
-    private static final class DriverProxy implements Driver {
+    static final class DriverProxy implements Driver {
 
         private boolean parentLoggerSupported = true;
 
diff --git a/src/test/java/org/apache/commons/dbutils/DbUtilsTest.java b/src/test/java/org/apache/commons/dbutils/DbUtilsTest.java
index 52b42d2..1907c8b 100644
--- a/src/test/java/org/apache/commons/dbutils/DbUtilsTest.java
+++ b/src/test/java/org/apache/commons/dbutils/DbUtilsTest.java
@@ -16,16 +16,23 @@
  */
 package org.apache.commons.dbutils;
 
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 
 import java.sql.Connection;
+import java.sql.Driver;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.util.Properties;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.fail;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.verify;
 
 public class DbUtilsTest {
 
@@ -282,4 +289,39 @@ public class DbUtilsTest {
 
     }
 
+    public static class DriverProxyTest {
+        private static final Driver mockedDriver = mock(Driver.class);
+        private DbUtils.DriverProxy proxy;
+
+        @Before
+        public void setUp() {
+            proxy = new DbUtils.DriverProxy(mockedDriver);
+        }
+
+        @After
+        public void tearDown() {
+            reset(mockedDriver);
+        }
+
+        @Test
+        public void testProxiedMethods() throws Exception {
+            proxy.getMajorVersion();
+            verify(mockedDriver).getMajorVersion();
+            proxy.getMinorVersion();
+            verify(mockedDriver).getMinorVersion();
+            proxy.jdbcCompliant();
+            verify(mockedDriver).jdbcCompliant();
+
+            String url = "testUrl";
+            proxy.acceptsURL(url);
+            verify(mockedDriver).acceptsURL(url);
+
+            Properties props = new Properties();
+            props.setProperty("test", "true");
+            proxy.connect(url, props);
+            verify(mockedDriver).connect(url, props);
+            proxy.getPropertyInfo(url, props);
+            verify(mockedDriver).getPropertyInfo(url, props);
+        }
+    }
 }


[commons-dbutils] 01/04: Simplify logic to only convert to Timestamp if not already a timestamp.

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 324fef13bd7e1589c28df26ddd81080b76ee7a4c
Author: Carl Hall <th...@apache.org>
AuthorDate: Sun Oct 27 21:11:48 2019 -0700

    Simplify logic to only convert to Timestamp if not already a timestamp.
---
 .../handlers/properties/DatePropertyHandler.java   | 20 +++++++------
 .../properties/DatePropertyHandlerTest.java        | 34 +++++++++++++---------
 2 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbutils/handlers/properties/DatePropertyHandler.java b/src/main/java/org/apache/commons/dbutils/handlers/properties/DatePropertyHandler.java
index e2f8d8b..24f8971 100644
--- a/src/main/java/org/apache/commons/dbutils/handlers/properties/DatePropertyHandler.java
+++ b/src/main/java/org/apache/commons/dbutils/handlers/properties/DatePropertyHandler.java
@@ -16,10 +16,11 @@
  */
 package org.apache.commons.dbutils.handlers.properties;
 
-import java.sql.Timestamp;
-
 import org.apache.commons.dbutils.PropertyHandler;
 
+import java.sql.Timestamp;
+import java.util.Date;
+
 public class DatePropertyHandler implements PropertyHandler {
     @Override
     public boolean match(final Class<?> parameter, final Object value) {
@@ -31,7 +32,8 @@ public class DatePropertyHandler implements PropertyHandler {
             if ("java.sql.Time".equals(targetType)) {
                 return true;
             } else
-            if ("java.sql.Timestamp".equals(targetType)) {
+            if ("java.sql.Timestamp".equals(targetType)
+                    && !Timestamp.class.isInstance(value)) {
                 return true;
             }
         }
@@ -42,17 +44,17 @@ public class DatePropertyHandler implements PropertyHandler {
     @Override
     public Object apply(final Class<?> parameter, Object value) {
         final String targetType = parameter.getName();
+        final Date dateValue = (java.util.Date) value;
+        final long time = dateValue.getTime();
+
         if ("java.sql.Date".equals(targetType)) {
-            value = new java.sql.Date(((java.util.Date) value).getTime());
+            value = new java.sql.Date(time);
         } else
         if ("java.sql.Time".equals(targetType)) {
-            value = new java.sql.Time(((java.util.Date) value).getTime());
+            value = new java.sql.Time(time);
         } else
         if ("java.sql.Timestamp".equals(targetType)) {
-            final Timestamp tsValue = (Timestamp) value;
-            final int nanos = tsValue.getNanos();
-            value = new Timestamp(tsValue.getTime());
-            ((Timestamp) value).setNanos(nanos);
+            value = new Timestamp(time);
         }
 
         return value;
diff --git a/src/test/java/org/apache/commons/dbutils/handlers/properties/DatePropertyHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/properties/DatePropertyHandlerTest.java
index 81380a0..b7ed03b 100644
--- a/src/test/java/org/apache/commons/dbutils/handlers/properties/DatePropertyHandlerTest.java
+++ b/src/test/java/org/apache/commons/dbutils/handlers/properties/DatePropertyHandlerTest.java
@@ -16,50 +16,58 @@
  */
 package org.apache.commons.dbutils.handlers.properties;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import org.junit.Before;
+import org.junit.Test;
 
 import java.sql.Time;
 import java.sql.Timestamp;
+import java.util.Date;
 
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 public class DatePropertyHandlerTest {
     private DatePropertyHandler handler;
+    private Date testValue;
 
     @Before
     public void setUp() {
         this.handler = new DatePropertyHandler();
+        this.testValue = new Date();
     }
 
     @Test
     public void testMatch() {
-        assertTrue(handler.match(java.sql.Date.class, new java.util.Date()));
-        assertTrue(handler.match(java.sql.Time.class, new java.util.Date()));
-        assertTrue(handler.match(java.sql.Timestamp.class, new java.util.Date()));
+        assertTrue(handler.match(java.sql.Date.class, testValue));
+        assertTrue(handler.match(java.sql.Time.class, testValue));
+        assertTrue(handler.match(java.sql.Timestamp.class, testValue));
+    }
+
+    @Test
+    public void testNotMatch() {
+        final Timestamp ts = new Timestamp(testValue.getTime());
+        assertFalse(handler.match(java.sql.Timestamp.class, ts));
     }
 
     @Test
     public void testMatchNegative() {
         assertFalse(handler.match(Float.class, null));
-        assertFalse(handler.match(Float.class, new java.util.Date()));
+        assertFalse(handler.match(Float.class, testValue));
     }
 
     @Test
     public void testApplyTypeOfDate() throws Exception {
-        assertEquals(java.sql.Date.class, handler.apply(java.sql.Date.class, new java.util.Date()).getClass());
+        assertEquals(java.sql.Date.class, handler.apply(java.sql.Date.class, testValue).getClass());
     }
 
     @Test
     public void testApplyTypeOfTime() throws Exception {
-        assertEquals(Time.class, handler.apply(java.sql.Time.class, new java.util.Date()).getClass());
+        assertEquals(Time.class, handler.apply(java.sql.Time.class, testValue).getClass());
     }
 
     @Test
     public void testApplyTypeOfTimestamp() throws Exception {
-        final Timestamp ts = new Timestamp(new java.util.Date().getTime());
-        assertEquals(Timestamp.class, handler.apply(java.sql.Timestamp.class, ts).getClass());
+        assertEquals(Timestamp.class, handler.apply(java.sql.Timestamp.class, testValue).getClass());
     }
 }


[commons-dbutils] 03/04: Configure jacoco using the parent pom Replace usage of cobertura with jacoco Upgrade Mockito to latest

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 46466ed371b4784aca89b139d4690a7b0fca42ae
Author: Carl Hall <th...@apache.org>
AuthorDate: Sat Nov 2 12:51:36 2019 -0700

    Configure jacoco using the parent pom
    Replace usage of cobertura with jacoco
    Upgrade Mockito to latest
---
 pom.xml                                            | 40 ++--------------------
 .../{profile.cobertura => profile.jacoco}          |  0
 2 files changed, 3 insertions(+), 37 deletions(-)

diff --git a/pom.xml b/pom.xml
index 9f57496..441be19 100644
--- a/pom.xml
+++ b/pom.xml
@@ -214,7 +214,7 @@
     <dependency>
       <groupId>org.mockito</groupId>
       <artifactId>mockito-core</artifactId>
-      <version>1.9.5</version>
+      <version>3.1.0</version>
       <scope>test</scope>
     </dependency>
     <dependency>
@@ -239,7 +239,6 @@
     <maven.compiler.target>1.7</maven.compiler.target>
 
     <checkstyle.plugin.version>2.17</checkstyle.plugin.version>
-    <jacoco.plugin.version>0.8.5</jacoco.plugin.version>
 
     <commons.componentid>dbutils</commons.componentid>
     <commons.module.name>org.apache.commons.dbutils</commons.module.name>
@@ -303,46 +302,13 @@
       <plugin>
         <groupId>org.jacoco</groupId>
         <artifactId>jacoco-maven-plugin</artifactId>
-        <version>${jacoco.plugin.version}</version>
         <executions>
           <execution>
-            <goals>
-              <goal>prepare-agent</goal>
-            </goals>
-          </execution>
-          <!-- attached to Maven test phase -->
-          <execution>
-            <id>report</id>
             <phase>test</phase>
-              <goals>
-                <goal>report</goal>
-              </goals>
-          </execution>
-          <execution>
-            <id>jacoco-check</id>
             <goals>
-              <goal>check</goal>
+              <goal>report</goal>
             </goals>
-            <configuration>
-              <rules>
-                <rule>
-                  <element>BUNDLE</element>
-                  <limits>
-                    <limit>
-                      <counter>INSTRUCTION</counter>
-                      <value>COVEREDRATIO</value>
-                      <minimum>0.6</minimum>
-                    </limit>
-                    <limit>
-                      <counter>CLASS</counter>
-                      <value>MISSEDCOUNT</value>
-                      <maximum>8</maximum>
-                    </limit>
-                  </limits>
-                </rule>
-              </rules>
-            </configuration>
-        </execution>
+          </execution>
         </executions>
       </plugin>
     </plugins>
diff --git a/src/site/resources/profile.cobertura b/src/site/resources/profile.jacoco
similarity index 100%
rename from src/site/resources/profile.cobertura
rename to src/site/resources/profile.jacoco