From 4f7e43ced9bf161e3e1e5ebcffe6efe921b37b15 Mon Sep 17 00:00:00 2001 From: wenshao Date: Fri, 16 Sep 2011 04:18:13 +0000 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84mock=E5=92=8C=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.alibabatech.com/svn/druid/trunk@791 b9813039-fb51-4c41-a8b9-e21c2acb5095 --- .../com/alibaba/druid/mock/MockResultSet.java | 4 + .../druid/bvt/pool/basic/ResultSetTest.java | 90 ++++++++++++------- .../druid/bvt/pool/basic/ResultSetTest2.java | 64 +++++++++++++ 3 files changed, 127 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/alibaba/druid/mock/MockResultSet.java b/src/main/java/com/alibaba/druid/mock/MockResultSet.java index e1e9c728c6..b3e545d30f 100644 --- a/src/main/java/com/alibaba/druid/mock/MockResultSet.java +++ b/src/main/java/com/alibaba/druid/mock/MockResultSet.java @@ -346,6 +346,10 @@ public class MockResultSet implements ResultSet { @Override public ResultSetMetaData getMetaData() throws SQLException { + if (closed) { + throw new SQLException("resultSet closed"); + } + return metaData; } diff --git a/src/test/java/com/alibaba/druid/bvt/pool/basic/ResultSetTest.java b/src/test/java/com/alibaba/druid/bvt/pool/basic/ResultSetTest.java index 672365f02f..898b44cec6 100644 --- a/src/test/java/com/alibaba/druid/bvt/pool/basic/ResultSetTest.java +++ b/src/test/java/com/alibaba/druid/bvt/pool/basic/ResultSetTest.java @@ -1467,12 +1467,13 @@ public class ResultSetTest extends TestCase { Assert.assertNotNull(error); } } + public void test_getRowId() throws Exception { resultSet.next(); - + resultSet.getRowId(1); resultSet.getRowId("1"); - + { SQLException error = null; try { @@ -1482,7 +1483,7 @@ public class ResultSetTest extends TestCase { } Assert.assertNotNull(error); } - + { SQLException error = null; try { @@ -1494,6 +1495,33 @@ public class ResultSetTest extends TestCase { } } + public void test_getObject_1() throws Exception { + resultSet.next(); + + resultSet.getObject(1); + resultSet.getObject("1"); + + { + SQLException error = null; + try { + resultSet.getObject(0); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + resultSet.getObject("0"); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + public void test_getTimestamp() throws Exception { resultSet.next(); @@ -1763,13 +1791,13 @@ public class ResultSetTest extends TestCase { Assert.assertNotNull(error); } } - + public void test_updateRowId() throws Exception { resultSet.next(); - + resultSet.updateRowId(1, null); resultSet.updateRowId("1", null); - + { SQLException error = null; try { @@ -1779,7 +1807,7 @@ public class ResultSetTest extends TestCase { } Assert.assertNotNull(error); } - + { SQLException error = null; try { @@ -1790,13 +1818,13 @@ public class ResultSetTest extends TestCase { Assert.assertNotNull(error); } } - + public void test_updateArray() throws Exception { resultSet.next(); - + resultSet.updateArray(1, null); resultSet.updateArray("1", null); - + { SQLException error = null; try { @@ -1806,7 +1834,7 @@ public class ResultSetTest extends TestCase { } Assert.assertNotNull(error); } - + { SQLException error = null; try { @@ -1817,13 +1845,13 @@ public class ResultSetTest extends TestCase { Assert.assertNotNull(error); } } - + public void test_updateClob() throws Exception { resultSet.next(); - + resultSet.updateClob(1, (Clob) null); resultSet.updateClob("1", (Clob) null); - + { SQLException error = null; try { @@ -1833,7 +1861,7 @@ public class ResultSetTest extends TestCase { } Assert.assertNotNull(error); } - + { SQLException error = null; try { @@ -1844,13 +1872,13 @@ public class ResultSetTest extends TestCase { Assert.assertNotNull(error); } } - + public void test_updateBlob() throws Exception { resultSet.next(); - + resultSet.updateBlob(1, (Blob) null); resultSet.updateBlob("1", (Blob) null); - + { SQLException error = null; try { @@ -1860,7 +1888,7 @@ public class ResultSetTest extends TestCase { } Assert.assertNotNull(error); } - + { SQLException error = null; try { @@ -1871,13 +1899,13 @@ public class ResultSetTest extends TestCase { Assert.assertNotNull(error); } } - + public void test_updateRef() throws Exception { resultSet.next(); - + resultSet.updateRef(1, (Ref) null); resultSet.updateRef("1", (Ref) null); - + { SQLException error = null; try { @@ -1887,7 +1915,7 @@ public class ResultSetTest extends TestCase { } Assert.assertNotNull(error); } - + { SQLException error = null; try { @@ -1898,13 +1926,13 @@ public class ResultSetTest extends TestCase { Assert.assertNotNull(error); } } - + public void test_updateObject() throws Exception { resultSet.next(); - + resultSet.updateObject(1, null); resultSet.updateObject("1", null); - + { SQLException error = null; try { @@ -1914,7 +1942,7 @@ public class ResultSetTest extends TestCase { } Assert.assertNotNull(error); } - + { SQLException error = null; try { @@ -1925,13 +1953,13 @@ public class ResultSetTest extends TestCase { Assert.assertNotNull(error); } } - + public void test_updateObject_1() throws Exception { resultSet.next(); - + resultSet.updateObject(1, null, 1); resultSet.updateObject("1", null, 1); - + { SQLException error = null; try { @@ -1941,7 +1969,7 @@ public class ResultSetTest extends TestCase { } Assert.assertNotNull(error); } - + { SQLException error = null; try { diff --git a/src/test/java/com/alibaba/druid/bvt/pool/basic/ResultSetTest2.java b/src/test/java/com/alibaba/druid/bvt/pool/basic/ResultSetTest2.java index 119b32b894..3603a63b8d 100644 --- a/src/test/java/com/alibaba/druid/bvt/pool/basic/ResultSetTest2.java +++ b/src/test/java/com/alibaba/druid/bvt/pool/basic/ResultSetTest2.java @@ -526,6 +526,70 @@ public class ResultSetTest2 extends TestCase { Assert.assertNotNull(error); } } + + public void test_getWarnings() throws Exception { + resultSet.getWarnings(); + + raw.close(); + + { + SQLException error = null; + try { + resultSet.getWarnings(); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_clearWarnings() throws Exception { + resultSet.clearWarnings(); + + raw.close(); + + { + SQLException error = null; + try { + resultSet.clearWarnings(); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_getCursorName() throws Exception { + resultSet.getCursorName(); + + raw.close(); + + { + SQLException error = null; + try { + resultSet.getCursorName(); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_getMetaData() throws Exception { + resultSet.getMetaData(); + + raw.close(); + + { + SQLException error = null; + try { + resultSet.getMetaData(); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } }