完善mock和测试

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@787 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-09-16 03:10:05 +00:00
parent 8549dd0754
commit 15096dcc8c
2 changed files with 137 additions and 9 deletions
@@ -41,15 +41,16 @@ import java.util.Map;
public class MockResultSet implements ResultSet {
private int rowIndex = -1;
private int rowIndex = -1;
private Statement statement;
private List<Object[]> rows = new ArrayList<Object[]>();
private List<Object[]> rows = new ArrayList<Object[]>();
private boolean wasNull = false;
private boolean wasNull = false;
private MockResultSetMetaData metaData = new MockResultSetMetaData();
private boolean closed = false;
private int fetchSize = 0;
private MockResultSetMetaData metaData = new MockResultSetMetaData();
private boolean closed = false;
private int fetchSize = 0;
private int fetchDirection = 0;
public MockResultSet(Statement statement){
super();
@@ -459,6 +460,10 @@ public class MockResultSet implements ResultSet {
@Override
public synchronized boolean previous() throws SQLException {
if (closed) {
throw new SQLException();
}
if (rowIndex > 0) {
rowIndex--;
return true;
@@ -472,6 +477,7 @@ public class MockResultSet implements ResultSet {
throw new SQLException();
}
this.fetchDirection = direction;
}
@Override
@@ -480,7 +486,7 @@ public class MockResultSet implements ResultSet {
throw new SQLException();
}
return 0;
return fetchDirection;
}
@Override
@@ -488,7 +494,7 @@ public class MockResultSet implements ResultSet {
if (closed) {
throw new SQLException();
}
this.fetchSize = rows;
}
@@ -949,7 +955,7 @@ public class MockResultSet implements ResultSet {
if (closed) {
throw new SQLException("resultSet closed");
}
return 0;
}
@@ -1,5 +1,6 @@
package com.alibaba.druid.bvt.pool.basic;
import java.sql.ResultSet;
import java.sql.SQLException;
import junit.framework.TestCase;
@@ -132,6 +133,31 @@ public class ResultSetTest2 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_FetchDirection() throws Exception {
resultSet.setFetchDirection(ResultSet.FETCH_REVERSE);
Assert.assertEquals(ResultSet.FETCH_REVERSE, resultSet.getFetchDirection());
raw.close();
{
SQLException error = null;
try {
resultSet.getFetchDirection();
} catch (SQLException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
{
SQLException error = null;
try {
resultSet.setFetchDirection(ResultSet.FETCH_REVERSE);
} catch (SQLException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
}
public void test_getHoldability() throws Exception {
resultSet.getHoldability();
@@ -228,6 +254,102 @@ public class ResultSetTest2 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_deleteRow() throws Exception {
resultSet.deleteRow();
raw.close();
{
SQLException error = null;
try {
resultSet.deleteRow();
} catch (SQLException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
}
public void test_updateRow() throws Exception {
resultSet.deleteRow();
raw.close();
{
SQLException error = null;
try {
resultSet.updateRow();
} catch (SQLException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
}
public void test_insertRow() throws Exception {
resultSet.deleteRow();
raw.close();
{
SQLException error = null;
try {
resultSet.insertRow();
} catch (SQLException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
}
public void test_previous() throws Exception {
resultSet.previous();
raw.close();
{
SQLException error = null;
try {
resultSet.previous();
} catch (SQLException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
}
public void test_relative() throws Exception {
resultSet.relative(1);
raw.close();
{
SQLException error = null;
try {
resultSet.relative(1);
} catch (SQLException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
}
public void test_absolute() throws Exception {
resultSet.absolute(1);
raw.close();
{
SQLException error = null;
try {
resultSet.absolute(1);
} catch (SQLException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
}
}