diff --git a/src/main/java/com/alibaba/druid/mock/MockResultSet.java b/src/main/java/com/alibaba/druid/mock/MockResultSet.java index 550e6e3f6c..5202469a3d 100644 --- a/src/main/java/com/alibaba/druid/mock/MockResultSet.java +++ b/src/main/java/com/alibaba/druid/mock/MockResultSet.java @@ -51,6 +51,8 @@ public class MockResultSet implements ResultSet { private boolean closed = false; private int fetchSize = 0; private int fetchDirection = 0; + private SQLWarning warning; + private String cursorName; public MockResultSet(Statement statement){ super(); @@ -80,6 +82,10 @@ public class MockResultSet implements ResultSet { @Override public synchronized boolean next() throws SQLException { + if (closed) { + throw new SQLException(); + } + if (rowIndex < rows.size() - 1) { rowIndex++; return true; @@ -94,6 +100,10 @@ public class MockResultSet implements ResultSet { @Override public boolean wasNull() throws SQLException { + if (closed) { + throw new SQLException(); + } + return wasNull; } @@ -301,18 +311,37 @@ public class MockResultSet implements ResultSet { @Override public SQLWarning getWarnings() throws SQLException { - return null; + if (closed) { + throw new SQLException(); + } + + return warning; } @Override public void clearWarnings() throws SQLException { + if (closed) { + throw new SQLException(); + } + + warning = null; + } + public void setWarning(SQLWarning warning) { + this.warning = warning; } @Override public String getCursorName() throws SQLException { + if (closed) { + throw new SQLException(); + } + + return cursorName; + } - return null; + public void setCursorName(String cursorName) { + this.cursorName = cursorName; } @Override @@ -463,7 +492,7 @@ public class MockResultSet implements ResultSet { if (closed) { throw new SQLException(); } - + if (rowIndex > 0) { rowIndex--; return true; 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 82bd06c7cc..ec0ccbf005 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 @@ -350,6 +350,38 @@ public class ResultSetTest2 extends TestCase { Assert.assertNotNull(error); } } + + public void test_next() throws Exception { + resultSet.next(); + + raw.close(); + + { + SQLException error = null; + try { + resultSet.next(); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_wasNull() throws Exception { + resultSet.wasNull(); + + raw.close(); + + { + SQLException error = null; + try { + resultSet.wasNull(); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } }