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 2023/02/26 16:26:28 UTC

[commons-dbutils] branch master updated (efcecc6 -> e4e9ce7)

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 efcecc6  Merge branch 'DBUTILS-150'
     new 2e7e493  DBUTILS-150 Add unit test to flex null reader check
     new e4e9ce7  Add remaining test coverage for BasicRowProcessor.CaseInsensitiveHashMap

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


Summary of changes:
 .../commons/dbutils/BasicRowProcessorTest.java     | 18 ++++++
 .../apache/commons/dbutils/BeanProcessorTest.java  | 71 ++++++++++++++++++++++
 2 files changed, 89 insertions(+)


[commons-dbutils] 02/02: Add remaining test coverage for BasicRowProcessor.CaseInsensitiveHashMap

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 e4e9ce7dd949c295d2b12f3180b199dbe0e80142
Author: Carl Hall <th...@apache.org>
AuthorDate: Sun Feb 26 11:25:18 2023 -0500

    Add remaining test coverage for BasicRowProcessor.CaseInsensitiveHashMap
---
 .../apache/commons/dbutils/BasicRowProcessorTest.java  | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/test/java/org/apache/commons/dbutils/BasicRowProcessorTest.java b/src/test/java/org/apache/commons/dbutils/BasicRowProcessorTest.java
index 8fa8b90..4a425f6 100644
--- a/src/test/java/org/apache/commons/dbutils/BasicRowProcessorTest.java
+++ b/src/test/java/org/apache/commons/dbutils/BasicRowProcessorTest.java
@@ -20,10 +20,13 @@ import java.sql.SQLException;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Objects;
 
 /**
  * Test the BasicRowProcessor class.
@@ -158,4 +161,19 @@ public class BasicRowProcessorTest extends BaseTestCase {
         assertFalse(itr.hasNext());
     }
 
+    public void testPutAllContainsKeyAndRemove() throws Exception {
+        Map<String, Object> test = new HashMap<>(3);
+        test.put("fiRst", "thing");
+        test.put("seCond", "another");
+        test.put("thIrd", "more");
+        Map<String, Object> brpMap = BasicRowProcessor.createCaseInsensitiveHashMap(3);
+        brpMap.putAll(test);
+
+        assertEquals(test, brpMap);
+        assertTrue(brpMap.containsKey("fiRst"));
+        assertTrue(brpMap.containsKey("first"));
+
+        brpMap.remove("first");
+        assertFalse(brpMap.containsKey("first"));
+    }
 }


[commons-dbutils] 01/02: DBUTILS-150 Add unit test to flex null reader check

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 2e7e4930bad9a6a8d3836642359198bc84434add
Author: Carl Hall <th...@apache.org>
AuthorDate: Sun Feb 26 11:03:05 2023 -0500

    DBUTILS-150 Add unit test to flex null reader check
---
 .../apache/commons/dbutils/BeanProcessorTest.java  | 71 ++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/src/test/java/org/apache/commons/dbutils/BeanProcessorTest.java b/src/test/java/org/apache/commons/dbutils/BeanProcessorTest.java
index 006d085..15fa93d 100644
--- a/src/test/java/org/apache/commons/dbutils/BeanProcessorTest.java
+++ b/src/test/java/org/apache/commons/dbutils/BeanProcessorTest.java
@@ -175,6 +175,77 @@ public class BeanProcessorTest extends BaseTestCase {
         }
     }
 
+    private static final class TestNoGetter {
+        public String testField;
+
+        /**
+         * Add setter to trigger JavaBeans to populate a PropertyDescriptor
+         *
+         * @param testField The new testField value
+         */
+        public void setTestField(String testField) {
+            this.testField = testField;
+        }
+    }
+
+    public void testCheckAnnotationOnMissingReadMethod() throws Exception {
+        String[] colNames = new String[] {"testField"};
+        ResultSetMetaData metaData = MockResultSetMetaData.create(colNames);
+
+        String testField = "first";
+        Object[][] rows = new Object[][] {
+                new Object[] {testField}
+        };
+
+        ResultSet rs = MockResultSet.create(metaData, rows);
+        assertTrue(rs.next());
+        TestNoGetter testCls = new TestNoGetter();
+        testCls = beanProc.populateBean(rs, testCls);
+        assertEquals(testCls.testField, "first");
+    }
+
+    private static final class TestWrongSetter {
+        public Integer testField;
+
+        public Integer getTestField() {
+            return testField;
+        }
+
+        /**
+         * dbutils checks for a setter with exactly 1 param. This tests resilience
+         * to a found setter that doesn't match expectations.
+         * @param idx
+         * @param testField
+         */
+        public void setTestField(int idx, Integer testField) {
+            this.testField = testField;
+        }
+    }
+
+    public void testWrongSetterParamCount() throws Exception {
+        String[] colNames = new String[] {"testField"};
+        ResultSetMetaData metaData = MockResultSetMetaData.create(colNames);
+
+        Integer testField = 1;
+        Object[][] rows = new Object[][] {
+                new Object[] {testField}
+        };
+
+        ResultSet rs = MockResultSet.create(metaData, rows);
+        assertTrue(rs.next());
+        TestWrongSetter testCls = new TestWrongSetter();
+        testCls = beanProc.populateBean(rs, testCls);
+        assertNull(testCls.testField);
+    }
+
+    /**
+     * Based on the report in DBUTILS-150. This test validates that indexed
+     * property descriptors are not used, and indexed getter/setter methods
+     * are not inspected.
+     *
+     * @throws Exception
+     * @see <a href="https://issues.apache.org/jira/browse/DBUTILS-150">DBUTILS-150</a>
+     */
     public void testIndexedPropertyDescriptor() throws Exception {
         String[] colNames = new String[] {"name", "things", "stuff"};
         ResultSetMetaData metaData = MockResultSetMetaData.create(colNames);