From ea7811fc6cd681f8bc64a1319cb3a8c77880501c Mon Sep 17 00:00:00 2001 From: wenshao Date: Thu, 15 Sep 2011 23:02:12 +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@777 b9813039-fb51-4c41-a8b9-e21c2acb5095 --- .../com/alibaba/druid/mock/MockResultSet.java | 39 +-- .../druid/bvt/pool/basic/ResultSetTest.java | 243 ++++++++++++++++++ 2 files changed, 256 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/alibaba/druid/mock/MockResultSet.java b/src/main/java/com/alibaba/druid/mock/MockResultSet.java index f40f6f147b..4116b8dcf7 100644 --- a/src/main/java/com/alibaba/druid/mock/MockResultSet.java +++ b/src/main/java/com/alibaba/druid/mock/MockResultSet.java @@ -741,80 +741,67 @@ public class MockResultSet implements ResultSet { @Override public Object getObject(String columnLabel, Map> map) throws SQLException { - - return null; + return getObject(columnLabel); } @Override public Ref getRef(String columnLabel) throws SQLException { - - return null; + return (Ref) getObject(columnLabel); } @Override public Blob getBlob(String columnLabel) throws SQLException { - - return null; + return (Blob) getObject(columnLabel); } @Override public Clob getClob(String columnLabel) throws SQLException { - - return null; + return (Clob) getObject(columnLabel); } @Override public Array getArray(String columnLabel) throws SQLException { - - return null; + return (Array) getObject(columnLabel); } @Override public Date getDate(int columnIndex, Calendar cal) throws SQLException { - - return null; + return (Date) getObject(columnIndex); } @Override public Date getDate(String columnLabel, Calendar cal) throws SQLException { - - return null; + return (Date) getObject(columnLabel); } @Override public Time getTime(int columnIndex, Calendar cal) throws SQLException { - - return null; + return (Time) getObject(columnIndex); } @Override public Time getTime(String columnLabel, Calendar cal) throws SQLException { - - return null; + return (Time) getObject(columnLabel); } @Override public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { - - return null; + return (Timestamp) getObject(columnIndex); } @Override public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { - - return null; + return (Timestamp) getObject(columnLabel); } @Override public URL getURL(int columnIndex) throws SQLException { - - return null; + return (URL) getObject(columnIndex); } @Override public URL getURL(String columnLabel) throws SQLException { - - return null; + return (URL) getObject(columnLabel); } @Override 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 e1bf3e6ae1..52fcd284b6 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 @@ -5,6 +5,7 @@ import java.io.Reader; import java.math.BigDecimal; import java.sql.SQLException; import java.sql.SQLXML; +import java.util.Collections; import junit.framework.TestCase; @@ -1412,4 +1413,246 @@ public class ResultSetTest extends TestCase { } } + public void test_getURL() throws Exception { + resultSet.next(); + + resultSet.getURL(1); + resultSet.getURL("1"); + + { + SQLException error = null; + try { + resultSet.getURL("0"); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + resultSet.getURL("0"); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_getTimestamp() throws Exception { + resultSet.next(); + + resultSet.getTimestamp(1, null); + resultSet.getTimestamp("1", null); + + { + SQLException error = null; + try { + resultSet.getTimestamp("0", null); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + resultSet.getTimestamp("0", null); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_getTime() throws Exception { + resultSet.next(); + + resultSet.getTime(1, null); + resultSet.getTime("1", null); + + { + SQLException error = null; + try { + resultSet.getTime("0", null); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + resultSet.getTime("0", null); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_getDate() throws Exception { + resultSet.next(); + + resultSet.getDate(1, null); + resultSet.getDate("1", null); + + { + SQLException error = null; + try { + resultSet.getDate("0", null); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + resultSet.getDate("0", null); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_getArray() throws Exception { + resultSet.next(); + + resultSet.getArray(1); + resultSet.getArray("1"); + + { + SQLException error = null; + try { + resultSet.getArray("0"); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + resultSet.getArray("0"); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_getClob() throws Exception { + resultSet.next(); + + resultSet.getClob(1); + resultSet.getClob("1"); + + { + SQLException error = null; + try { + resultSet.getClob("0"); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + resultSet.getClob("0"); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_getBlob() throws Exception { + resultSet.next(); + + resultSet.getBlob(1); + resultSet.getBlob("1"); + + { + SQLException error = null; + try { + resultSet.getBlob("0"); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + resultSet.getBlob("0"); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_getRef() throws Exception { + resultSet.next(); + + resultSet.getRef(1); + resultSet.getRef("1"); + + { + SQLException error = null; + try { + resultSet.getRef("0"); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + resultSet.getRef("0"); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_getObject() throws Exception { + resultSet.next(); + + resultSet.getObject(1, null); + resultSet.getObject("1", null); + + { + SQLException error = null; + try { + resultSet.getObject("0", null); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + resultSet.getObject("0", null); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } }