mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
完善mock和测试
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@788 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user